在R中,如何根据系统发育树的尖端和边缘排序数据向量?

时间:2014-02-28 16:39:47

标签: r colors tree phylogeny

我想根据为该树的每个分支估计的一些值来绘制具有颜色的系统发育树。根据{{​​1}}和植物工具的各种功能,有可能:plot.phylo但矢量col必须遵循plot.phylo(tree,edge.color=col)的顺序。

问题在于:我的数据包括边缘和提示,是否可以在一致的调色板中绘制?

简短的例子:

tree$edge

提前致谢, 泽维尔

1 个答案:

答案 0 :(得分:3)

这取决于你想要实现的目标。有些方法可以很容易地自动化(例如我的第二个例子)。

恕我直言,你必须手动为你的树上色,如果你想根据分类法或类似的东西给每个分支一个不同的颜色,例如:

library("ape")
tree <- read.tree("tree.mod")

tree$edge
#     [,1] [,2]
#[1,]    5    6 # root -> a:b
#[2,]    6    1 # == "a"
#[3,]    6    2 # == "b"
#[4,]    5    7 # root -> c:d
#[5,]    7    3 # == "c"
#[6,]    7    4 # == "d"

cols <- rep(c("red", "green"), each=3)
plot.phylo(tree, edge.col=cols)

enter image description here

一个可以自动完成的简单示例是为最后一片叶子着色,例如:

ntips <- length(tree$tip.label)
cols <- c(rainbow(ntips), rep("black", nrow(tree$edge)-ntips+1))
plot.phylo(tree, edge.col=cols[tree$edge[,2]])

enter image description here

编辑:在匹配之前,您必须按tree$edge[,2]订购标签。请在下面找到一个例子:

library("ape")
tree <- read.tree("tree.mod")

myColors <- c(node="black", a="red", b="green", c="blue", d="purple")
myLabels <- c(tree$tip.label, tree$node.label)

## match colors and labels (nomatch == node => select idx 1)
## (myLabels are reordered by edge ordering
selColors <- myColors[match(myLabels[tree$edge[,2]], names(myColors), nomatch=1)]

plot.phylo(tree, edge.col=selColors)
相关问题