Compound Figures

remixed from Claus O. Wilke’s SDS375 course

Compound figures

Two common scenarios:

Compound figures

Two common scenarios:

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

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

1. Small multiples (facets)

1. Small multiples (facets)

1. Small multiples (facets)

Avoid bars or other elements that are floating in space

1. 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

2. Combining disparate figures into one display

Don’t use overly large or otherwise prominent 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

Combine plots of different types

This helps your readers to distinguish different parts of the analysis

Distinguish infographics from figures in article/book


There are two distinct use cases:

Distinguish infographics from figures in article/book


There are two distinct use cases:


Infographic: Standalone, has title/subtitle/caption

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

Example of infographic

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

Exercise

Go to (https://elsherbini.github.io/durban-data-science-for-biology/materials/1-workshop1/7-custom-data-visualizations/#coding-exercise-7.3 and complete the Figure Design exercise.