A heatmap is a statistical graphic that uses color to show the size of values in a table or matrix. Each cell represents one number, and the color of the cell tells you whether that number is low, middle, or high. Heatmaps matter because they help people see patterns that are hard to notice in rows of numbers.
They are widely used for correlations, survey results, temperatures, gene expression, website clicks, and many other data sets.
To read a heatmap, match each cell color to the color scale or legend. In a correlation heatmap, values often range from -1 to 1, where colors can show negative, near-zero, and positive relationships. In an intensity heatmap, larger counts or measurements may be shown with warmer or darker colors.
Choosing the right color scale is important because a poor scale can hide patterns or exaggerate differences.
Key Facts
- A heatmap encodes a numeric value by cell color in a grid of rows and columns.
- A color legend maps colors to numbers, such as blue = low, yellow = middle, red = high.
- For a correlation heatmap, the correlation coefficient satisfies -1 ≤ r ≤ 1.
- A positive correlation means two variables tend to increase together, while a negative correlation means one tends to increase as the other decreases.
- For a data matrix X, each heatmap cell can represent x_ij, the value in row i and column j.
- Use a sequential color scale for ordered values and a diverging color scale for values centered around a meaningful midpoint, such as 0.
Vocabulary
- Heatmap
- A graph that displays values in a matrix by coloring each cell according to its numerical size.
- Color scale
- A rule that connects numerical values to specific colors in a visualization.
- Correlation matrix
- A square table showing the correlation coefficient for every pair of variables in a data set.
- Intensity
- The magnitude or strength of a value, often shown by a darker, brighter, or warmer color.
- Diverging scale
- A color scale that uses two different color directions from a central value such as zero.
Common Mistakes to Avoid
- Ignoring the legend, which is wrong because the same color can mean different numbers in different heatmaps.
- Treating color differences as exact numerical differences, which is wrong because colors usually show approximate value ranges unless exact labels are provided.
- Using a rainbow color scale without a clear reason, which is wrong because uneven color changes can make patterns look stronger or weaker than they really are.
- Assuming correlation means causation, which is wrong because a strong color in a correlation heatmap shows association, not proof that one variable causes another.
Practice Questions
- 1 A heatmap legend maps 0 to dark blue, 50 to pale yellow, and 100 to red. If a cell has value 75, should its color be closer to pale yellow or red, and why?
- 2 In a correlation heatmap, the correlation between hours studied and test score is r = 0.82, while the correlation between hours studied and hours of sleep is r = -0.30. Which relationship is stronger in magnitude, and what does each sign mean?
- 3 A heatmap of classroom quiz scores uses red for high values and blue for low values. Several students have red cells on algebra questions but blue cells on geometry questions. What pattern does this suggest, and what should the teacher be careful not to conclude from the colors alone?