[BioC] How to adjust the Heatmap.2 color key

Jenny Drnevich drnevich at illinois.edu
Wed Jul 9 17:56:46 CEST 2008


Hi Benjamin,

Good points! Some adjustments to codes:

>1. Jennys solution, as far as I can see with a 
>quick glimpse on the code, will give you an 
>asymmetric binning size on each side of the zero 
>value, as long as you set the length.out 
>argument is 50 for each color. So if you do want 
>to use maybe an equal bin size (e.g. each step 
>about 0.5 signal) then you'll have to adjust the 
>number of color bins according to the ratio of the min and max.

Make symmetrical bins of 0.5 signal ranging to +/- 10:

 > pairs.breaks <- seq(-10, 10, by=0.5)
 > length(pairs.breaks)
[1] 41

Then make a color panel that has 40 bins (one less than the number of breaks):

 > mycol <- colorpanel(n=40,low="green",mid="black",high="red")
 > length(mycol)
[1] 40

Then when you call heatmap.2, subset both 
pairs.break and mycol to the range of your data 
(in this case, trim off the first 6 and last one 
breaks/colors to range from -7 to 9.5):

 > heatmap.2(heatdata, breaks=pairs.breaks[7:40], col=mycol[7:39])


>2. The reason I didn't have that argument in 
>mind that moment was a nice and mighty feature 
>of that "breaks" argument I used to associate it 
>with. That is the possibility of the asymmetric 
>bin sizes from another point of view. Suppose 
>you have some very few outliers with very 
>extreme values masking your real data 
>distribution then they will tend to spread the 
>color scale on the edges and condense it in the 
>middle. You won't see the real differences in 
>your normal value range because they will 
>probably have very similar colors. In this case 
>you can replace parts of Jennys pairs.breaks 
>sequence with bins derived from your data quantiles.

Here's a simple situation of just having the 
final bin be a + group. Say you have an outlier:

 > sort(heatdata,decreasing=T)[1:5]
[1] 255.1548114 9.167324 6.802191 4.948795 4.789992

You could adjust the final break so that the final bin means 9.5+ :
 > pairs.breaks[40:41]
[1]  9.5 10.0

 > pairs.breaks[41] <- 500

 > pairs.breaks[40:41]
[1]   9.5 500.0

Then just cut off the first 6 breaks/colors

 > heatmap.2(heatdata, breaks=pairs.breaks[7:41], col=mycol[7:40])

Of course, how then do you change the labels on the color key to indicate 9.5+?

Jenny


