Monday, December 15, 2014

New (non-CRAN) version of phytools; more on new phytools function add.arrow

I just posted a new non-CRAN version of phytools (go here and pick the latest version, which can be installed from source). I'm working towards an update to phytools on CRAN; but I need to do some more debugging of phytools' new functions, such as locate.yeti and locate.fossil, as well as add some details to new documentation, before I do that.

This latest version now includes the aforementioned locate.fossil. It also includes fitPagel, a relatively simple wrapper function that implements Pagel's 1994 method to test for correlated evolution of two binary characters, as well as the brand new function add.arrow, which adds an arrow to a plotted radial or square phylogram.

Here's a quick demo of the last function in this list:

library(phytools)
packageVersion("phytools")
## [1] '0.4.42'
## simulate tree with realistic tip labels
set.seed(10)
tree<-rtree(n=26)
tree$tip.label<-paste(LETTERS[26:1],"._",sep="",
    replicate(26,paste(sample(letters,sample(3:12,1)),
    collapse="")))
h<-max(nodeHeights(tree))
plotTree(tree,ftype="i")
add.arrow(tree=tree,tip=tree$tip.label[12],angle=40,arrl=0.1*h)
add.arrow(tree=tree,tip=tree$tip.label[6],angle=40,arrl=0.1*h,col="red")
## we can do it without supplying a tree as a function argument
add.arrow(tip=23,offset=8,angle=40,arrl=0.1*h,col="green")
## we can have an arrow point to a node
add.arrow(tip=41,offset=0.5,angle=40,arrl=0.1*h)

plot of chunk unnamed-chunk-1

Of course, as described in the original post the function also works for radial (type="fan") trees, e.g.:

tree<-pbtree(n=64)
tree$tip.label<-paste(sample(LETTERS,64,replace=TRUE),"._",sep="",
    replicate(26,paste(sample(letters,sample(3:12,1)),
    collapse="")))
h<-max(nodeHeights(tree))
plotTree(tree,type="fan",ftype="i")
## setEnv=TRUE for this type is experimental. please be patient with bugs
add.arrow(tree,tip="D._idemqv",col="red")
add.arrow(tree,tip="U._fjgchek",col="blue")

plot of chunk unnamed-chunk-2

And we can use it for plotted objects of class "contMap" and "densityMap", e.g.:

x<-fastBM(tree)
obj<-contMap(tree,x,plot=FALSE)
plot(obj,type="fan",legend=2)
add.arrow(tree,tip="D._idemqv",col="red")
add.arrow(tree,tip="U._fjgchek",col="blue")

plot of chunk unnamed-chunk-3

That's it for now.

No comments:

Post a Comment

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