remixed from Claus O. Wilke’s SDS375 course
Two common scenarios:
Two common scenarios:
Two common scenarios:
The same type of plot is replicated many times (small multiples)
Several disparate plots are combined into one display
Avoid bars or other elements that are floating in space
This helps your readers to distinguish different parts of the analysis
This helps your readers to distinguish different parts of the analysis
This helps your readers to distinguish different parts of the analysis
There are two distinct use cases:
There are two distinct use cases:
Infographic: Standalone, has title/subtitle/caption
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
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
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
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
# 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
Automatic labeling of plots
Automatic labeling of plots
Applying one theme to all plots
(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
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.