Friday, December 4, 2015

Plotting a color gradient from the bottom to the top of a tree

I just discovered this easy way to plot a constant color gradient from the bottom to the top of a tree using some new functionality of the phytools package:

library(phytools)
tree<-rtree(n=26)
tree$tip.label<-LETTERS
x<-fastBM(tree,sig2=0,mu=1,internal=TRUE)
a<-x[as.character(1:tree$Nnode+Ntip(tree))]
x<-x[tree$tip.label]
obj<-contMap(tree,x,anc.states=a,method="user",plot=FALSE)

Object created, now we're ready to plot:

plot(obj,legend=FALSE) ## defaults

plot of chunk unnamed-chunk-2

inv<-setMap(obj,invert=TRUE) ## inverted
plot(inv,legend=FALSE)

plot of chunk unnamed-chunk-2

gs<-setMap(obj,colors=c("white","black")) ## grey scale
plot(gs,legend=FALSE)

plot of chunk unnamed-chunk-2

It even works for circular trees:

tree<-pbtree(n=200)
x<-fastBM(tree,sig2=0,mu=1,internal=TRUE)
a<-x[as.character(1:tree$Nnode+Ntip(tree))]
x<-x[tree$tip.label]
obj<-contMap(tree,x,anc.states=a,method="user",plot=FALSE)
plot(obj,type="fan",ftype="off",legend=FALSE,lwd=4,outline=FALSE)

plot of chunk unnamed-chunk-3

Does anyone care? I'm not sure.

No comments:

Post a Comment

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