Tuesday, May 9, 2017

New features in geo.legend for adding a geological (or arbitrary temporal) color legend to a plotted tree

I just pushed some new features for the phytools function geo.legend that I blogged about earlier today.

These features have the effect of invisibly exporting the legend & color scheme that was used to generate the plot. We can also completing turn-off plotting of the color legend (hence returning only the legend to be employed), which makes it easy to apply the legend to forward-in-time rather than merely on backward-in-time trees, as I will show:

library(phytools)
tree<-pbtree(b=0.03,d=0.01,n=200)
h<-max(nodeHeights(tree))
## first get the legend without plotting
plotTree(tree,plot=FALSE)
obj<-geo.legend(alpha=0.3,cex=1.2,plot=FALSE)
## flip the legend direction:
obj$leg<-h-obj$leg
## plot it
plotTree(tree,ftype="off",ylim=c(-0.2*Ntip(tree),Ntip(tree)),lwd=1)
geo.legend(leg=obj$leg,colors=obj$colors,cex=1.2)

plot of chunk unnamed-chunk-1

That's it.

This version of phytools can be obtained from GitHub using devtools.

2 comments:

  1. Hello, Mr. Revell.
    I am Bruno and I'm pretty new in R. This geoscaling legend is just awesome. I've got a phylogeny much less deep than this one. Its maximum height is 0.383. How could I do this kind of coloring in my tree using different time slices (like glacial periods, for example)?
    Thank you very very much for your blog and for helping.

    ReplyDelete
    Replies
    1. Actually I did find how to set a different timescale to the legend. However I'm having some trouble to flip the legend. It is saying I've got the wrong number of dimension in "leg[, 2]", which I don't know how to fix.
      Thank you very much again.

      Delete

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