[BioC] heatmap 'contrast': suggestions for a zlim adjustment in heatmap.2

E. McClellan e.mcclellan at erasmusmc.nl
Mon Aug 23 13:27:55 CEST 2010


Karl,

You say "specifying breaks interferes with the scale argument in heatmap.2"
but 
I get the exact same image from your heatmap.2 plot as when I plot an image
of 
your scaled matrix "stdizedmat":

a <- heatmap.2(toy.mat,
     Rowv=T, Colv=T,
     distfun=dist.pear,
     hclustfun=hclust.ave,
     scale= "row",
     col=greenred(256),
     breaks = c(seq(-2, 2, length.out = 257)),
     trace="none",
     density.info="none",
     main="heatmap.2 clustered"
   ) ##will produce heatmap image

row.order<-a$rowInd
col.order<-a$colInd

windows()
image(t(stdizedmat[row.order,col.order]),zlim=c(-clipper,clipper), 
col=greenred(256)) ##same image as before

...so I don't think it actually does mess up the scaling in this case.

Elizabeth


-----Original Message-----
From: Karl Brand [mailto:k.brand at erasmusmc.nl] 
Sent: Friday, August 20, 2010 5:30 PM
To: Kevin Coombes
Cc: bioconductor at stat.math.ethz.ch; Elizabeth McClellan
Subject: Re: [BioC] heatmap 'contrast': suggestions for a zlim adjustment in
heatmap.2

Thank you Kevin,

I took a punt on your suggestion which is very helpful given that i need 
more control over the details of my plots. But that also means i will 
need more understanding about what i'm doing and how to do it. Which i lack.

I failed to duplicate the clustering i achieved within heatmap.2 when 
attempting to cluster 'manually'. The plots (run examples below) differ 
in row ordering. So far i cant work out how to eliminate this difference.

Any help clarifying whats needed to manually duplicate the row ordering 
greatly appreciated,

Karl


##run
toy.mat <- matrix(rnorm(1000), nrow=100, ncol=10)
#cluster manually then just plot with heatmap.2
   rowclust <- hclust(as.dist(1-cor(t(toy.mat))), method="average")
   colclust <- hclust(as.dist(1-cor(toy.mat)), method="average")
   stdizedmat <- t(scale(t(toy.mat)))
   clipper <- 2
   stdizedmat[stdizedmat < -clipper]<- -clipper
   stdizedmat[stdizedmat > clipper] <- clipper
windows()
plot.new()
   heatmap.2(stdizedmat,
     Rowv=as.dendrogram(rowclust),
     Colv=as.dendrogram(colclust),
     scale="none", zlim=c(-clipper, clipper),
     col=greenred(256),
     trace="none",
     density.info="none",
     main="manually clustered"
   )

#using heatmap.2 to cluster AND plot
dist.pear <- function(x) as.dist(1-cor(t(x)))
hclust.ave <- function(x) hclust(x, method="average")
windows()
plot.new()
   heatmap.2(toy.mat,
     Rowv=T, Colv=T,
     distfun=dist.pear,
     hclustfun=hclust.ave,
     scale= "row",
     col=greenred(256),
     breaks = c(seq(-2, 2, length.out = 257)),
     trace="none",
     density.info="none",
     main="heatmap.2 clustered"
   )
##end

On 8/19/2010 11:13 PM, Kevin Coombes wrote:
> I've had the best results by treating heatmap as purely a display
> function, and breaking out all of the processing in previous steps. To
> make that more explicit, you can do something like
>
> rowclust <- hclust(mydDist(mat, "myMetric"), "myLinkage")
> colclust <- hclust(myDist(mat, "anotherMetric"), "anotherLinkage")
> stdizedmat <- t(scale(t(mat)))
> clipper <- 3
> stdizedmat[stdizedmat < -clipper]<- -clipper
> stdidezmat[stdizedmat > clipper] <- clipper
>
> heatmap(stdizedmat,
> Rowv=as.dendrogram(rowclust),
> Colv=as.dendrogram(colclust),
> scale='none', zlim=c(-clipper, clipper))
>
> Karl Brand wrote:
>> Esteemed BioC Users,
>>
>> In pursuit of a simple method to adjust the "contrast" of a heatmap i
>> attempted to use the image() argument "zlim" in heatmap.2, both
>> directly and using add.expr. These attempts failed (shown below on my
>> example heatmap.2).
>>
>> heatplot() from library(made4) includes just such a convenient zlim=
>> argument, but for now i'd trying to use heatmap.2 for all my heatmap
>> needs. For the record, i can achieve what a zlim adjustment using the
>> breaks argument to specify the effective range of zlim, but specifying
>> breaks interferes with the scale argument in heatmap.2. So no good.
>>
>> So any suggestions for a zlim adjustment in heatmap.2 are greatly
>> appreciated, cheers,
>>
>> Karl
>>
>>
>>
>> #example
>> toy.mat <- matrix(rnorm(1000), nrow=100, ncol=10)
>> library(gplots)
>> windows()
>> plot.new()
>> heatmap.2(toy.mat,
>> Rowv=T, Colv=T,
>> dendrogram="column",
>> scale= "row",
>> col=c(greenred(256)),
>> # breaks = c(seq(-10, 10, length.out = 257)),#interferes with 'scale'
>> trace="none",
>> density.info="none",
>> zlim=c(-10, 10) #no error, but no effect
>> # add.expr = (zlim=c(-10, 10)) #no error, but no effect
>> # add.expr = "zlim", zlim=c(-10, 10) #no error, but no effect
>> # add.expr = zlim, zlim=c(-10, 10) #produces error
>> )
>> #end
>>

-- 
Karl Brand <k.brand at erasmusmc.nl>
Department of Genetics
Erasmus MC
Dr Molewaterplein 50
3015 GE Rotterdam
P +31 (0)10 704 3409 | F +31 (0)10 704 4743 | M +31 (0)642 777 268



More information about the Bioconductor mailing list