Compound Figures

Claus O. Wilke

2025-02-23

Compound figures


Two common scenarios:

1. The same type of plot is replicated many times (small multiples)

2. Several disparate plots are combined into one display

Small multiples (facets)

Small multiples (facets)

Avoid bars or other elements that are floating in space

Small multiples (facets)

Small multiples work even for massive amounts of data

y-axis ranges should be consistent among panels

y-axis ranges should be consistent among panels

Combining disparate figures into one display


Don’t use overly large or otherwise prominent labels


Note: Also don’t use serif fonts (such as Times) for labels

Use a consistent color language among sub-plots

Use a consistent color language among sub-plots

Pay attention to sub-plot alignment

Pay attention to sub-plot alignment

Combine plots of different types

This helps your readers to distinguish different parts of the analysis

Combine plots of different types

This helps your readers to distinguish different parts of the analysis

Distinguish infographics from figures in article/book

Distinguish infographics from figures in article/book


There are two distinct use cases:

Infographic: Standalone, has title/subtitle/caption

Figure in article/book: Caption contains title, not part of figure

Figure 1. Corruption and human development. The most developed countries experience the least corruption. Inspired by a posting in The Economist online (2011). Data sources: Transparency International & UN Human Development Report.

Example of figure in article or book

Making compound plots in R

The patchwork package

library(patchwork)

# make first plot
p1 <- ggplot(mtcars) + 
  geom_point(aes(mpg, disp))

p1

 

The patchwork package

library(patchwork)

# make first plot
p1 <- ggplot(mtcars) + 
  geom_point(aes(mpg, disp))

# make second plot
p2 <- ggplot(mtcars) + 
  aes(gear, disp, group = gear) +
  geom_boxplot()

p2

 

The patchwork package

library(patchwork)

# make first plot
p1 <- ggplot(mtcars) + 
  geom_point(aes(mpg, disp))

# make second plot
p2 <- ggplot(mtcars) + 
  aes(gear, disp, group = gear) +
  geom_boxplot()

# place plots side-by-side
p1 | p2

 

The patchwork package

library(patchwork)

# make first plot
p1 <- ggplot(mtcars) + 
  geom_point(aes(mpg, disp))

# make second plot
p2 <- ggplot(mtcars) + 
  aes(gear, disp, group = gear) +
  geom_boxplot()

# place plots on top of one-another
p1 / p2

 

The patchwork package

# add a few more plots
p3 <- ggplot(mtcars) + 
  geom_smooth(aes(disp, qsec))

p4 <- ggplot(mtcars) + 
  geom_bar(aes(carb))

# make complex arrangement
(p1 | p2 | p3) / p4

 

Plot annotations and themes

(p1 | p2 | p3) / p4 +
   plot_annotation(
     tag_levels = "A"
   )

 

Automatic labeling of plots

Plot annotations and themes

(p1 | p2 | p3) / p4 +
   plot_annotation(
     tag_levels = "a"
   )

 

Automatic labeling of plots

Plot annotations and themes

(p1 | p2 | p3) / p4 +
  plot_annotation(
   tag_levels = "a"
  ) &
  theme_minimal_grid()

 

Applying one theme to all plots

Plot annotations and themes

(p1 | p2 | p3) / p4 +
  plot_annotation(
   tag_levels = "a",
   title = "A plot about mtcars",
   subtitle = "With subtitle...",
   caption = "...and caption"
  ) &
  theme_minimal_grid()

 

Titles and captions

Further reading