Hierarchical Facets: Advanced Layouts for Small Multiples
Many real-world datasets aren’t flat — they’re organized into nested groups such as regions within country, products within broader categories, or species within a genus or family. Hierarchical facets help you reflect this structure directly in your visualizations, so viewers can navigate complex groupings without getting lost.
In this lesson, you’ll learn how to build multi-level facet layouts, customize strip labels to keep them readable and informative, and use nested structures to clarify relationships between groups.
Before You Start 🧰
We’re using Rethink Sans and Domine again in this lesson to make these plots look their best. You should have the typefaces installed by now — but if not, please install them on your system to ensure everything renders correctly in the sandbox.
🪜 The Grid Upgrade
In the previous lesson, we used facet_wrap() and facet_grid() to split our data into neat, digestible multiples. While the ggplot2's defaults for the strips work well for exploration of numeric variables — let's say a group of scatterplots or time series — standard facets often struggle with hierarchy when comparing nested categories for two specific reasons:
- The "Ping-Pong" Effect — When category names are on the left but group headers (strips) are on the right or top, the reader has to constantly ping-pong their eyes across the chart to connect an item to its group.
- Flat Visual Weight — By default,
ggplot2gives strip and axis text a similar importance. Due to the missing clear visual distinction, the logical order of information is less clear.
As stressed in several lessons before:
Hierarchy is everything in the world of (data) communication.
Hierarchy is the secret sauce for "scannability" and visual pruning: it ensures readers can navigate your graphic and jump directly to the major group of interest before searching for a specific item.