[英]R - Add a colored side bar to a heatmap.2
I have several problems with R. I am trying to plot a heatmap with both row and col dendrograms, till here everything is okay. 我在使用R时遇到了几个问题。我正在尝试绘制带有行图和列树图的热图,直到此处一切正常。 Now I want to add a side bar using ColSideColors.
现在,我想使用ColSideColors添加侧边栏。 The colors depends of the proteins' domains, I have these data in a different vector called domains, containing the names of the proteins and the colors associated to the domains.
颜色取决于蛋白质的域,我将这些数据保存在称为域的不同载体中,其中包含蛋白质的名称和与域相关的颜色。 I have already check, each domain has a color, everything is fine.
我已经检查过,每个域都有一种颜色,一切都很好。 But when I add the side bar to the plot, it seems that the color are not in the correct order.
但是,当我将侧栏添加到绘图中时,似乎颜色的顺序不正确。 How can I fix this ?
我怎样才能解决这个问题 ? Please find the code bellow :
请找到下面的代码:
domains <- read.table("pubchem_proteins_domains.csv", sep = ",", dec = ".", quote = "\"")
domains$values <- (domains$V2 - min(domains$V2))/(max(domains$V2) - min(domains$V2))
domains$gray <- gray(domains$values)
head(domains)
V1
1 P10275.ANDR_HUMAN.Androgen.receptor.OS.Homo.sapiens.GN.AR.PE.1.SV.2
2 P00915.CAH1_HUMAN.Carbonic.anhydrase.1.OS.Homo.sapiens.GN.CA1.PE.1.SV.2
3 P00918.CAH2_HUMAN.Carbonic.anhydrase.2.OS.Homo.sapiens.GN.CA2.PE.1.SV.2
4 P22748.CAH4_HUMAN.Carbonic.anhydrase.4.OS.Homo.sapiens.GN.CA4.PE.1.SV.2
5 P21554.CNR1_HUMAN.Cannabinoid.receptor.1.OS.Homo.sapiens.GN.CNR1.PE.1.SV.1
6 P24941.CDK2_HUMAN.Cyclin-dependent.kinase.2.OS.Homo.sapiens.GN.CDK2.PE.1.SV.2
V2 values gray
1 16 0.60 #999999
2 7 0.24 #3D3D3D
3 7 0.24 #3D3D3D
4 7 0.24 #3D3D3D
5 2 0.04 #0A0A0A
6 22 0.84 #D6D6D6
mol_distances <- read.table("pubchem_molecular_distances.csv", header = T, sep = ",")
row.names(mol_distances) <- mol_distances[,1]
mol_distances <- mol_distances[,-c(1)]
alignment <- read.alignment(file = "pubchem_alignment.txt", format = "clustal")
prot_distances <- dist.alignment(alignment)
hc_mol <- hclust(as.dist(mol_distances), method="ward")
hc_prot <- hclust(as.dist(prot_distances), method="ward")
heatmap.2(dat_mat,
Rowv = as.dendrogram(hc_prot),
Colv = as.dendrogram(hc_mol),
RowSideColors=domains$gray[domains$proteins_name],
dendrogram = "both",
scale = "none",
margins = c(12,24),
key = TRUE,
keysize = 1.0,
col = rainbow(512, start = 1, end = 0.4),
density.info="density",
denscol = "black",
xlab="Compounds",
ylab="Targets", main="X Activity Profile",
trace ="none")
Beside, I could not find another function to do similar things in R for colors, can i do the same with rainbow ? 另外,我找不到其他函数可以在R中为颜色做类似的事情,我可以对Rainbow做同样的事情吗?
Thank you Regards Deuterium 谢谢问候氘
Well, I solved my problem, it seems that they were several problem within my data sets, meaning that the R script is correct. 好吧,我解决了我的问题,看来这是我数据集中的几个问题,这意味着R脚本是正确的。 Now the colors are assigned to the correct proteins.
现在将颜色分配给正确的蛋白质。 But I still don't know if it is possible to do similar side bar using other colors than gray, to make it more clear.
但是我仍然不知道是否可以使用除灰色以外的其他颜色来制作类似的侧边栏,以使其更加清晰。
Thank you Deuterium 谢谢氘
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.