[英]in R how can I color the labels from my phylogenetic tree? (using BioNj from ape)
所以我有一個如下所示的數據集:
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 中的相關矩陣和熱圖:
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 function 制作系統發育樹
arbol <- bionj(correlationData)
plot(arbol1, cex = 0.25, edge.width = 0.5)
這是我卡住的地方,所以我讀到可以通過添加一行來更改標簽的顏色,該行指示它應該在哪個顏色組中。所以我添加了創建新數據集的這一列:
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)
我希望我的問題很清楚,甚至有可能做到這一點......
數據集的鏈接
您可以在 plot.phylo function 中指定它。 bionj 返回一個“phylo”class,當您調用 plot(arbol1, cex = 0.25, edge.width = 0.5) 時,您實際上是在使用 plot.phylo。 您可以輸入?plot.phylo 來查看選項。
我沒有你的數據,但下面我使用示例數據集添加顏色 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)
要為不同的標簽添加顏色,您可以嘗試以下操作:
# 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.