liveBook · Manning

Geom_tile() function

As explained in Statistics Slam Dunk

The ggplot2 geom_tile() function draws rectangular tiles whose position and appearance encode mapped data values.

geom_tile() draws the rectangular cells of a ggplot2 heat map. Map two variables to x and y, then map a value such as a correlation coefficient to fill. section 2.5.4

For a correlation matrix, reshape the computed coefficients into Var1, Var2, and value columns. Each row then supplies one tile and its color. section 2.5.4

Correlation heat map

p4 <- ggplot(data = draft_cor, aes(x = Var1, y = Var2, fill = value)) + geom_tile() + scale_fill_gradient2(midpoint = 0.5, mid = "grey84", limits = c(-1, 1)) + geom_text(aes(label = round(value, 2)), color = "black", fontface = "bold", size = 5) The resulting matrix uses color gradients for positive and negative associations and labels each tile with its rounded coefficient.

How Statistics Slam Dunk covers it

How deep it goes
Explains tile placement and demonstrates mapped fill values, but defers the underlying rendering internals.
Examples
Uses a draft-data correlation matrix with colored tiles and rounded coefficient labels.
What it assumes
Assumes familiarity with ggplot2 aesthetics and a data frame containing separate x, y, and value columns.
What you can do after
Apply it via ggplot2 to construct annotated heat maps from long-format matrix data.
How it connects
Connects geom_tile() with ggplot(), heat maps, correlation matrices, fill scales, and text annotations.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.