1

我想根据为该树的每个分支估计的一些值绘制具有颜色的系统发育树。根据plot.phylophytools 的各种功能,有可能:plot.phylo(tree,edge.color=col)但向量 col 必须遵循tree$edge.

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

简短的例子:

test.mod:
((a:1,b:1)a-b:1,(c:1,d:1)c-d:1)a-d;

test.data:
a 0.5
b 0.6
a-b 1
c 2.5
d 2
c-d 2.1
a-d 1.5

在此先感谢,泽维尔

4

1 回答 1

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)

在此处输入图像描述

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

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]])

在此处输入图像描述

编辑:您必须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)
于 2014-02-28T17:56:04.167 回答