Monday, July 13, 2015

Interesting feature of plot.ltt(...,log="y")

Shortly after submitting the latest CRAN version of phytools, I discovered in interesting, unexpected “feature” of the new method to overlay a tree on a lineage-through-time plot using ltt.

The behavior appears when we set log="y" in the S3 plotting method for the object of class "ltt" in which we set show.tree=TRUE. If we do that, we see the following:


plot of chunk unnamed-chunk-1


plot of chunk unnamed-chunk-1

At first, it looks OK - but then on closer inspection one quickly sees that the spacing of the edges is off. In fact, they have been plotted on a log, rather than a linear, scale. Oops! This occurs in spite of the fact that the lineage-through-time plot and the added phylogeny use different x & y scales in the standard plot as follows:


plot of chunk unnamed-chunk-2

I just posted an updated version of the code with this feature removed - however if users like it, I will post a workaround hack. I basically set the tip spacing of the plotted tree to exp(1:Ntip(tree) if par()$ylog==TRUE as follows:

    tips<-if(par()$ylog) setNames(exp(1:Ntip(x$tree)),x$tree$tip.label) 
        else setNames(1:Ntip(x$tree),x$tree$tip.label)

Let's try it:

plot(obj,show.tree=TRUE) ## still works

plot of chunk unnamed-chunk-3

plot(obj,log.lineages=FALSE,log="y",show.tree=TRUE) ## fixed

plot of chunk unnamed-chunk-3

That's it.

No comments:

Post a Comment

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