Get access to all lessons in this course.
-
RMarkdown
- Why Use RMarkdown?
- RMarkdown Overview
- YAML
- Text
- Code Chunks
- Wrapping Up
-
Data Wrangling and Analysis
- Getting Started
- The Tidyverse
- select
- mutate
- filter
- summarize
- group_by
- count
- arrange
- Create a New Data Frame
- Crosstabs
- Wrapping Up
-
Data Visualization
- An Important Workflow Tip
- The Grammar of Graphics
- Scatterplots
- Histograms
- Bar Charts
- color and fill
- scales
- Text and Labels
- Plot Labels
- Themes
- Facets
- Save Plots
- Wrapping Up
-
Wrapping Up
- You Did It!
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.
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
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 11, 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
David Keyes
April 12, 2021
If you run the help for the scale_fill_brewer() you'll see the various options. To see what they look like, this page has a visual display.
Jeff Shandling
April 12, 2021
Thanks for the help
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!
David Keyes
October 6, 2021
Good questions!
On the palettes question, the available palettes for the
scale_fill_brewer()
function can be found in the help file for that function.I've never used the
palette.pals()
function so I'm not entirely sure how you'd use what's returned there.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")
David Keyes
October 18, 2021
The reason why you're having trouble is that you're using the fill aesthetic property, but
scale_color_brewer()
. Tryscale_fill_brewer()
instead and it should work!Tatiana Bustos
July 28, 2022
Ah! I was having this error too. Changing to scale_fill makes sense.
Ellen Wilson
January 10, 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...
David Keyes
January 10, 2023
Check out this blog post on how we do just this in our consulting work!
Ellen Wilson
January 20, 2023
Thanks! That is great, but I admit that it looks pretty overwhelming to me, as a novice coder. I'm still debating about Excel vs. R, and this is one thing that Excel does so easily, it is discouraging to see it so complicated in R!
David Keyes
January 20, 2023
I empathize with you: this is something that is quite a bit harder in R than in Excel. However, I do think that if you do it once, it becomes easier (because you then can easily reuse your code).