gpt4 book ai didi

r - 绘制系统发育树与 R 中的链接面对面

转载 作者:行者123 更新时间:2023-12-04 12:13:04 25 4
gpt4 key购买 nike

我想使用 ape 在 R 中绘制彼此相对的两个系统发育图包裹。一棵树有 40 个节点,一棵树有 26 个节点:

library(ape)
tree1 <- rtree(40)
tree2 <- rtree(26)
cophyloplot函数将这些与指定链接面对面绘制。

我在指定链接时遇到问题。

请注意,在我的实际 nexus 中树文件,提示标签是文本(如果有必要,我不确定如何将它们更改为数字......)。

链接应如下所示:

如果,在 tree1 nexus 文件,序列的提示标签为 1-40。在 tree2 nexus 文件,提示标签为 1-26。那么链接应该是:
a <- c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40)
b <- c(14,1,4,1,9,12,2,10,6,3,13,5,14,15,18,19,19,7,14,9,10,11,25,22,21,16,23,24,26,17,1,12,12,21,15,16,21,8,20,21)
association <- cbind(a, b)

(即 tree1 中的序列 1 与 tree2 中的序列 14 链接)

所以,我用这样的东西来绘制树木:
cophyloplot(tree1, tree2, assoc=association,length.line=4, space=28, gap=10, rotate=TRUE)

并计算距离矩阵:
dist.topo(tree1, tree2, method = "PH85")

我不太确定我哪里出错了。任何帮助,将不胜感激!

最佳答案

要绘制树木,请尝试此操作

library(ape)
set.seed(1)

# create trees
tree1 <- rtree(40)
tree2 <- rtree(26)

# modify tip labels
tree1$tip.label <- sub("t", "", tree1$tip.label, fixed = T)
tree2$tip.label <- sub("t", "", tree2$tip.label, fixed = T)

# create associations matrix
a <- as.character(c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40))
b <- as.character(c(14,1,4,1,9,12,2,10,6,3,13,5,14,15,18,19,19,7,14,9,10,11,25,22,21,16,23,24,26,17,1,12,12,21,15,16,21,8,20,21))
association <- cbind(a, b)

# plot
cophyloplot(tree1, tree2, assoc = association, length.line = 4, space = 28, gap = 3)

enter image description here

关于r - 绘制系统发育树与 R 中的链接面对面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31285542/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com