Tutorials

Heatmaps and clustering: scaling choices that change the picture

How colour scales, row and column scaling, distance and linkage change a heatmap, and how to read a dendrogram without overclaiming.

A heatmap displays a matrix of values as colours, and clustering arranges rows and columns so that similar patterns sit together. The picture can reveal structure, but the scaling and distance choices can also create structure that is not there.

What the colours mean

Each cell is a value, usually a gene expression measurement after some transformation. The colour scale maps value to colour. A diverging scale is common for log ratios, with one colour for low, one for high and a neutral colour in the middle.

Read the legend before interpreting the pattern. A scale that runs from −2 to 2 is not the same as one that runs from −10 to 10. A heatmap without a scale is a decoration.

Scaling: rows, columns or none

Scaling is the most consequential choice. Scaling each row (gene) to zero mean and unit variance emphasises the pattern across samples for that gene. Scaling each column (sample) emphasises the pattern across genes for that sample.

Row scaling is common for gene expression heatmaps because it makes genes with different absolute levels comparable. It also exaggerates small differences in low-variance genes. A gene that barely changes can look as dramatic as a gene with a large change.

Column scaling can reveal sample-level patterns but can hide gene-level differences. No scaling preserves the absolute values but lets highly expressed genes dominate the colour range.

State the scaling in the caption. If the heatmap is used to compare genes, row scaling is usually appropriate. If it is used to compare samples, column scaling may be more appropriate.

Distance and linkage

Clustering needs a distance measure and a linkage rule. Common distances are Euclidean and correlation. Common linkage rules are complete, average and Ward.

Euclidean distance is sensitive to the magnitude of the values. Correlation distance focuses on the shape of the profile and ignores the absolute level. Two genes with the same pattern but different amplitudes are close under correlation distance and farther under Euclidean distance.

Different linkage rules can produce different dendrograms. The clusters are a summary of the chosen distance and linkage, not a unique decomposition of the data. If the clusters matter, test whether they are stable under a reasonable change of method.

Reading a dendrogram

The dendrogram shows the order in which clusters are merged. The height of a merge indicates the distance between the clusters at that step. A tall merge suggests distinct groups; a short merge suggests a continuum.

The order of leaves is not unique. Rotating a branch does not change the clustering. Do not read the left-to-right order as a time series or a ranking.

Common heatmap mistakes

  • Using row scaling and calling a small change "dramatic".
  • Clustering samples and genes with the same distance without thinking.
  • Interpreting the dendrogram as a hypothesis test.
  • Using a colour scale that hides the distribution.
  • Showing only selected genes and implying they are representative.

Heatmaps and sample grouping

A common use is to check whether samples cluster by condition. If the treated and control samples separate cleanly, that is consistent with a treatment effect. If they separate by batch, the heatmap has revealed a problem.

Add a colour bar for the condition and for any batch variable. Without the annotation, the reader cannot tell whether the clustering matches the design.

Presenting a heatmap

Keep the number of rows manageable. A heatmap of thousands of genes is hard to read and often looks like noise. Select genes by a pre-specified rule, such as differential expression or a pathway, and say how they were selected.

Order the rows in a way that helps the reader, for example by cluster or by a known pathway. Label the samples clearly. Include the scale and the clustering method in the caption.

If the heatmap is decorative, say so. If it supports a claim, provide the underlying statistics.

A note on single-cell data

Single-cell heatmaps often show average expression per cluster. The average can hide heterogeneity within the cluster. A dot plot, which shows both the fraction of expressing cells and the mean expression, is often more informative.

For single-cell data, the choice of scaling and the handling of dropout matter even more than in bulk data. A heatmap of raw counts is dominated by highly expressed genes. A heatmap of scaled values can exaggerate noise.

Heatmaps for different questions

A heatmap of samples by genes can answer several different questions. If the question is "do the samples group by condition?", cluster the samples and annotate the condition. If the question is "which genes share a pattern?", cluster the genes. If the question is "what is the value in this specific cell?", use a table, not a colour.

Mixing the questions in one figure is common but can confuse the reader. A heatmap with both sample and gene clustering shows two structures at once. The caption should say which structure is the focus.

Reproducibility

Record the input matrix, the transformation, the scaling, the distance, the linkage and the software. A heatmap is easy to redraw but hard to reproduce if the choices are not documented.

If the figure was edited after clustering, for example by reordering rows by hand, say so. A hand-ordered heatmap can be a useful visual, but it is no longer a direct output of the clustering.

Keep the code or the analysis file. A screenshot of a heatmap is not a reproducible result.

Key points

  • Read the colour scale before the pattern.
  • Scaling changes the story; state it.
  • Distance and linkage are choices, not facts.
  • A dendrogram is not a hypothesis test.
  • Select genes by a rule, not by what looks good.

Common mistakes

  • Row-scaling and overinterpreting small changes.
  • Clustering samples without a condition annotation.
  • Using a heatmap of thousands of genes as a figure.
  • Treating cluster order as meaningful.
  • Hiding the selection rule for the genes shown.

When to ask for help

If the clustering does not match the design, if the heatmap changes with the scaling, or if you need a publication figure, ask for a review. You can order an analysis or read the PCA guide. The Scientific Data Visualisation course covers heatmaps and colour, and the RNA-seq workflow shows where clustering fits.

Sources and further reading

When to ask for help. If your data or design do not fit a tutorial, order an analysis and we will reply with a fixed price.

Written by the Solagene team for research and education. Found an error? Tell us and we will correct it.