mpg |>
ggplot(aes(x = displ, y = hwy, color = drv)) +
geom_jitter() +
labs(x = "Displacement", y = "Highway fuel efficiency") +
scale_color_brewer(palette = "Accent") +
theme(legend.position = c(0.8, 0.8))
2023-04-07

Distinguish categories (qualitative)
Represent ordered numeric values (sequential)
Represent binary numeric values (diverging)
Highlight
red R (0-255): amount of red
green G (0-255): amount of green
blue B (0-255): amount of blue
| R | G | B | hexcode |
|---|---|---|---|
| 0 | 0 | 0 | #000000 |
| 255 | 0 | 0 | #FF0000 |
| 0 | 255 | 255 | #00FFFF |
| 128 | 128 | 128 | #808080 |
| 0 | 158 | 115 | #009E73 |
| 255 | 255 | 255 | #FFFFFF |
Humans cannot reason well about the RGB color space
Explore HCL colors with colorspace::choose_color()
5%–8% of men are color blind!
| Name | Hex code | R, G, B (0-255) |
|---|---|---|
| orange | #E69F00 | 230, 159, 0 |
| sky blue | #56B4E9 | 86, 180, 233 |
| bluish green | #009E73 | 0, 158, 115 |
| yellow | #F0E442 | 240, 228, 66 |
| blue | #0072B2 | 0, 114, 178 |
| vermilion | #D55E00 | 213, 94, 0 |
| reddish purple | #CC79A7 | 204, 121, 167 |
| black | #000000 | 0, 0, 0 |


| Scale function | Data type | Palette type | |
|---|---|---|---|
scale_color_hue() |
discrete | qualitative | |
scale_color_gradient() |
continuous | sequential | |
scale_color_gradient2() |
continuous | diverging | |
scale_color_brewer() |
discrete | qualitative, diverging, sequential | |
scale_color_distiller() |
continuous | qualitative, diverging, sequential |
Replace color with fill for shaded areas

scale_color_brewer()
mpg |>
ggplot(aes(x = displ, y = hwy, color = drv)) +
geom_jitter() +
labs(x = "Displacement", y = "Highway fuel efficiency") +
scale_color_brewer(palette = "Accent") +
theme(legend.position = c(0.8, 0.8))

scale_color_distiller()
mpg |>
ggplot(aes(x = displ, y = hwy, color = cty)) +
geom_jitter() +
labs(x = "Displacement", y = "Highway fuel efficiency") +
scale_color_distiller(palette = "YlGnBu") +
theme(legend.position = c(0.8, 0.8))

scale_color_distiller()
mpg |>
ggplot(aes(x = displ, y = hwy, color = cty)) +
geom_jitter() +
labs(x = "Displacement", y = "Highway fuel efficiency") +
scale_color_distiller(palette = "Spectral") +
theme(legend.position = c(0.8, 0.8))




Switch to R script