Sunday, July 7, 2013

Plotting 'partial' circular trees

At this year's Evolution meeting in Snowbird, Utah, I saw a very nice poster by Patrick Fuller of the Wainwright Lab at UCDavis. One cool attribute of the poster was that he had a half circular phylogeny aligned to the bottom of this poster. My immediate thought, naturally, was that phytools should do this.

I have now added this capability to the functions plotSimmap (as well as plotTree, which uses plotSimmap internally). I have included these updates in a new non-CRAN release of phytools (phytools 0.2-91), which can be downloaded and installed from source.

Doing this was not hard. Basically, when we are deciding the circular positions of all the terminal edges of the tree, we start by ordering them cladewise, and then we evenly space the tips from 0 through 2π before wrapping them into our circular space. (I describe this a little more here.) To plot a partial fan tree, we just decide what fraction, θ, of the circle we want to use, then we space our terminal edges, instead of evenly from 0 to 2π, evenly from 0 through 2πθ. Aside from resizing our plot axes to match - that's pretty much all there is to it.

Here's a quick demo of the results:

> library(phytools)
> packageVersion("phytools")
[1] ‘0.2.91’
> data(anoletree)
> plotSimmap(anoletree,type="fan",part=0.5,fsize=0.9, ftype="i")
no colors provided. using the following legend:
    CG     GB      Non-     TC     TG        Tr        TW
"black"  "red"  "green3" "blue" "cyan" "magenta"  "yellow"

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

> ss<-sort(unique(getStates(anoletree,"tips")))
> add.simmap.legend(colors=setNames(palette()[1:length(ss)],ss))
Click where you want to draw the legend
(Click here for full resolution.)

Pretty cool. That's about what we were going for. Here's a smaller, simulated 1/4 fan tree - again, with a mapped discrete character:

> Q<-matrix(c(-1,1,1,-1),2,2)
> tree<-sim.history(pbtree(n=40,scale=1),Q,anc=1)
> plotSimmap(tree,colors=setNames(c("blue","red"),1:2), type="fan",part=0.25,lwd=4)

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

> add.simmap.legend(colors=setNames(c("blue","red"),1:2))
Click where you want to draw the legend

That's it.

No comments:

Post a Comment

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