简体   繁体   中英

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. Now I want to add a side bar using 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 ?

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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