using_ggbeast

Installing the package

You can install the package from github running this line bellow.

remotes::install_github("wilsonfrantine/ggbeast")

Loading the package

After installing, you must load it.

library("ggbeast")
#> Loading required package: ggplot2

Using ggbeast

First, you must load some data providing the path to your “EBSP.log” file.

Herein we’ll load it from the example file in the package.

file_path <- system.file("extdata/ebsp.log", package="ggbeast")
file_path
#> [1] "/tmp/Rtmpq7kT21/Rinst4169678a919b/ggbeast/extdata/ebsp.log"

Now we must take all the relevant data with harvest_ebsp()

ebsp <- harvest_ebsp(path=file_path)
head(ebsp)
#>                                                           ID     allTimes
#> 1 /tmp/Rtmpq7kT21/Rinst4169678a919b/ggbeast/extdata/ebsp.log 0.0000000000
#> 2 /tmp/Rtmpq7kT21/Rinst4169678a919b/ggbeast/extdata/ebsp.log 0.0001603866
#> 3 /tmp/Rtmpq7kT21/Rinst4169678a919b/ggbeast/extdata/ebsp.log 0.0003011270
#> 4 /tmp/Rtmpq7kT21/Rinst4169678a919b/ggbeast/extdata/ebsp.log 0.0004927056
#> 5 /tmp/Rtmpq7kT21/Rinst4169678a919b/ggbeast/extdata/ebsp.log 0.0007009645
#> 6 /tmp/Rtmpq7kT21/Rinst4169678a919b/ggbeast/extdata/ebsp.log 0.0008341639
#>     Nmedian  NlowerHPD NupperHPD NlowerCPD NupperCPD
#> 1 0.7992785 0.03125119  3.150747 0.1444267  3.277080
#> 2 0.7556362 0.10106009  3.052590 0.1390891  3.091103
#> 3 0.7173397 0.13127935  2.929836 0.1488629  2.973820
#> 4 0.6652098 0.12492745  2.789292 0.1428887  2.872570
#> 5 0.6085411 0.11802250  2.636510 0.1305588  2.762506
#> 6 0.5640666 0.05987804  2.538793 0.1212913  2.692110

Now, it is simple like this

p1 <- ggebsp(ebsp)
p1

Customizing your plot

The coolest thing about ggplot framework is the possibility to change almost anything. You can linearize axis, change colors, change formats and so on…

Down bellow, you will find some simple examples.

Changing the Time scales

You can change time scales with simple commands:

p1+scale_time_Ka()

Changing Ne scale

The default of the ggebsp is to output the Ne in log scale (as above), but you can linearize that by:

p1 + scale_Ne_linear()
#> Scale for y is already present.
#> Adding another scale for y, which will replace the existing scale.

Changing colors

p1+scale_time_Ka()+
  ggplot2::scale_color_manual(values="blue")+
  ggplot2::scale_fill_manual(values="blue")

Creating compositions

Usually we have more than one plot to show. The ggbeast has a function ggwrap, which prepare the data for a facet_wrap from ggplot2.

See the example bellow. As we don’t have two plots, I’ll send the p1 twice.

ggwrap(p1, p1) |>
    ggebsp() + facet_wrap(~Run)

We can make it better by changing colors, time scale and removing the frame arround the facets names (1 and 2).

myplots <- ggwrap(p1, p1) |>
    ggebsp() + facet_wrap(~Run)
    
myplots <- myplots +
  aes(fill=Run, colour = Run)+
  scale_time_Ka()+
  scale_fill_manual(values=c("black", "grey"))+
  scale_color_manual(values=c("black", "grey"))+
  theme(strip.background = element_blank())

myplots

You may wanna change the plots names for those meaningfull to you. That is easy with ggplot2.

We create a labeller for the variable Run, which is the one who identify the plots. Then, we say that 1 = pop1, and so on for as many plots we have.


labels <- labeller( Run = c("1"="Pop1", "2"="Pop2") )

myplots + 
  facet_wrap(~Run, labeller = labels)+
  scale_Ne_log()
#> Scale for y is already present.
#> Adding another scale for y, which will replace the existing scale.