Heatmap Explained: How to Make, Read and Report It

By Dr. Faheem Afzal Shah, Founder, StatFAS.com · Tool: Heatmap Maker

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?

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

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

Illustrative correlation matrix (n = 120)
Study hoursAttendanceSleepGPA
Study hours1.00.45.10.62
Attendance.451.00.15.51
Sleep.10.151.00.27
GPA.62.51.271.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.

  1. 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.
  2. Load the data and select variables. Remove ID or text columns.
  3. Set options. Typical choices are colour palette, colour limits, scaling (none, row, column), clustering, cell annotations and title.
  4. Review the figure. Check the legend, the colour limits, label legibility and whether the printed values match the colours.
  5. Download. Export at a resolution suitable for publication.
Screenshot 1 (to be supplied): statfas-heatmap-maker-interface.png
Alt text: "StatFAS heatmap maker interface before data entry."
Caption: The Heatmap Maker on StatFAS.com.
Screenshot 2: 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

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

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

Author attribution: Dr. Faheem Afzal Shah, Plant Functional Genomics and Regulatory Genomics Researcher; StatFAS.com Founder.