Skip to content
R for the Rest of Us Logo

Grids, borders, lines, and axes examples and exercises

This lesson is locked

Get access to all lessons in this 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

Have any questions? Put them below and we will help you out!

You need to be signed-in to comment on this post. Login.

Blayne Beacham

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?

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 the scale_x_continuous() function using the labels argument. Does that make sense?