Get access to all lessons in this course.
-
The shape of data
- Chart types
- How to choose a chart
- Visual metaphor
- Memorability vs. speed of comprehension
- Identifying your audience
- Data encoding process
-
Layout
- Grids, borders, lines
- Axes
- Grids, borders, lines, and axes examples and exercises
- Alignment
- White space
- Charts in larger layouts
- Alignment, white space, and layout of multiple plots examples and exercises
-
Typography
- What is typography and why does it matter?
- Typographic hierarchy
- Font styles
- Good fonts and where to find them
- Using custom fonts in R examples and exercises
- ggtext examples and exercises
- Pairing fonts
- Typography beyond charts
-
Color
- Color palettes
- Color examples and exercises
- Color models
- HCL color palettes in ggplot examples and exercises
- The color wheel
- Color and emotion
- The eyedropper tool and color inspiration
-
Special topics
- Legends
- Accessibility
- Combining ggplot with a vector editor
- Annotations
- Resizing plots for export
- Finding inspiration
The Glamour of Graphics
HCL color palettes in ggplot examples and exercises
This lesson is locked
This lesson is called HCL color palettes in ggplot examples and exercises, part of the The Glamour of Graphics course. This lesson is called HCL color palettes in ggplot examples and exercises, part of the The Glamour of Graphics 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
Copy the code below (also here) and follow the instructions.
library(tidyverse)
#if not installed, install the colorspace package
#install.packages("colorspace")
library(colorspace)
#Your turn
#This is some data for a line chart
air <-
airquality %>%
filter(Month == 5) %>%
select(Temp, Ozone, Wind, Day) %>%
pivot_longer(cols = 1:3)
#take this chart, and change the color of the lines
#using a qualitative HCL color palette
ggplot(air) +
geom_line(aes(x = Day, y = value, color = name)) +
theme_minimal()
#take this plot and adjust the colors so that
#the bubbles are on a sequential scale using an HCL palette
ggplot(mtcars) +
geom_point(aes(x = wt, y = hp, color = mpg), size = 4, alpha = 0.8) +
theme_minimal()
#generate some dummy data
x <- LETTERS[1:20]
y <- paste0("var", seq(1,20))
data <- expand.grid(X=x, Y=y)
data$Z <- runif(400, -5, 5)
#adjust this heatmap so that the colors
#are a diverging scale using an HCL palette
ggplot(data, aes(X, Y, fill= Z)) +
geom_tile()
Learn More
The documentation for the colorspace package is quite useful and shows you how to do all kinds of operations with the HCL colorspace.
For more fun color palettes, check out the paletteer package which is a meta-package that collects all other color palette R packages.
You need to be signed-in to comment on this post. Login.