Tuesday, May 17, 2022

A quick & easy trick to flip the x ("time") axis on a lineages through time plot

Here's a quick & easy trick to flip the direction of the x-axis (to show time running backwards from the present day into the past) on a lineages-through-time (LTT) plot.

To start, I'll load phytools and read a tree from file. (Here I'm using a tree of darters from Near et al. 2011.)


Next, I'll compute my "ltt" object without graphing it using phytools::ltt.

## Object of class "ltt" containing:
## (1) A phylogenetic tree with 201 tips and 198 internal
##     nodes.
## (2) Vectors containing the number of lineages (ltt) and
##     branching times (times) on the tree.
## (3) A value for Pybus & Harvey's "gamma" statistic of
##     gamma = NA, p-value = NA.

(The γ statistic shows up as NA because our tree has polytomies – but for graphing the LTT we don't need to worry about that.)

Finally, I'll graph the "ltt" object, without showing the axes, I'll add, first, the vertical (y) axis – and then I'll flip the directionality of the x axis before adding it too.

    xlab="time (mybp)")

plot of chunk unnamed-chunk-3

Cool. It works!

No comments:

Post a Comment

Note: due to the very large amount of spam, all comments are now automatically submitted for moderation.