tangelgram的彩色线条-封装ape函数cophyloplot [英] Coloured lines for tangelgram - package ape function cophyloplot

查看:318
本文介绍了tangelgram的彩色线条-封装ape函数cophyloplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to do a phylogenetic comparison of two trees which contain the same taxa. I want to colour the connections based on isolation site. I had thought I had performed this successfully but there is error in my work flow i.e. the coloured lines are not corresponding to isolation site accurately . I was wondering if you have any insights, please find my reproducible example below.

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) 

按现状,这是我当前的输出:

As it stands this is my current output:

推荐答案

仅在提取提示标签时发现了该线程,它就可以工作. 小费的正确顺序猿中的标签

Just spotted this thread on extracting tip labels and it works. correct order of tip labels in ape

我还需要将sort=F合并到合并功能中.

I also need to incorporate sort=F into the merge function.

最后,工作流程如下:

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) 

这篇关于tangelgram的彩色线条-封装ape函数cophyloplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