微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

向 ggtree 添加引导值的问题

如何解决向 ggtree 添加引导值的问题

我根据表型特征制作了一棵树,例如: 物种1 2102102 物种2 1101210, 其中数字是特征的表示。我计算了汉明距离,然后将它们归一化。接下来,我创建了一个 NJ 树,然后使用了这个函数https://augix.github.io/wiki/Make%20trees%20in%20R,%20test%20its%20stability%20by%20bootstrapping.html 这是输出: 新泽西树

enter image description here

现在我想使用 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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?