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.

1 comment:

  1. Hello Liam,
    I hope you are doing good. I was trying to use phylogenetic independent contrast (pic) using ape package. I can do this for individual variable. Is there any way to do all together using a for loop or other alternatives?
    > g1=setNames(f1[,1],row.names(f1)) #(f1 is the dataframe)
    > pic.gene<-pic(g1,t1) # t1 is the phylogentic tree (it works good)
    > g_all=setNames(f1[,1:196],row.names(f1)) #all variable, woking good
    > pic.g<-pic(g_all,t1) #doesn't work, Error in pic(g_all, t1) :
    length of phenotypic and of phylogenetic data do not match

    Looking forward to here from you.
    Best regards
    Zillur Rahman
    Graduate student
    University of Puerto Rico, Rio-Peadras




    ReplyDelete

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