>Regards, Benjamin -----Ursprüngliche 
>Nachricht----- Von: Jenny Drnevich 
>[mailto:drnevich at illinois.edu] Gesendet: 
>Wednesday, July 09, 2008 3:49 PM An: Benjamin 
>Otto; 'Martin Bonke'; 
>bioconductor at stat.math.ethz.ch Betreff: Re: 
>[BioC] How to adjust the Heatmap.2 color key Hi 
>Martin, One of the many(!) arguments to 
>heatmap.2 is breaks; see ?heatmap.2 for the 
>explanation. I also tried what Benjamin 
>suggested, but breaks seems to make a smoother 
>color scale. Here's how I use it: > 
>max(heatdata) [1] 9.167324 > min(heatdata) [1] 
>-6.469931 > pairs.breaks <- c(seq(-7, 0, 
>length.out=50),seq(0, 9.2, length.out=50)) > 
>mycol <- 
>colorpanel(n=99,low="green",mid="black",high="red")  
> > heatmap.2(heatdata, breaks=pairs.breaks, 
>col=mycol) Cheers, Jenny At 06:33 AM 7/9/2008, 
>Benjamin Otto wrote: >Hi Martin, I would define 
>my own color sequence. >For example if your 
>maximum logratio in your >table is 5 and the 
>minimum is -8 then you will >have to decide how 
>much color steps you like. >Let me assume you 
>use RColorBrewer for choosing >a color palette. 
>You can check the range of your >data with 
>range(#whatyoutableiscalled#). Then >you could 
>do: > mycol 
><- >c(brewer.pal(8,"Greens"),"black",brewer.pal(5 
>,"Reds")[5:1])  > > heatmap.2(mytable, 
>col=mycol) Regards, >Benjamin 
>-----Ursprüngliche Nachricht----- 
>Von: >bioconductor-bounces at stat.math.ethz.ch >[ma 
>ilto:bioconductor-bounces at stat.math.ethz.ch] >Im 
>Auftrag von Martin Bonke Gesendet: 
>Wednesday, >July 09, 2008 12:21 PM 
>An: >bioconductor at stat.math.ethz.ch Betreff: 
>[BioC] >How to adjust the Heatmap.2 color key 
>Dear all, >I'm a postdoc at the University of 
>Helsinki and >currently I'm in the middle of the 
>analyses of a >huge data set of microarray data. 
>A couple of >months ago I made the jump from 
>Genespring to >using R and although the learning 
>curve has been >somewhat steep, I'm quite happy 
>that I have done >so. Right now I'm making 
>heatmaps with the gene >lists that I've 
>generated using heatmap.2. In >general I'm quite 
>happy with the results, but in >several of them 
>I'm having some trouble with the >color coding 
>of the heatmap. My data has been >normalized 
>towards control experiments, to get a >factor of 
>up or down regulation (experiment >values are 
>divided by control values) and in >general I see 
>that genes are somewhat stronger >down regulated 
>compared to upregulated. To give >an example, 
>the strongest downregulated gene >could be at -8 
>fold, while the strongest >upregulated could be 
>at +5 fold. So the >distributon is then from -8 
>to +5, which puts >the middle at -1.5 in the 
>color key that >heatmap.2 automatically assigns. 
>As a result, >those genes that are not really 
>affected by my >experiments (and thus have 0 
>fold difference >towards the control experiment) 
>fall in a >slightly green zone in the color key 
>that >heatmap.2 assigns. This makes 
>visual >identification of interesting gene 
>clusters a >lot more difficult. So my question 
>to you all is >whether there is a way to tell 
>heatmap.2 which >colors should be assigned to a 
>certain level of >expression? I've thought about 
>checking each >matrix for the strongest up and 
>down regulated >values and then forcing the data 
>to max out on >whichever of the two is lowest, 
>but that will be >a lot of work, and it'll mean 
>that I have to >duplicate all data in order to 
>conserve the >original values as well. So if 
>there is a better >way, I'll gladly hear it. My 
>thanks in advance. >Best, Martin 
>Bonke         [[alternative HTML >version 
>deleted]] >______________________________________ 
>_________ >Bioconductor mailing 
>list >Bioconductor at stat.math.ethz.ch >https://sta 
>t.ethz.ch/mailman/listinfo/bioconductor >Search 
>the 
>archives: >http://news.gmane.org/gmane.science.bi 
>ology.informatics.conductor >-- Pflichtangaben 
>gemäß Gesetz über >elektronische 
>Handelsregister und >Genossenschaftsregister 
>sowie das >Unternehmensregister 
>(EHUG): >Universitätsklinikum 
>Hamburg-Eppendorf >Körperschaft des 
>öffentlichen Rechts >Gerichtsstand: Hamburg 
>Vorstandsmitglieder: >Prof. Dr. Jörg F. 
>Debatin (Vorsitzender) Dr. >Alexander Kirstein 
>Ricarda Klein Prof. Dr. Dr. >Uwe 
>Koch-Gromus >____________________________________ 
>___________ >Bioconductor mailing 
>list >Bioconductor at stat.math.ethz.ch >https://sta 
>t.ethz.ch/mailman/listinfo/bioconductor >Search 
>the 
>archives: >http://news.gmane.org/gmane.science.bi 
>ology.informatics.conductor Jenny Drnevich, 
>Ph.D. Functional Genomics Bioinformatics 
>Specialist W.M. Keck Center for Comparative and 
>Functional Genomics Roy J. Carver Biotechnology 
>Center University of Illinois, Urbana-Champaign 
>330 ERML 1201 W. Gregory Dr. Urbana, IL 61801 
>USA ph: 217-244-7355 fax: 217-265-5066 e-mail: 
>drnevich at illinois.edu -- Pflichtangaben gemäß 
>Gesetz über elektronische Handelsregister und 
>Genossenschaftsregister sowie das 
>Unternehmensregister (EHUG): 
>Universitätsklinikum Hamburg-Eppendorf 
>Körperschaft des öffentlichen Rechts 
>Gerichtsstand: Hamburg Vorstandsmitglieder: 
>Prof. Dr. Jörg F. Debatin (Vorsitzender) Dr. 
>Alexander Kirstein Ricarda Klein Prof. Dr. Dr. Uwe Koch-Gromus



More information about the Bioconductor mailing list