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
Grids, borders, lines, and axes examples and exercises
This lesson is locked
This lesson is called Grids, borders, lines, and axes examples and exercises, part of the The Glamour of Graphics course. This lesson is called Grids, borders, lines, and axes 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
Start with the code below. Then, apply the principles you have learned about for axes, grids, borders, etc to a plot you have made. The code below also has a starting plot for you if you prefer to use that.
##Your turn
library(tidyverse)
#plastic pollution dataset
plastics <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-01-26/plastics.csv')
#Take a plot you made with the plastic pollution dataset (it doesn't need to be a scatter plot)
#And apply the principles you learned about for axes, grids, borders, etc.
#If you don't want to use your own plot, you can use this one...
#wrangle data
data <- 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))
#example starting plot
ggplot(data) +
geom_col(aes(x = total, y = reorder(parent_company, total)), fill = "orchid4")
#now apply your styling of the grids, axes, borders, and backgrounds
You need to be signed-in to comment on this post. Login.
Blayne Beacham
February 20, 2023
Hey Will,
I really like the "g" and "mm" trick for the labelling of the x and y axes but I'm wondering if it is possible to just label the first (or last) instance of this and let the others be just the numbers. Is this possible?
David Keyes
February 21, 2023
You can't do within the
scale_x_continuous()
function directly like Will does, but you could create a vector with all of the labels you want and then pass that vector to thescale_x_continuous()
function using thelabels
argument. Does that make sense?