I want to annotate a phylogenetic tree with bootstrap and add color to certain clades in ggtree. Something goes wrong when I try to do both, which has something to do with the indices of the internal nodes.
Here is a random tree with 24 tips:
library(ape) set.seed(123) rtree <- rtree(24)
The following identifies the nodes to which I want to assign different colors:
rtree.clade <- groupClade(rtree, c(44, 37, 29))
These are the bootstrap scores:
rtree.bs <- c(1000, 918, 966, 997, 661, 631, 711, 1000, 980, 991, 999, 998, 1000, 1000, 990, 1000, 980, 1000, 899, 755, 654, 908, 334)
In the following two trees, the bootstrap scores do not show up on the same nodes:
#Tree with color added to clades library(ggtree) ggtree(rtree.clade, aes(color = group)) + geom_tiplab() + geom_nodelab(label = rtree.bs, geom = 'label') #Tree with no color ggtree(rtree.clade) + geom_tiplab() + geom_nodelab(label = rtree.bs, geom = 'label')
In the tree without color, the bootstrap scores have been assigned to the correct nodes. It is the tree with color that is incorrect. What am I doing wrong?