Skip to content
R for the Rest of Us Logo

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.

Heads up!

Definitely take a look at the solutions video for this lesson (once you've tried it yourself!). It goes through the exercise for this lesson, which is quite challenging, step by step and provides an overview of how you can think about creating a plot you see elsewhere with code that you write.

Your Turn

Complete the facets sections of the data-visualization-exercises.Rmd file. You'll be asked to recreate a visualization as part of this. Here is the image for your reference:

Learn More

Facets Resources

Chapter 11 of the R Graphics Cookbook covers facets. Kieran Healy discusses them in Chapter 4 of Data Visualization: A Practical Introduction, as does Claus Wilke in Chapter 21 of Fundamentals of Data Visualization.

I’ve also written an article about the value of small multiples. It includes some code for making them.

Note that, while I’ve only showed you facet_wrap, there is also a facet_grid function that you might want to explore as well. Both are discussed in the R Graph Gallery article on facets.

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

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

Erin Guthrie

Erin Guthrie

April 4, 2021

When I run the code (with some help from the solutions video), I get a message font family not found in Windows font database. The graphs and the labels are on top of each other. Is this something having to do with the theme?

David Keyes

David Keyes

April 5, 2021

Yes, unfortunately. Fonts are notoriously complicated in R. It's just telling you it can't find the custom font that's being used here. No need to worry about it for now. You'll learn how to use custom fonts in a Going Deeper lesson.

Andrew Paquin

Andrew Paquin

April 5, 2023

I tried accessing this lesson to fix the issue around overlapping labels on the x axis, but the link appears to be broken.

David Keyes

David Keyes

April 5, 2023

Try this link: https://rfortherestofus.com/courses/r-in-3-months-spring-2023/lessons/customize-your-fonts/

Abby Isaacson

Abby Isaacson

April 15, 2021

Do you know why my bar outlines might be blue, even when running your solution code? The fills are all correct. After I installed devtools I think this started happening in both my Rmarkdown files.

David Keyes

David Keyes

April 15, 2021

Hmm, that doesn't sound familiar at all. Can you try restarting RStudio and letting me know if it still happens?

Abby Isaacson

Abby Isaacson

April 15, 2021

When I restarted it went away, thanks :/

JULIO VERA DE LEON

JULIO VERA DE LEON

March 31, 2022

Hi! How do you change "female" and "male" to "Female" and "Male"? Thanks!

Charlie Hadley

Charlie Hadley

March 31, 2022

Hi Julio,

The str_to_title() function from {stringr} is a good choice for this, eg

nhanes %>% 
  mutate(gender = str_to_title(gender))

Cheers, Charlie

JULIO VERA DE LEON

JULIO VERA DE LEON

April 1, 2022

Thanks Charlie!

Mychal Davis

Mychal Davis

April 7, 2022

Hello,

I am not able to install any themes, when I try I get this error message "Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : there is no package called ‘cli’".

Originally the error message stated, "Error in loadNamespace(j = 3.1.0 is required." So I attempted to update the package, but an error occurred when I tired to update it. I uninstalled the package and tired to reinstall it, but when I attempted to reinstall the package I received an error message.

Charlie Hadley

Charlie Hadley

April 8, 2022

Hi Mychal,

Sometimes reinstalling packages in the same session can mess up. Could you try these instructions:

  • Open up a completely fresh RStudio
  • Run remove.packages("cli")
  • Restart RStudio by going to the menu bar and selecting Session > Restart R
  • Run install.packages("cli")
  • Restart RStudio again
  • Try and install themes again.

Please do let me know how this goes.

Thanks, Charlie

Mychal Davis

Mychal Davis

April 8, 2022

Hello,

I was able to successfully reinstall the "cli" package.

Thanks, Mychal

Amanda Krantz

Amanda Krantz

October 26, 2022

I am able to generate the same graph, except the font size of the ages labels on the x axis are bigger and do they are squished together. I am getting errors about the Windows fonts, but it is still generating the graph otherwise, so maybe I just need to fix those fonts per the last lesson?

David Keyes

David Keyes

October 28, 2022

This is probably an issue with hrbrthemes. If everything works when you remove that, I wouldn't worry about it at this point.

Melissa Mullins

Melissa Mullins

April 19, 2023

The facetting seems like it will be incredibly useful. I did have the same trouble as some people in the past with the overlapping font on the x-axis (whether I ran the code I wrote or the one from the solutions). I see there is a new video about this coming up so I look forward to learning more.