Monday, March 13, 2017

Using ape::nodelabels with plotTree.singletons

I just pushed a small update to plotTree.singletons to address a small issue posted here.

The update assigns the environmental variable "last_plot.phylo" which basically makes the function compatible with ape functions such as nodelabels and tiplabels designed to add features to a plotted tree.

Here is how it works.

First, our tree with singleton (i.e., non-furcating) nodes:

library(phytools)
obj
## 
## Phylogenetic tree with 26 tips and 38 internal nodes.
## 
## Tip labels:
##  A, B, C, D, E, F, ...
## 
## Rooted; includes branch lengths.
plotTree.singletons(obj)

plot of chunk unnamed-chunk-1

Now let's try to add node labels & tip labels:

plotTree.singletons(obj)
nodelabels(cex=0.5)
tiplabels(cex=0.5)

plot of chunk unnamed-chunk-2

Works.

The tree was obtained by using map.to.singleton to convert a "simmap" object to a tree with non-furcating nodes, as follows:

tree<-pbtree(n=26,scale=1,tip.label=LETTERS)
Q<-matrix(c(-1,1,0,1,-2,1,0,1,-1),3,3,
    dimnames=list(letters[1:3],letters[1:3]))
tree<-sim.history(tree,Q,anc="a")
obj<-map.to.singleton(tree)
names(obj$edge.length)<-NULL

That's it.

No comments:

Post a Comment