tangelgram 的彩色线条 - 包猿函数 cophyloplot

Coloured lines for tangelgram - package ape function cophyloplot

我正在尝试对包含相同分类单元的两棵树进行系统发育比较。我想根据隔离站点为连接着色。我原以为我已经成功执行了此操作,但我的工作流程中存在错误,即彩色线条未准确对应隔离站点。我想知道您是否有任何见解,请在下面找到我的可重现示例。

site <- structure(list(name = structure(c(1L, 3L, 4L, 5L, 6L, 7L, 8L,9L, 10L, 2L), .Label = c("t1", "t10", "t2", "t3", "t4", "t5","t6", "t7", "t8", "t9"), class = "factor"), site = c(1L, 1L,1L, 2L, 2L, 3L, 1L, 3L, 2L, 2L)), .Names = c("name", "site"), row.names = c(NA,10L), class = "data.frame") 

library(ape)
t1 <- rtree(10)
t2 <- rtree(10)
order <- cbind(t1$tip.label)
list <- merge(order, site, by.x="V1", by.y="name")
x <- list$site
A <- cbind(t1$tip.label, t1$tip.label)
cophyloplot(t1, t2, assoc = A, show.tip.label = T, space=50, col = x) 

就目前而言,这是我当前的输出:

刚刚在提取提示标签时发现了这个线程,它有效。 correct order of tip labels in ape

我还需要将sort=F合并到合并函数中。

所以为了完成,工作流程如下所示:

site <- structure(list(name = structure(c(1L, 3L, 4L, 5L, 6L, 7L, 8L,9L, 
10L, 2L), .Label = c("t1", "t10", "t2", "t3", "t4", "t5","t6", "t7", "t8", 
"t9"), class = "factor"), site = c(1L, 1L,1L, 2L, 2L, 3L, 1L, 3L, 2L, 2L)), 
.Names = c("name", "site"), row.names = c(NA,10L), class = "data.frame") 

library(ape)
t1 <- rtree(10)
t2 <- rtree(10)
is_tip<- t1$edge[,2] <= length(t1$tip.label)
ordered_tips <- t1$edge[is_tip,2]
order <-t1$tip.label[ordered_tips]
order <- as.data.frame(order)
list <- merge(order, site, by.x="V1", by.y="name", sort=F)
x <- list$site
A <- cbind(t1$tip.label, t1$tip.label)
cophyloplot(t1, t2, assoc = A, show.tip.label = T, space=50, col = x) 

仅作为后续行动,在我的工作中,合并命令更改了标签的正确顺序。我的树结构非常复杂,可能是两棵树之间的 absence/presence 个个体造成了这个问题。我只是通过添加一个带有位置的向量来修复 data.frame.

order <- as.data.frame(order, seq=seq(1:length(order)) )

后者可以轻松地根据树结构重新排列 data.frame。

干杯,