How to overlay RateThroughTime plots

33 views
Skip to first unread message

Daniel David Díaz Contreras Díaz

unread,
Mar 15, 2023, 5:51:40 PM3/15/23
to bamm-project
Hello everyone,
This may be relatively simple for most experienced users in R plotting, but I am trying to generate something like the image below. I want to overlay different RateThroughTime lines in the same plot. Any hint is greatly appreciated.

Thanks in advance. Best wishes.
Daniel

Daniel David Díaz Contreras Díaz

unread,
Mar 15, 2023, 5:55:36 PM3/15/23
to bamm-project
More precisely, as in the letter B, C or D. Thank you

pasca...@gmail.com

unread,
Mar 16, 2023, 10:23:00 AM3/16/23
to bamm-project
Hi Daniel,

The examples in the help for plotRateThroughTime() show how to do this.

I would recommend that you first calculate the time-binned rates and then do the plotting. This makes it easier to experiment with the plotting without needing to recalculate the rates each time.

So for example:

library(BAMMtools)

data(events.whales)
data(whales)
ephy <- getEventData(whales,events.whales)

rmat1 <- getRateThroughTimeMatrix(ephy, node = 141, nodetype = 'exclude')
rmat2 <- getRateThroughTimeMatrix(ephy, node = 141, nodetype = 'include')

plotRateThroughTime(rmat1, intervals=seq(from = 0, 0.9, by = 0.01),
    smooth = TRUE, ylim = c(0, 1.2))

plotRateThroughTime(rmat2, intervals = seq(from = 0, 0.9, by = 0.01),
    smooth = TRUE, add = TRUE, intervalCol = 'orange')


To get the proper plot dimensions, you may need to adjust xlim and ylim in the first plot.
And of course you can do this with any number of groups/clades.

If you have more specific questions, let me know.
-Pascal
Reply all
Reply to author
Forward
0 new messages