问题描述
我正在使用 R 包 adegenet
来绘制邻接树.
I am using the R package adegenet
to plot the neighbor-joining tree.
在我的文件中,我有 20,000 列和 500 行.行对应于个人.我的第一列是人口 ID,第二列是个人 ID.列包含值 0,1 &2. 我可以用一种颜色绘制一棵树,但根据人口数量,我希望每个集群都是不同的颜色.
In my file I have 20,000 columns and 500 rows. Rows correspond to individuals. My first column is Population ID and second column is Individual ID. Columns contain values 0,1 & 2. I am able to plot a tree in one color, but depending upon the population I want every cluster to be a different color.
这就是我所做的,如果dat"是我的数据文件,那么
This is what I did, If "dat" is my data file,then
D<-dist(as.matrix(dat))
tre<-nj(D)
plot(tre, type = "unr", show.tip.lab = TRUE, cex=0.3, font=1, edge.col="Blue")
如果我尝试 edge.col=c("red","green","blue")
我遇到以下错误:
If I try edge.col=c("red","green","blue")
I run into following error :
Error in if (use.edge.length) unrooted.xy(Ntip, Nnode, z$edge, z$edge.length, :
argument is not interpretable as logical
非常感谢您的帮助!
推荐答案
您的示例应该是可重现的,以便更容易帮助和重现您的问题.请参阅此帖子以了解更多详情.我正在尝试使用 iris
,它的作用就像一个魅力.顺便说一下,我认为这里不需要 adegenet
,plot
实际上是 ape
包中的 plot.phylo
code>),所有其他函数要么是内置的,要么来自 ape
).
Your example should be reproducible, so that it would be easier to help and reproduce your problem. See this post for more details. I'm trying with iris
and it works like a charm. By the way, I think adegenet
is not required here, the plot
is actually a plot.phylo
from the package ape
), and all other functions are either built-in or from ape
).
文档 (?plot.phylo
) 说:
edge.col
模式字符向量,给出用于绘制绘制系统发育分支的颜色.这些被认为与 phy 的分量边的顺序相同.如果给出的颜色少于边的长度,则颜色被回收.
ape
保留顺序或行,您可以使用 factor
来索引颜色向量,因此使用 iris
的可重现示例可能是:
ape
preserves the order or rows, and you can use a factor
to index you vector of colors, so a reproducible example using iris
could be:
library(ape)
D <-dist(as.matrix(iris[, 1:4]))
tree <- nj(D)
plot(tree, type = "unr", show.tip.lab = TRUE, cex=0.3, font=1,
edge.col=c("red","green","blue")[iris$Species])
这是你想要的吗?
这篇关于使用adegenet R包为树中的不同簇设置不同颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!