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
inv<-setMap(obj,invert=TRUE) ## inverted
plot(inv,legend=FALSE)
gs<-setMap(obj,colors=c("white","black")) ## grey scale
plot(gs,legend=FALSE)
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)
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.