[BioC] heatmap_2: How to change the legend on the color key?
Saroj Mohapatra
smohapat at vbi.vt.edu
Mon Mar 9 16:01:10 CET 2009
Hi Yen:
Please find the attached file for the new function (my_heatmap_2.R). I
tried the code the following way (most of it is taken from your example)
by comparing the outputs from the default heatmap_2 and the new function.
Hope it solves the problem.
Best,
Saroj
----------------------
> library(Heatplus)
>
> mm = matrix(rnorm(1000, m=1), 100,10)
> mm = cbind(mm, matrix(rnorm(2000), 100, 20))
> mm = cbind(mm, matrix(rnorm(1500, m=-1), 100, 15))
> mm2 = matrix(rnorm(450), 30, 15)
> mm2 = cbind(mm2, matrix(rnorm(900,m=1.5), 30,30))
> mm=rbind(mm, mm2)
> colnames(mm) = paste("Sample", 1:45)
> rownames(mm) = paste("Gene", 1:130)
>
> max(apply(mm,1,max))
[1] 5.125852
>
> windows()
> heat.col <- c("#FF0000FF", "#FF2400FF", "#FF4900FF", "#FF6D00FF",
+ "#FF9200FF", "#FFB600FF", "#FFDB00FF", "#FFFF00FF",
+ "#FFFF40FF", "#FFFFAAFF")
> heatmap_2(mm, Rowv = NA, Colv = NA, scale="none",
+ legend=1,col=heat.col[length(heat.col):1])
>
> windows()
>
> new.max=7
> breaks <-seq(0, new.max, length.out=11)
> source("my_heatmap_2.R")
> my_heatmap_2(mm, Rowv = NA, Colv = NA,
+ scale="none",breaks=breaks,
+ legend=1,col=heat.col[length(heat.col):1], max.legend.col=new.max)
> sessionInfo()
R version 2.8.1 (2008-12-22)
i386-pc-mingw32
locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] Heatplus_1.12.0
-----------------------
Yen Ngo wrote:
> Dear Saroj,
>
> I would be very much appreciated to have your function. This would save my day.
>
> Thanks a lot.
> Yen
>
>
> -----Ursprungligt meddelande-----
> Från: Saroj Mohapatra [mailto:smohapat at vbi.vt.edu]
> Skickat: den 6 mars 2009 19:21
> Till: Yen Ngo
> Kopia: bioconductor at stat.math.ethz.ch
> Ämne: Re: [BioC] heatmap_2: How to change the legend on the color key?
>
> Hi Yen:
> I think this is related to the fact that color legend is automatically
> derived from the data. If you look at the code for the function
> heatmap_2, e.g.,
> > edit(heatmap_2)
> you would see a line
> dummy.x <- seq(min(x, na.rm = TRUE), *max(x, na.rm = TRUE)*,
> A crude solution is to create your own function (with a different name
> e.g., yen_heatmap_2) with an additional parameter max.legend.col and
> changing the term max(x, na.rm=TRUE) to max.legend.col. Then instead of
> calling heatmap_2 you call yen_heatmap_2(mm, max.legend.col=7). When you
> want the default setting, you call it with max.legend.col=max(x, na.rm=T)
> I checked and it seems to work. If you want, I would send you the
> function with these additional pieces.
> Hope that helps,
> Saroj
>
> Yen Ngo wrote:
>
>>
>>
>> Dear list,
>>
>>
>>
>> Using example from heatmap_2 (Heatplus) i could conduct a heatmap.
>> However when i changed the color key according to
>>
>> a certain range, the labels on the color key didnt change. Is there a
>> way to fix this?
>>
>>
>>
>> Thanks in advance.
>>
>> Yen
>>
>>
>>
>>
>>
>> mm = matrix(rnorm(1000, m=1), 100,10)
>>
>> mm = cbind(mm, matrix(rnorm(2000), 100, 20))
>>
>> mm = cbind(mm, matrix(rnorm(1500, m=-1), 100, 15))
>>
>> mm2 = matrix(rnorm(450), 30, 15)
>>
>> mm2 = cbind(mm2, matrix(rnorm(900,m=1.5), 30,30))
>>
>> mm=rbind(mm, mm2)
>>
>> colnames(mm) = paste("Sample", 1:45)
>>
>> rownames(mm) = paste("Gene", 1:130)
>>
>>
>>
>>
>>
>>> max(apply(mm,1,max))
>>>
>>>
>> [1] 4.452612
>>
>>
>>
>> windows()
>>
>> heat.col <- c("#FF0000FF", "#FF2400FF", "#FF4900FF", "#FF6D00FF"
>> ,"#FF9200FF",
>>
>> "#FFB600FF", "#FFDB00FF", "#FFFF00FF",
>> "#FFFF40FF", "#FFFFAAFF")
>>
>>
>>
>> heatmap_2(mm, Rowv = NA, Colv = NA, scale="none",
>>
>> legend=1,col=heat.col[length(heat.col):1])
>>
>>
>>
>> ## Change the color key to 0-7
>>
>> ## would like color key on the legend to indicate 0-7 not from 0 to the
>> original max value.
>>
>>
>>
>> windows()
>>
>> heat.col <- c("#FF0000FF", "#FF2400FF", "#FF4900FF", "#FF6D00FF"
>> ,"#FF9200FF",
>>
>> "#FFB600FF", "#FFDB00FF", "#FFFF00FF",
>> "#FFFF40FF", "#FFFFAAFF")
>>
>>
>>
>> breaks <-seq(0, 7, length.out=11)
>>
>> heatmap_2(mm, Rowv = NA, Colv = NA,
>>
>> scale="none",breaks=breaks,
>> legend=1,col=heat.col[length(heat.col):1])
>>
>>
>>
>>
>> [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> Bioconductor mailing list
>> Bioconductor at stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/bioconductor
>> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor
>>
>>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: my_heatmap_2.R
URL: <https://stat.ethz.ch/pipermail/bioconductor/attachments/20090309/24fe0d52/attachment.pl>
More information about the Bioconductor
mailing list