[BioC] heatmap_2: How to change the legend on the color key?
Yen Ngo
yen.ngo at smi.se
Mon Mar 9 08:17:05 CET 2009
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
>
More information about the Bioconductor
mailing list