Skip to content
R for the Rest of Us Logo

Use Axis Text Wisely

This lesson is locked

Get access to all lessons in this course.

If the video is not playing correctly, you can watch it in a new window

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

Make your y axis labels show up as nicely formatted percents using the percent_format() function.

Learn More

Dana Siedel gave a nice talk at rstudio::conf 2020 about the scales package that is well worth a 20-minute watch!

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

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

Catherine Roller White

Catherine Roller White

May 11, 2021

Hi there. How can I change the font of my data labels to match the rest of the font? I'm using a font called "Sylfaen." It's showing up for my axis labels but I'm not sure where to specify that font for data labels. Thank you!

enrollment_by_race_ethnicity %>% 
  filter(race_ethnicity == "Hispanic or Latino") %>%
  ggplot(aes(x = year,
             y = percent,
             group = district)) +
  geom_line(color = "lightgray",
            alpha = 0.5) +
  geom_line(data = highlight_district,
            inherit.aes = TRUE,
            color = "blue") +
  geom_text(data = highlight_district,
            inherit.aes = TRUE,
            aes(label = percent_display),
            hjust = c(1, 0)) +
  scale_y_continuous(label = percent_format(),
                     limits =c(0,1)) +
  theme_ipsum(axis_title_size = 0,
              base_family = "Sylfaen",
              grid = "XY")