Get access to all lessons in this course.
-
The shape of data
- Chart types
- How to choose a chart
- Visual metaphor
- Memorability vs. speed of comprehension
- Identifying your audience
- Data encoding process
-
Layout
- Grids, borders, lines
- Axes
- Grids, borders, lines, and axes examples and exercises
- Alignment
- White space
- Charts in larger layouts
- Alignment, white space, and layout of multiple plots examples and exercises
-
Typography
- What is typography and why does it matter?
- Typographic hierarchy
- Font styles
- Good fonts and where to find them
- Using custom fonts in R examples and exercises
- ggtext examples and exercises
- Pairing fonts
- Typography beyond charts
-
Color
- Color palettes
- Color examples and exercises
- Color models
- HCL color palettes in ggplot examples and exercises
- The color wheel
- Color and emotion
- The eyedropper tool and color inspiration
-
Special topics
- Legends
- Accessibility
- Combining ggplot with a vector editor
- Annotations
- Resizing plots for export
- Finding inspiration
The Glamour of Graphics
Alignment, white space, and layout of multiple plots examples and exercises
This lesson is locked
This lesson is called Alignment, white space, and layout of multiple plots examples and exercises, part of the The Glamour of Graphics course. This lesson is called Alignment, white space, and layout of multiple plots examples and exercises, part of the The Glamour of Graphics course.
Transcript
Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.
Your Turn
You can either use your own charts or the charts provided in the code below (also available in this file).
library(tidyverse)
plastics <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-01-26/plastics.csv')
bar_chart <-
plastics %>%
group_by(parent_company) %>%
summarize(total = sum(grand_total, na.rm = TRUE)) %>%
arrange(desc(total)) %>%
slice(4:14) %>%
mutate(parent_company = ifelse(parent_company == "NULL", "Unknown", parent_company)) %>%
ggplot() +
geom_col(aes(x = total, y = reorder(parent_company, total)), fill = "orchid4") +
theme_light() +
labs(title = "Top brands") +
theme(axis.title = element_blank(), panel.border = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.major.y = element_blank(),
plot.title.position = "plot")
pie_chart <-
plastics %>%
group_by(year) %>%
summarize(total = sum(grand_total, na.rm = TRUE)) %>%
ggplot() +
geom_bar(aes(x = "", y = total, fill = as.character(year)), stat = "identity", width = 1) +
coord_polar("y", start = 0) +
theme_minimal() +
labs(title = "Plastic pollution by year", fill = "") +
theme(axis.title = element_blank(), panel.grid = element_blank(),
axis.text = element_blank())
bar_chart_2 <-
plastics %>%
select(hdpe:pvc) %>%
pivot_longer(cols = 1:7) %>%
group_by(name) %>%
summarize(total = sum(value, na.rm = TRUE)) %>%
ggplot() +
geom_col(aes(x = total, y = reorder(name, total)), fill = "goldenrod") +
theme_light() +
labs(title = "By plastic type") +
theme(axis.title = element_blank(), panel.border = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.major.y = element_blank(),
plot.title.position = "plot")
Create a patchwork with one chart in a lefthand column spanning two vertical rows, and two charts in a second column stacked on top of each other.
Take the patchwork you just created, and add a title, subtitle, and figure labels
Make the figure labels read “Fig. 1, Fig. 2, Fig. 3”
Use theme options to make the figure labels a little smaller
You need to be signed-in to comment on this post. Login.
Cedric Vidonne
January 11, 2023
FYI the link to the download the lesson slides is broken as well as the 2nd video that appears to be private.
David Keyes
January 11, 2023
Sorry about that! Just updated the lesson. FYI there are no slides and the second video was supposed to go in the solutions section (it's there now).
Deepak Varughese
January 29, 2023
Hi Wlll. Great session. Had a question How do I get rd of the 2e+05 etc on the x axis?
David Keyes
January 29, 2023
You can do this with
options(scipen = 999)
, which will remove scientific notation altogether. You can also look at thescales
package to customize your axes further (e.g. adding 1,000,000 instead of 1000000).