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)
That's it.
This version of phytools can be obtained from GitHub using devtools.
Hello, Mr. Revell.
ReplyDeleteI 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.
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.
DeleteThank you very much again.