如何解决向 ggtree 添加引导值的问题
我根据表型特征制作了一棵树,例如: 物种1 2102102 物种2 1101210, 其中数字是特征的表示。我计算了汉明距离,然后将它们归一化。接下来,我创建了一个 NJ 树,然后使用了这个函数:https://augix.github.io/wiki/Make%20trees%20in%20R,%20test%20its%20stability%20by%20bootstrapping.html 这是输出: 新泽西树
现在我想使用 ggtree
,但我不知道如何根据我的距离将这些引导值添加到普通的 NJ 树中。问题是当 boot.tree
函数的输出只有 9 个数字时,有 20 个节点。
代码:
#creating tree from matrix of normalized hamming distances
seed_NJ <-NJ(final_matrix2)
plot(seed_NJ,main="Neighbor Joining")
#https://augix.github.io/wiki/Make%20trees%20in%20R,%20test%20its%20stability%20by%20bootstrapping.html
boot.tree <- function(data,B = 10000,tree = "upgma") {
func <- function(x) upgma(dist(x,method = "euclidean"),method="average")
if (tree == "nj") {
func <- function(x) nj(dist(x,method = "euclidean"))
}
if (tree == "hclust") {
func <- function(x) {
tr = hclust(dist(x,method = "euclidean"))
tr = as.phylo(tr)
return(tr)
}
}
tr_real = func(data)
plot(tr_real)
library(ape)
bp <- boot.phylo(tr_real,data,FUN=func,B=B)
bp <- bp/B
bp <-round(bp,digits=2)
bp <- bP*100
nodelabels(bp)
print(bp)
return(bp)
}
data = (final_matrix2)
#bootstrap
my_tree <- boot.tree(data,tree='nj')
#trying to add bootstrap here,but the number of nodes is 20,while I have 9 bootstrap values
library(ggtree)
plottree <- ggtree(seed_NJ) + theme_tree2()+ geom_tiplab(size=3,color="purple")+ geom_text(aes(label=node),hjust=-.3)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。