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


  1. Thank you for a fantastic package! I'm wondering how to label only specific nodes on a phylogeny based on the labels from the function nodelabels()? I'm interested in only labeling bootstrap support for the deeper nodes in my phylogeny and have a vector of nodelabels I'm interested in but am unsure how to access the bootstrap support for those labels. For example :
    how would I access the bootstrap support in t$tip.label for nodes labeled : c(1093, 1073, 1068)?

    nodelabels(t$tip.label?? , adj=c(1,-0.4),frame="none", cex=0.7,
    node = c(1093, 1073, 1068))

    Thank you!

    1. Hi Katie. Why are you bootstrap support values stored in the tip labels? Normally I would expect them to be stored as node labels. In which case you should be able to do something like:


      in which ... are the other arguments you want to send to nodelabels.

      Let me know if this gets you on the right track.

      - Liam

  2. Excellent, thank you! Yes, my bootstrap support values were stored as node labels. In the future, is there a place where node numbers are stored? Is there a way to access them other than visualizing them on the tree with the nodelabels function? Thank you!

    1. They should be in the vector tree$node.label.

      All the best, Liam

  3. It is really a great work and the way in which you are sharing the knowledge is excellent.Thanks for your informative article

    web designing course in chennai

  4. I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much.
    HTML5 courses in chennai

  5. Bootstrap is one of the best framework among all and it is being used almost everywhere. thanks for sharing this article.

  6. Hello, can you help?. I wrote my question in I have a problem to show bootstrap in my tree using R.

    Thanks a lot

  7. Indeed Bootstrap is the best and very popular framework for website design. Thanks for the article. I really enjoyed this. Thanks for the dotTree code! hire magento developer

  8. This comment has been removed by the author.

  9. Next time you go after that power tool, ensure you audit the wellbeing rules gave in the guidance manual, and consider the critical security safety measures laid out in this article.tire inflator