Question: heatmap.2 row clustering does not look right
gravatar for moxu
2.8 years ago by
moxu460 wrote:

Heatmap Example

Image is at

I am using R heatmap.2.

Take a look at the above heatmap generated by heatmap.2. There are 5 big clusters of rows: 1 yellow/red, 2 red/yellow, 3 yellow/red, 4 red/yellow, 5 yellow/red.

Shouldn't the yellow/red clusters cluster together, and red/yellow ones cluster together, and then form the biggest cluster?

The R code is as follows:

heatmap.2(data.matrix(heatmapEntries), main="xxx", dendrogram="row", Rowv = TRUE, Colv=FALSE, margins=c(11.3333333333333,5), scale="row", trace = "none", cexRow=1, lhei=c(1,10), lwid=c(1,3));

Thanks in advance!

rna-seq next-gen R software error • 2.5k views
ADD COMMENTlink modified 2.8 years ago by Kevin Blighe65k • written 2.8 years ago by moxu460
gravatar for Kevin Blighe
2.8 years ago by
Kevin Blighe65k
Kevin Blighe65k wrote:

Not necessarily, but you can modify the ordering of the heatmap with the reorderfun parameter to heatmap.2. For example, try:

heatmap.2(..., reorderfun=function(d,w) reorder(d, w, agglo.FUN=mean), ...)

You can choose any mathematical parameter here, including min, max, var, sd, etc.

You can also modify the scaling to see how that modifies the heatmap ordering. For example, to scale to Z-scores (by gene), use:

heatZ <- t(scale(t(heatmapEntries)))

  scale = 'none',
  reorderfun = function(d,w) reorder(d, w, agglo.FUN=mean),

For other suggestions, see my answer here: A: How to cluster the upregulated and downregulated genes in heatmap?

ADD COMMENTlink modified 4 months ago • written 2.8 years ago by Kevin Blighe65k

Scaling is the answer! Thanks much!

ADD REPLYlink written 2.8 years ago by moxu460

Okay, but, as per the other thread, scaling is usually combined with a 'breaks' parameter:

heatZ <- t(scale(t(heatmapEntries)))
myBreaks <- seq(-3, 3, length.out=101)
heatmap.2(data.matrix(heatZ), ..., breaks=myBreaks, scale="none", reorderfun=function(d,w) reorder(d, w, agglo.FUN=mean), ...)

Also important to realise that the heatmap / hierarchical clustering is just for the purposes of visualisation. The genes that you supplied to your heatmap would have presumably been derived from expression data on a different scale (if RNA-seq, most like negative binomial).

ADD REPLYlink written 2.8 years ago by Kevin Blighe65k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1479 users visited in the last hour