[R] Heatmap Colors

David Winsemius dwinsemius at comcast.net
Sat Sep 29 02:04:55 CEST 2012


On Sep 28, 2012, at 4:52 PM, David Winsemius wrote:

> 
> On Sep 28, 2012, at 3:16 PM, Nick Fankhauser wrote:
> 
>> Hello R-Users!
>> 
>> I'm using a heatmap to visualize a matrix of values between -1 and 3.
>> How can I set the colors so that white is zero, below zero is blue of increasing intensity towards -1 and above zero is red of increasing intensity towards red?
>> 
>> I tried like this (using the marray and gplots packages from bioconductor):
>> mcol <- maPalette(low="blue", mid="white", high="red",k=100)
>> heatmap.2(my_matrix, col=mcol)
>> 
>> But white does not correspond to zero, because the value distribution is not symmetrical, so that zero is not in the middle.
>> Is it somehow possible to create a color palette with white centered at zero?
> 
> The way you stated it at the beginning, I thought you should want the palette centered at 1 rather than 0:

Oopps ... should have the number of breaks match the number of colors:

test <- seq(-1,3, len=20)
shift.BR <- colorRamp(c("blue","white", "red"), bias=2)((1:20)/20)
tpal <- rgb(shift.BR, maxColorValue=255)
barplot(test,col = tpal)
> 
-- 

David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list