Monday, May 14, 2012

Neat way to plot a slanted phylogram in phytools that almost always works

I'm not sure what I was doing when I thought to try this, but I realized that the phytools function phenogram can also be used to plot a neat looking slanted phylogram. This works as follows:

> tree<-pbtree(n=20,scale=100)
> # we do the following to make sure the tips are
> # in the right order
> tree<-read.tree(text=write.tree(tree))
> x<-1:length(tree$tip)
> names(x)<-tree$tip.label
> phenogram(tree,x)

Here the horizontal axis is time since the root, and the vertical axis doesn't mean anything of course. Unfortunately, as alluded in the post title, this only works most of the time - particularly when the tree has a lot of tips. For example, for one stochastic 50 taxon tree I get the following problem:

Obviously, the branches of the tree cross in a couple of different spots, which is no good. If we are determined to plot a tree in this format, we could try rotating the offending nodes above the problematic crossings and then replot our tree:

> plotTree(tree,node.numbers=T)
> tree<-rotate(tree,95)
> tree<-rotate(tree,53)
> tree<-read.tree(text=write.tree(tree))
> x<-1:length(tree$tip)
> names(x)<-tree$tip.label
> phenogram(tree,x)

It worked - at least for this particular case.

Some users might note that ape can also plot a slanted phylogram:

> plot.phylo(tree,type="cladogram")
But, obviously, this visualization has a very different look compared to the one we created previously. I'm not aware of other packages that might have an analogous function. Perhaps some readers of this blog are.

No comments:

Post a Comment