This is a test version of Biostars. For the public version, visit https://www.biostars.org.
heatmap.2 row clustering does not look right

Heatmap Example

Image is at https://imgur.com/CDzSiLU

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 software error next-gen r

1 answer

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)))

heatmap.2(data.matrix(heatZ),
  ...,
  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?

Scaling is the answer! Thanks much!

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).

Log in to answer this question.