简体   繁体   English

在 R 中,如何为系统发育树中的标签着色? (使用来自猿的 BioNj)

[英]in R how can I color the labels from my phylogenetic tree? (using BioNj from ape)

So I have a dataset which looks like this:所以我有一个如下所示的数据集:

Pos sample_1 sample_2 celltypeX_sample3 celltypeY_sample4 celltypeX_sample5
0     0        0              3                  0             1
2     2        1              3                  0             0
5     0        0              0                  0             1
6     1        0              0                  1             0
12    0        1              0                  1             1

from this dataset I can calculate a correlation matrix and a heatmap in R with:从这个数据集中,我可以计算 R 中的相关矩阵和热图:

data = read.table(file = "fileNameX", row.names = 1, header = T, sep = "\t")
correlationData = cor(data)
heatmap(correlationData, cexRow = 0.25, cexCol = 0.25, symm = T)

after this I want to make a phylogenetic tree using the bionj function of the ape library在此之后,我想使用猿库的 bionj function 制作系统发育树

arbol <- bionj(correlationData)

plot(arbol1, cex = 0.25, edge.width = 0.5)

Here is where I get stuck, so i have read that it is possible to change te color of the labels by adding a row that indicates in which color group it should be in. So I added this column which creates the new dataset:这是我卡住的地方,所以我读到可以通过添加一行来更改标签的颜色,该行指示它应该在哪个颜色组中。所以我添加了创建新数据集的这一列:

Pos sample_1 sample_2 celltypeX_sample3 celltypeY_sample4 celltypeX_sample5
0     0        0              3                  0             1
2     2        1              3                  0             0
...
7026  0        1              0                  1             1
clr   0        0              1                  2             1

Is there any way I could color the labels in this way?有什么办法可以用这种方式给标签上色吗? So everything without a celltype in the name (thus named sample_x) should have the same colour and all cell types should have the same color (thus named celltypeX_sampleY)因此,名称中没有单元类型的所有内容(因此命名为 sample_x)都应该具有相同的颜色,并且所有单元类型都应该具有相同的颜色(因此命名为 celltypeX_sampleY)

I hope my question is clear and it is even possible to do this...我希望我的问题很清楚,甚至有可能做到这一点......

a link to the dataset 数据集的链接

You can specify it in the plot.phylo function.您可以在 plot.phylo function 中指定它。 bionj returns a "phylo" class, and when you call plot(arbol1, cex = 0.25, edge.width = 0.5), you are actually using plot.phylo. bionj 返回一个“phylo”class,当您调用 plot(arbol1, cex = 0.25, edge.width = 0.5) 时,您实际上是在使用 plot.phylo。 You can type?plot.phylo to see the options.您可以输入?plot.phylo 来查看选项。

I don't have your data, but below I use an example dataset to add the color label.. Hope this is what you wanted我没有你的数据,但下面我使用示例数据集添加颜色 label.. 希望这是你想要的

library(ape)
data(woodmouse)
trw <- bionj(dist.dna(woodmouse))
# we label samples that have No120 as blue
# others orange
COLS = ifelse(grepl("No120",trw$tip.label),"blue","orange")
plot(trw,tip.color=COLS)

在此处输入图像描述

To add colours to different labels, you can try this:要为不同的标签添加颜色,您可以尝试以下操作:

# from https://www.r-bloggers.com/the-paul-tol-21-color-salute/
tol18rainbow=c("#771155", "#AA4488", "#CC99BB", "#114477", "#4477AA", "#77AADD", "#117777", "#44AAAA", "#77CCCC", "#777711", "#AAAA44", "#DDDD77", "#774411", "#AA7744", "#DDAA77", "#771122", "#AA4455", "#DD7788")
# I assume here, the word before the "_" tells us how to colour the label
TYPE = gsub("_[^ ]*","",arbol$tip.label)
# check the TYPE numbers are correct
col_assignment = tol18rainbow[1:length(unique(TYPE))]
names( col_assignment) = unique(TYPE)
COLS = col_assignment[TYPE]
# then pass COLS into your plot

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM