Tuesday, May 15, 2012

Addendum to previous post on plotting slanted phylograms with phytools::phenogram

In my last post I demonstrated how the phytools function phenogram could be used to plot a slanted phylogram - at least most of the time. The ape phylogenetics package function plot.phylo can also plot slanted phylograms (by setting type="cladogram" for a tree with branch lengths assigned), but this phylogram has a fundamentally different style than the type created by phenogram. The effect in particular is one in which the branches of the tree plotted with phenogram slant much more gently from the root than the branches in plot.phylo(...,type="cladogram"). The following graphic contrasts the two styles:

While I was musing about yesterday's post this morning, it occurred to me that plot.phylo(...,type="cladogram") kind of looks like it uses the same method as phenogram, but with the positions of the internal nodes determined by computing the "ancestral state" (that is, of the y coordinate of the tip) for the root node of each subtree separately. This could be accomplished using ace(...,method="pic") in the ape package. Well, this is not, in fact, how plot.phylo(...,type="cladogram") works, but the two methods visually present as almost identical. For instance:

> set.seed(1)
> tree<-read.tree(text=write.tree(pbtree(n=50)))
> plot.phylo(tree,type="cladogram")
> x<-1:50; names(x)<-tree$tip.label
> a<-ace(x,tree,method="pic")$ace
> x11(); phenogram(tree,c(x,a))

It turns out that both of these methods can sometimes result in lines that cross. For instance:

> set.seed(25)
> tree<-pbtree(n=50)
> plot.phylo(tree,type="cladogram")

Now, I'm not sure whether to characterize this as a bug in plot.phylo or not. Evidently, it is not always possible to avoid having lines cross when we want our tip labels to be evenly spaced on the vertical axis. This is stated in Felsenstein (2008; p. 576): "Note that with many of these methods (for plotting slanted phylograms), one cannot always avoid having lines cross. . . . The only way of avoiding crossing is to have the tips not be evenly spaced along the y axis." Clearly, in the above plotted example it would be possible to redraw this tree with the same horizontal branch lengths and no crossing lines, no?

No comments:

Post a Comment