Heatmap Explained: How to Make, Read and Report It
A heatmap turns a table of numbers into a grid of colours so that patterns jump out: which variables move together, which samples cluster, where the extreme values sit. It is a standard display for correlation matrices and for high-dimensional data such as gene-expression tables. This guide explains how a heatmap is built, how to choose the colour scale and transformations, how to read one critically, and how to report it, with a worked correlation example.
What is a heatmap?
A heatmap encodes each cell of a numeric matrix as a colour. Rows and columns usually represent variables, samples or categories. A clustered heatmap also reorders rows and columns by similarity, typically with hierarchical clustering, and draws dendrograms alongside; the idea became widely used for genome-wide expression data (Eisen et al., 1998), and its history is reviewed by Wilkinson and Friendly (2009).
When should you use a heatmap?
- Displaying a correlation matrix among many variables.
- Showing expression, abundance or response values across many features and samples.
- Visualising a confusion matrix, a cross-tabulation or a time-by-category grid.
- Spotting blocks, gradients and outliers in a matrix before formal modelling.
Heatmap versus other charts. Colour is a weaker channel for reading exact values than position or length (Cleveland & McGill, 1984). If the reader needs the numbers, print them in the cells or provide a table. For a handful of values, a bar plot is clearer.
The mathematical foundation
For a correlation heatmap, each cell holds the Pearson correlation between two variables:
rxy = Σ(xi − x̄)(yi − ȳ) / √[Σ(xi − x̄)² · Σ(yi − ȳ)²]
The matrix is symmetric with ones on the diagonal, so only one triangle carries information. The square of a correlation, r², is the proportion of variance shared by the two variables. The significance threshold for a correlation depends on the sample size: a correlation is significantly different from zero at the 5% level (two-tailed) when:
|r| > tcrit / √(tcrit² + n − 2)
When data in different rows or columns are on different scales, a heatmap is often drawn on standardised values (z-scores) so that colour reflects position relative to each variable's own mean:
zij = (xij − x̄j) / sj
Clustered heatmaps additionally depend on a distance measure (for example Euclidean or 1 − r) and a linkage method (for example average or complete), and both choices can change the ordering.
Assumptions and data requirements
- Rectangular numeric matrix. Rows and columns with consistent meaning; missing cells need explicit handling.
- Comparable scale. Colour compares cells to each other, so cells should share a unit or be standardised.
- Appropriate colour scale. Use a diverging palette centred on a meaningful midpoint (zero for correlations and z-scores) and a sequential palette for non-negative magnitudes.
- Consistent colour limits. If two heatmaps will be compared, use the same colour limits for both.
- Adequate sample size for correlations. Correlations from small samples are volatile, and a matrix of many correlations produces many chance "hits"; consider adjusting for multiple comparisons.
- Accessible colours. Avoid red–green pairs and rainbow scales; check legibility in greyscale.
Original research example (illustrative)
Background. A researcher collects four measures from university students: weekly study hours, class attendance rate, nightly sleep hours and grade point average (GPA).
Objective and question. Which variables are most strongly related, and which relationships are negligible?
Data. n = 120 students. The correlations below are invented for teaching.
Step 1: Build the correlation matrix
| Study hours | Attendance | Sleep | GPA | |
|---|---|---|---|---|
| Study hours | 1.00 | .45 | .10 | .62 |
| Attendance | .45 | 1.00 | .15 | .51 |
| Sleep | .10 | .15 | 1.00 | .27 |
| GPA | .62 | .51 | .27 | 1.00 |
Step 2: Find the significance threshold
With n = 120, df = 118 and the two-tailed 5% critical t is about 1.98. The threshold is |r| > 1.98 / √(1.98² + 118) = 1.98 / √(3.92 + 118) = 1.98 / 11.04 ≈ .18. So r = .10 and r = .15 are not distinguishable from zero at the 5% level, while .27, .45, .51 and .62 are. Note that this threshold is for a single test; with six correlations in the matrix, a multiplicity adjustment (such as Bonferroni, which would require p < .05/6 ≈ .0083) is advisable. The smallest significant correlation here, .27, still passes that stricter threshold (its p is about .003).
Step 3: Translate to shared variance
The strongest relationship, study hours with GPA, has r = .62, so r² = .62² = .384: study hours share about 38% of their variance with GPA. For sleep and GPA, r² = .27² = .073, about 7%. For study hours and sleep, r² = .01, effectively nothing.
Step 4: Choose the colour scale and interpret
Because correlations run from −1 to +1, a diverging palette centred on zero, with limits fixed at −1 and +1, is appropriate. All cells here are positive, so the map would show only the warm half of the scale, with GPA row and column the "hottest" and the sleep cells the palest. Reading the pattern: study hours and attendance each relate strongly to GPA and moderately to each other, which suggests they may overlap in what they explain, so a regression with both would need to check collinearity. Sleep relates only weakly to the rest. Remember that correlations describe association, not cause, and that a pattern in colour should be backed by the printed values.
How to make a heatmap with the StatFAS Heatmap Maker
Open statfas.com/heatmap-maker.html.
- Prepare your data. A numeric matrix with row and column labels and a header row. For a correlation heatmap, either supply the raw variables or a ready correlation matrix.
- Load the data and select variables. Remove ID or text columns.
- Set options. Typical choices are colour palette, colour limits, scaling (none, row, column), clustering, cell annotations and title.
- Review the figure. Check the legend, the colour limits, label legibility and whether the printed values match the colours.
- Download. Export at a resolution suitable for publication.
statfas-heatmap-maker-interface.pngAlt text: "StatFAS heatmap maker interface before data entry."
Caption: The Heatmap Maker on StatFAS.com.
statfas-heatmap-example-data.png · Alt: "Four-variable student dataset loaded in the StatFAS heatmap maker."Screenshot 3:
statfas-heatmap-settings.png · Alt: "Colour palette and clustering settings in the StatFAS heatmap maker."Screenshot 4:
statfas-heatmap-result.png · Alt: "Finished correlation heatmap with annotated cells." Use only genuine captures of the tool.Reading a heatmap
- Legend first. Check the colour limits and midpoint. Mistake: assuming "red = bad" or that the scale starts at zero.
- Blocks and gradients. Contiguous blocks of similar colour indicate groups of variables or samples that behave alike.
- Symmetry. In a correlation heatmap, the upper and lower triangles are mirror images; hide one to reduce clutter.
- Cluster order. The row and column order in a clustered heatmap depends on the distance and linkage method. Mistake: reading adjacency as meaning without checking the dendrogram.
- Scaling. After row or column scaling, colours show relative position, not absolute magnitude.
- Numbers behind colours. Colour differences are hard to quantify; annotate cells with values when the matrix is small.
APA 7 reporting example (based on the illustrative data)
Figure 1 displays the Pearson correlations among study hours, attendance, sleep and GPA (n = 120). GPA correlated most strongly with study hours (r = .62, p < .001) and attendance (r = .51, p < .001), and more weakly with sleep (r = .27, p = .003). Colour intensity represents the correlation coefficient on a diverging scale from −1 to +1.
Essential elements: a numbered figure with a caption explaining the colour scale, the sample size, the correlation type and any multiplicity adjustment, and the exact coefficients in the text or an accompanying table. If the heatmap is clustered, state the distance and linkage method.
Common mistakes and troubleshooting
- Rainbow palettes. They create false boundaries and are hard to read for colour-blind viewers. Use perceptually ordered palettes.
- Sequential scale for signed data. It hides the sign; use a diverging scale centred on zero.
- Inconsistent colour limits between figures. Identical colours then mean different values.
- Unscaled variables on different units. One variable dominates the colour range.
- Reading the matrix as significance. Colour shows magnitude, not statistical significance.
- Ignoring multiple comparisons. A large matrix will contain chance correlations.
- Unreadable labels. Too many rows or columns crowd the labels; filter, cluster or enlarge.
- Treating cluster order as truth. Different methods can produce different orders.
Limitations and alternatives
A heatmap shows pattern, not mechanism, and its colour encoding limits precision. For pairwise detail, use scatterplots; to summarise correlated variables, consider PCA or exploratory factor analysis, which often start from the same correlation matrix. For the numbers behind the colours, use the correlation calculator and the descriptive statistics calculator. For ordered trends, a line graph may be clearer.
Frequently asked questions
What is a heatmap used for?
To display a matrix of values as colours so that patterns across rows and columns are easy to see, for example correlations or expression data.
Which colour scale should I use?
A diverging scale centred on zero for signed values; a sequential scale for non-negative magnitudes; avoid rainbow palettes.
Should I scale rows or columns before plotting?
Scale when variables have different units or ranges and you want to compare patterns. Do not scale values that already share a meaningful unit, such as correlations.
Does a dark cell mean a significant result?
No. Colour reflects magnitude. Significance depends on sample size and any multiplicity adjustment.
Conclusion
A good heatmap is built on a sensible choice of data transformation and colour scale, labelled clearly, and read together with the numbers behind it. When you are ready to draw one from your own data, the StatFAS Heatmap Maker provides a browser-based route, and the exported figure should be checked by you before publication.
References
- Cleveland, W. S., & McGill, R. (1984). Graphical perception: Theory, experimentation, and application to the development of graphical methods. Journal of the American Statistical Association, 79(387), 531–554.
- Eisen, M. B., Spellman, P. T., Brown, P. O., & Botstein, D. (1998). Cluster analysis and display of genome-wide expression patterns. Proceedings of the National Academy of Sciences, 95(25), 14863–14868.
- Wilkinson, L., & Friendly, M. (2009). The history of the cluster heat map. The American Statistician, 63(2), 179–184.