我想使用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")
我不太确定我在哪里出错了。任何帮助,将不胜感激!
答案 0 :(得分:4)
要绘制树木,请尝试此
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)
答案 1 :(得分:1)
cophyloplot
功能不需要提示标签索引。人们可以用他们的名字来指代分类群。请注意,lukeA的答案将关联中的数字存储为character
。将它们转换为与提示标签对应的文本并绘制两棵树的结果显示相同的结果。
association <- apply(association, 2, function(x) sub("^","t", x))
head(association)
# a b
# [1,] "t1" "t14"
# [2,] "t2" "t1"
# [3,] "t3" "t4"
# [4,] "t4" "t1"
# [5,] "t5" "t9"
cophyloplot(tree1, tree2, assoc=association, length.line=4, space=28, gap=3)
矩阵中列出关联的顺序无关紧要。最佳做法是使用read.table()
从外部文件导入它们。