Wednesday, July 10, 2013

Adding a scale bar to a partial circular tree

Here's a neat trick that I thought of yesterday. We can pretty easily add a scale bar to a partial circular tree created using plotTree(...,type="fan") in the phytools package, and here's how:

> library(phytools)
> packageVersion("phytools")
[1] ‘0.2.93’
> # for this demo - simulate a tree of length 100
> tree<-pbtree(n=100,scale=100)
> # plot it
> # (you'll probably need to tweak 'part' to fit the axis)
> plotTree(tree,type="fan",part=0.93,fsize=0.9)

Note: type="fan" is in development.
Many options of type="phylogram" are not yet available.

> # ok, now plot the axis
> h<-max(nodeHeights(tree))
> axis(1,pos=-0.05*h,at=seq(0,h,by=h/2),lwd=2)
> text(x=0.5*h,y=-0.25*h,"time")

That's pretty cool.

No comments:

Post a Comment

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