Saturday, October 25, 2014

Reversing the time axis in an ltt95 plot

A phytools user recently asked the following:

“I am currently using the ltt95 function on a "multiPhylo" object. I would like to known if there is a solution to reverse the time axis from the root of the tree to present?”

Indeed this is not too difficult. ltt95 already returns an object of class "ltt95" invisibly. This object is basically a matrix containing the plotted data for x and y in columns, with a few different attributes to tell the S3 plotting method for objects of its class how to handle the matrix. So if we were naive as to the functionality of our plotting method, we could just manipulate the contents of that matrix to get the plot that we wanted. phytools makes things even easier, however, as there is an argument xaxis in the plotting method for objects of class "ltt95" that automates this all for us.

Here's how we can use it to control the direction of x in various ways:

## load phytools
## Loading required package: ape
## Loading required package: maps
## simulate some trees
## now create a standard ltt95 plot

plot of chunk unnamed-chunk-1

## OK - now if we want to simply flip the values on x
## so that they should "time before present"

plot of chunk unnamed-chunk-1

## we can also plot time before present as "negative time"

plot of chunk unnamed-chunk-1

Well, that's really it.

No comments:

Post a Comment

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