Search
Question: Customizing gplots heatmap.2 - color range for heatmap and legend for RowSideColors
0
6.6 years ago by
Chao-Jen Wong580
USA/Seattle/Fred Hutchinson Cancer Research Center
Chao-Jen Wong580 wrote:
Hi, Kurinji 1. *adjusting color range on heatmap.2* You can use the mighty "breaks" argument to symmetrically bin your data, ranged from 0 to 1, into color. For instance, bk <- seq(0, 1, by=0.025) heatmap.2z.ma, breaks=bk, col=greenred, blah, blah) It should map values around 0.5 to black color. 2. *obtaining a legend for RowSideColors* First, convert your x$USCS to a factor: f <- factor(x$UCSC) library(RColorBrewer) mycol <- brewer.pal(6, "Set1") ## if you only have 6 levels heatmap.2z.ma, ..., RowSideColors=mycol[f]) The legend can be recreated by legend(x="topleft", legend=levels(f), col=mycol[factor(levels(f))], pch=15) If you want to superimpose the legend on the plot generated by heatmap.2(), you will need to adjust the x, y argument of legend() to position the legend to a more plausible place. Cheers, Chao-Jen ----- Original Message ----- From: "Kurinji Pandiyan" <kurinji.pandiyan@gmail.com> To: bioconductor at r-project.org Sent: Friday, October 28, 2011 8:54:47 AM Subject: [BioC] Customizing gplots heatmap.2 - color range for heatmap and legend for RowSideColors Dear All, I am using package gplots - heatmap.2 - function to plot some data. I would really appreciate your help customizing my heatmap in terms of - 1. *adjusting color range on heatmap.2* - I am using color "greenred" and would like this to consistently range from 0-1. Because one of my datasets does not have values ranging all the way to one, the color scale has been adjusted from 0-0.5, with red being 0.5. This is confusing as it is not consistent with all the other heatmaps where red indicates a value of 1. I would like to change the range of the color scale to always be the same, regardless of dataset - always 0 being green and red being 1, with a gradation of black in between (which greenred does by default anyway) 2. *obtaining a legend for RowSideColors* - I am also trying to use a specific column of my dataframe, which has 6 different levels of annotation, to plot RowSideColors - I was able to do this: x <http: hct.delta.body.ma=""/> <- y[,c(3,9:10)] # 3 is the column with the levels of interest - for coloring - and is labeled "USCS" z <http: hct.delta.ma=""/>.ma <- as.matrix(y[,9:10]) mycol <- c("red", "green", "blue", "purple", "yellow", "black") heatmap.2z.ma <http: hct.delta.ma=""/>, col=greenred, scale = "none", trace="none",keysize = 1.5, main = list("Accessibility Plot", cex = 1.5), margins = c(5,5), cexCol = 1, Rowv = "NULL", RowSideColors=mycol[as.integer( x <http: hct.delta.body.ma=""/>\$USCS)]) This worked well - only issue is, I am not sure how it picked which color to which value. I was eventually able to figure it out with a small sample set but it will be nice to not have to figure it out and to just use code to produce a legend with color and level name. Please let me know how to produce a legend with the colors used for RowSideColors. I would greatly appreciate someone's input. Thanks, Kurinji Graduate Student [[alternative HTML version deleted]] _______________________________________________ Bioconductor mailing list Bioconductor at r-project.org https://stat.ethz.ch/mailman/listinfo/bioconductor Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor -- Chao-Jen Wong Program in Computational Biology Division of Public Health Sciences Fred Hutchinson Cancer Research Center 1100 Fairview Avenue N., M1-B514 PO Box 19024 Seattle, WA 98109 206.667.4485 cwon2 at fhcrc.org