在R中,如何为系统发育树中的标签着色? (使用猿的BioNj) [英] in R how can I color the labels from my phylogenetic tree? (using BioNj from ape)

查看:559
本文介绍了在R中,如何为系统发育树中的标签着色? (使用猿的BioNj)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个像这样的数据集:

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

从该数据集中,我可以使用以下公式计算R中的相关矩阵和热图:

from this dataset I can calculate a correlation matrix and a heatmap in R with:

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)

此后,我想使用猿库的bionj函数制作系统发育树

after this I want to make a phylogenetic tree using the bionj function of the ape library

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

我可以通过这种方式为标签上色吗? 因此,名称中没有单元格类型的所有内容(因此命名为sample_x)应具有相同的颜色,所有单元格类型均应具有相同的颜色(因此名为celltypeX_sampleY)

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)

我希望我的问题很清楚,甚至有可能做到这一点...

I hope my question is clear and it is even possible to do this...

数据集

推荐答案

您可以在plot.phylo函数中指定它. bionj返回一个"phylo"类,当您调用plot(arbol1,cex = 0.25,edge.width = 0.5)时,您实际上是在使用plot.phylo.您可以键入?plot.phylo以查看选项.

You can specify it in the 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. You can type ?plot.phylo to see the options.

我没有您的数据,但是下面我使用示例数据集添加颜色标签.希望这就是您想要的

I don't have your data, but below I use an example dataset to add the color label.. Hope this is what you wanted

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

这篇关于在R中,如何为系统发育树中的标签着色? (使用猿的BioNj)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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