I am thankful for How Do I Draw A Heatmap In R With Both A Color Key And Multiple Color Side Bars? in R where you can add row and column information together with the color mapping information. I use it all the time to make pictures of hierarchically clustered expression profiles measured by expression arrays.
Usually I scale the input matrix on rows (probesets) to Z-scores in order to make weigh equally in the clustering. The colors of the heatmap are mapped linearly to the Z-scores. \
The problem is, when you have a few extremes in your data set, they tend to make your heatmap a little faint. In the attached heatmap you can see that the Z-scores range from somewhere around -10 to 10, however, about 99% is in the range of -4 to 4. I would like to change the way colors are mapped to the Z-scores in such a way that the green-to-red goes from -4 to 4 and the colors of the Z-scores outside this range just do not become any more green or red then they are already, any ideas?
# import gplots for greenred colors
library(gplots)
# generate random matrix
x<-replicate(100,rnorm(100,0,1))
# draw heatmap
heatmap.3(x,density.info="histogram",col=greenred)
# introduce outliers
x[1,1] <- -10
x[2,2] <- 10
# draw heatmap with outliers
heatmap.3(x,density.info="histogram",col=greenred)
Thanks, thats it!
It's like a learning time machine. 16 months on and this is exactly what I needed. Thanks!