Get Started →
RelationshipComparison CategoricalNumerical

Heatmap

ggplot2: geom_tile() · Package: ggplot2 · Variables: 2 categorical + 1 numerical

WHAT IS A HEATMAP?

A heatmap displays values in a matrix grid where each cell is colored according to its value. It reveals patterns across two dimensions simultaneously — like which day of the week and time of day sees the most website traffic, or which variables in a dataset are most correlated. Heatmaps are particularly powerful for correlation matrices, user activity patterns, and any data that can be arranged in a rows-by-columns format. Use a diverging color scale (e.g., blue-white-red) for data with a meaningful center point. In ggplot2, use geom_tile() with scale_fill_gradient2().

BEST FOR

  • · Correlation matrices
  • · Two-dimensional patterns
  • · Time-of-day/day-of-week patterns
  • · Large numeric tables

AVOID WHEN

  • · Precise values needed
  • · Few data points
  • · Color-blind accessibility concerns

R + GGPLOT2 CODE EXAMPLE

ggplot2
cor_mat <- reshape2::melt(cor(mtcars[, 1:7]))
ggplot(cor_mat, aes(x = Var1, y = Var2, fill = value)) +
  geom_tile() +
  scale_fill_gradient2(low = "blue", mid = "white", high = "#ff6a00") +
  labs(title = "Correlation Matrix")

Run this code now

Paste the code above into RChat and see the heatmap rendered instantly in your browser.

Try RChat Free →

SIMILAR CHART TYPES

ALTERNATIVES FOR YOUR DATA TYPE