Wednesday, July 5, 2017

User control of arc width & color in arc.cladelabels

The other day I received the following email:

“I am playing around with the new arc.cladelabels function. Is it possible to add in options for color and line thickness. I see it calls draw.arc internally so I am assuming it would just be a matter of adding the options "col" and "lwd" in the function? It would be useful to have alternating or different colors and/or line widths for when you are labeling all clades in the tree and there is not much space between the arcs.”

Indeed, these are relatively simple options to add, which I have just done on GitHub. I also added an additional option which is to specify the node corresponding to the common ancestor of the clade to be labeled interactively.

The latter option is hard to demonstrate (absent a video); however the former options work as follows:

library(phytools)
tree
## 
## Phylogenetic tree with 200 tips and 199 internal nodes.
## 
## Tip labels:
##  t7, t23, t24, t126, t127, t35, ...
## 
## Rooted; includes branch lengths.
plotTree(tree,type="fan",lwd=1,ftype="off")
nodes
## [1] 203 215 264 288 323 356
text<-paste("Clade",LETTERS[1:length(nodes)])
text
## [1] "Clade A" "Clade B" "Clade C" "Clade D" "Clade E" "Clade F"
library(RColorBrewer)
cols<-brewer.pal(length(nodes),"Accent")
nulo<-mapply(arc.cladelabels,text=text,node=nodes,col=cols,
    MoreArgs=list(mark.node=FALSE,lwd=6))

plot of chunk unnamed-chunk-1

This function version should be obtained by installing the latest development version of phytools from GitHub.

No comments:

Post a Comment