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)
This version of phytools can be obtained from GitHub using devtools.