刚刚在提取尖端标签上发现了这个线程,它起作用了。ape 中尖端标签的正确顺序 https://stackoverflow.com/questions/34364660/how-to-get-correct-order-of-tip-labels-in-ape-after-calling-ladderize-function
我还需要合并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)