Lecture 18
Duke University
STA 113 - Fall 2023
Palette name: Okabe-Ito
Palette name: ColorBrewer Set1
Palette name: ColorBrewer Set3
Palette name: Viridis
Palette name: Inferno
Palette name: Cividis
Palette name: ColorBrewer PiYG
Palette name: Carto Earth
Palette name: Blue-Red
Palette name: Grays with accents
Palette name: Okabe-Ito accent
Palette name: ColorBrewer accent
temps_months
dataGetting the temps_months
data:
temps_months <- read_csv("data/tempnormals.csv") |>
group_by(location, month_name) |>
summarize(mean = mean(temperature)) |>
mutate(
month = factor(
month_name,
levels = c("Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
),
location = factor(
location, levels = c("Death Valley", "Houston", "San Diego", "Chicago")
)
) |>
select(-month_name)
temps_months
dataThe temps_months
data:
popgrowth
dataGetting the popgrowth
data:
US_census <- read_csv("data/US_census.csv")
US_regions <- read_csv("data/US_regions.csv")
popgrowth <- left_join(US_census, US_regions) |>
group_by(region, division, state) |>
summarize(
pop2000 = sum(pop2000, na.rm = TRUE),
pop2010 = sum(pop2010, na.rm = TRUE),
popgrowth = (pop2010-pop2000)/pop2000,
.groups = "drop"
) |>
mutate(region = factor(region, levels = c("West", "South", "Midwest", "Northeast")))
popgrowth
dataThe popgrowth
data:
# A tibble: 51 × 6
region division state pop2000 pop2010 popgrowth
<fct> <chr> <chr> <dbl> <dbl> <dbl>
1 Midwest East North Central Illinois 12419293 12830632 0.0331
2 Midwest East North Central Indiana 6080485 6483802 0.0663
3 Midwest East North Central Michigan 9938444 9883640 -0.00551
4 Midwest East North Central Ohio 11353140 11536504 0.0162
5 Midwest East North Central Wisconsin 5363675 5686986 0.0603
6 Midwest West North Central Iowa 2926324 3046355 0.0410
7 Midwest West North Central Kansas 2688418 2853118 0.0613
8 Midwest West North Central Minnesota 4919479 5303925 0.0781
9 Midwest West North Central Missouri 5595211 5988927 0.0704
10 Midwest West North Central Nebraska 1711263 1826341 0.0672
# ℹ 41 more rows
Scale function | Aesthetic | Data type | Palette type |
---|---|---|---|
scale_color_hue() |
color |
discrete | qualitative |
Scale function | Aesthetic | Data type | Palette type |
---|---|---|---|
scale_color_hue() |
color |
discrete | qualitative |
scale_fill_hue() |
fill |
discrete | qualitative |
Scale function | Aesthetic | Data type | Palette type |
---|---|---|---|
scale_color_hue() |
color |
discrete | qualitative |
scale_fill_hue() |
fill |
discrete | qualitative |
scale_color_gradient() |
color |
continuous | sequential |
Scale function | Aesthetic | Data type | Palette type |
---|---|---|---|
scale_color_hue() |
color |
discrete | qualitative |
scale_fill_hue() |
fill |
discrete | qualitative |
scale_color_gradient() |
color |
continuous | sequential |
scale_color_gradient2() |
color |
continuous | diverging |
Scale function | Aesthetic | Data type | Palette type |
---|---|---|---|
scale_color_hue() |
color |
discrete | qualitative |
scale_fill_hue() |
fill |
discrete | qualitative |
scale_color_gradient() |
color |
continuous | sequential |
scale_color_gradient2() |
color |
continuous | diverging |
scale_fill_viridis_c() |
color |
continuous | sequential |
scale_fill_viridis_d() |
fill |
discrete | sequential |
scale_color_brewer() |
color |
discrete | qualitative, diverging, sequential |
scale_fill_brewer() |
fill |
discrete | qualitative, diverging, sequential |
scale_color_distiller() |
color |
continuous | qualitative, diverging, sequential |
… and there are many many more
Scale name: scale_<aesthetic>_<datatype>_<colorscale>()
<aesthetic>
: name of the aesthetic (fill
, color
, colour
)<datatype>
: type of variable plotted (discrete
, continuous
, binned
)<colorscale>
: type of the color scale (qualitative
, sequential
, diverging
, divergingx
)Scale function | Aesthetic | Data type | Palette type |
---|---|---|---|
scale_color_discrete_qualitative() |
color |
discrete | qualitative |
scale_fill_continuous_sequential() |
fill |
continuous | sequential |
scale_colour_continous_divergingx() |
colour |
continuous | diverging |
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 |
High chroma: Toys
Low chroma: “Elegance”
5%–8% of men are color blind!
Red-green color-vision deficiency is the most common
5%–8% of men are color blind!
Blue-green color-vision deficiency is rare but does occur
Choose colors that can be distinguished with CVD
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 |
When in doubt, run CVD simulations