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

use*_*089 5 r phylogeny

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

library(ape)
tree1 <- rtree(40)
tree2 <- rtree(26)
Run Code Online (Sandbox Code Playgroud)

cophyloplot函数使用指定的链接面对面地绘制这些图。

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

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

链接应如下所示:

如果,在tree1Nexus文件中,序列的尖端标签是1-40。在tree2Nexus 文件中,提示标签为 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)
Run Code Online (Sandbox Code Playgroud)

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

所以,我用这样的东西来绘制树木:

cophyloplot(tree1, tree2, assoc=association,length.line=4, space=28, gap=10, rotate=TRUE)
Run Code Online (Sandbox Code Playgroud)

并计算距离矩阵:

dist.topo(tree1, tree2, method = "PH85")
Run Code Online (Sandbox Code Playgroud)

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

luk*_*keA 5

要绘制树木,请尝试以下操作

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)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述