Wednesday, February 24, 2016

Adding node labels (including bootstrap values) to a tree plotted using dotTree

Yesterday, a phytools blog reader asked the following:

Thank you very much for this great addition. May I ask if there's any way to add bootstrap value by each node on the tree plotted by dotTree?

The answer is “yes.” The internal plotting function used by dotTree (phylogram), though not in the namespace of phytools, nonetheless works in similar ways to the S3 plotting method plot.phylo in ape, and other phytools plotting functions such as plotTree, in that it sets the environmental variable "last_plot.phylo" & thus can be used with functions such as nodelabels and tiplabels from the ape package.

Here's a demo which assumes that the bootstrap values are stored as node labels on the object of class "phylo":

##  [1] ""   "76" "88" "88" "80" "91" "99" "95" "85" "89" "81" "83" "98" "98"
## [15] "99" "77" "80" "87" "95" "78" "76" "92" "79" "93" "79"

plot of chunk unnamed-chunk-1

Here, I am going to show the bootstrap proportion as a pie chart at each node:


plot of chunk unnamed-chunk-2

Note that we have to be very careful with things like bootstrap values & posterior probabilities in R because though they are usually stored as node labels, they are actually associted with edges (i.e., splits) not with nodes! This distinction become important if we re-root the tree. Perhaps there should be more on this topic in a future post.

Data for this demo were simulated as follows:

tree<-pbtree(n=26,tip.label=LETTERS) ## random tree
X<-fastBM(tree,nsim=2) ## random traits
## random bootstraps

No comments:

Post a Comment