Get access to all lessons in this course.
- Welcome to Fundamentals of R
- Update Everything
- Start a New Project
-
Data Wrangling and Analysis
- The Tidyverse
- Pipes
- select()
- mutate()
- filter()
- summarize()
- group_by() and summarize()
- arrange()
- Create a New Data Frame
- Bring it All Together (Data Wrangling)
-
Data Visualization
- The Grammar of Graphics
- Scatterplots
- Histograms
- Bar Charts
- Setting color and fill Aesthetic Properties
- Setting color and fill Scales
- Setting x and y Scales
- Adding Text to Plots
- Plot Labels
- Themes
- Facets
- Save Plots
- Bring it All Together (Data Visualization)
-
Quarto
- Quarto Overview
- YAML
- Text
- Code Chunks
- Tips for Working with Quarto
- Bring It All Together (Quarto)
-
Wrapping Up
- An Important Workflow Tip
Fundamentals of R
scales
This lesson is locked
This lesson is called scales, part of the Fundamentals of R course. This lesson is called scales, part of the Fundamentals of R 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
Complete the scales sections of the data-visualization-exercises.Rmd file.
Learn More
scales Resources
Want to see all the built-in colors you can use? Here's a cheatsheet.
There is information on the tidyverse website about the various scales (scale_color_brewer, scale_color_viridirs_d, scale_y_continuous, etc.).
Chapter 8 of Data Visualization: A Practical Introduction
There are a lot of other packages that give you color/fill palettes you can work with. See especially the paleteer package, which is a meta palette package, give you access to palettes from many other packages.
You need to be signed-in to comment on this post. Login.
David Keyes Founder
April 5, 2021
Yup! Check out the
seq()
function. For example, this:breaks = seq(from = 0, to = 8, by = 1))``` Does the same thing as: ```scale_y_continuous(limits = c(0, 8), breaks = c(0, 1, 2, 3, 4, 5, 6, 7, 8))```
Jeff Shandling
April 12, 2021
Hi David-
I'm a bit confused on where to find the distinct colors for each palette. For example, where did you find "Dark2"? Thanks Jeff
Lina Khan
October 6, 2021
For the change of colors (or fill) using scale_color_brewer, I typed palette.pals() to see the options available. It shows the option used in the solutions ("Dark2") as "Dark 2" with a space inside, which I when I ran didn't work. But Dark2 worked. I also tried "Okabe-Ito" as shown in the palette.pals() list, but that didn't work either. Anyway, why would the options show with the spacing (or whatever else?) not correct? Also, when would we need to worry about adding 'd' (like scale_color_veridis_d, as shown in the lesson), vs not? Thanks!
Juan Clavijo
October 18, 2021
Hi! I'm typing this code in to change the color of the bar graph but the color is not changing from the standard colors. However, when I copy and paste your code from the solutions (which looks the same at least to me) it does work. Why might that happen?
ggplot(data = sleep_by_gender, mapping = aes(x = gender, y = avg_sleep, fill = gender)) + geom_col() + scale_color_brewer(palette = "Dark2")
Ellen Wilson
January 11, 2023
The pre-set palettes are very cool! I'm wondering, though, how to use an organization's brand colors? How can that be set up? The ideal would be if there was a way to get sequential, qualitative, and diverging palette options based on brand colors...