class: center, middle, inverse, title-slide # Data Visualization ## Colour ### Andrew Irwin,
a.irwin@dal.ca
### Math & Stats, Dalhousie University ### 2021-03-24 (updated: 2021-03-12) --- class: middle # Plan * Discrete colour scales * Continuous colour scales * viridis colour * other palettes * custom colours --- class: middle ### Colour guidelines - Discrete * Not too many * Keep brightness constant --- class: middle ### Colour guidelines - Continuous * One shade, vary brightness * Two shades if there is a natural middle or 0, white in middle * Avoid red-green diverging scales --- class: middle ### Discrete colour scales ```r penguins %>% ggplot(aes(body_mass_g, flipper_length_mm, color = species)) + geom_point() + my_theme ``` <img src="31-colour_files/figure-html/unnamed-chunk-1-1.svg" width="60%" style="display: block; margin: auto;" /> --- class: middle ### Discrete colour scales ```r penguins %>% ggplot(aes(body_mass_g, flipper_length_mm, color = species)) + geom_point() + my_theme + scale_color_viridis_d(end = 0.7) ``` <img src="31-colour_files/figure-html/unnamed-chunk-2-1.svg" width="60%" style="display: block; margin: auto;" /> --- class: middle ### Discrete colour scales ```r penguins %>% ggplot(aes(body_mass_g, flipper_length_mm, color = species)) + geom_point() + my_theme + scale_color_paletteer_d("ggthemes::hc_default") ``` <img src="31-colour_files/figure-html/unnamed-chunk-3-1.svg" width="60%" style="display: block; margin: auto;" /> --- class: middle ### Discrete colour scales ```r penguins %>% ggplot(aes(body_mass_g, flipper_length_mm, color = species)) + geom_point() + my_theme + scale_color_manual(values = c("red", "blue", "orange")) ``` <img src="31-colour_files/figure-html/unnamed-chunk-4-1.svg" width="60%" style="display: block; margin: auto;" /> --- ### Continuous colour shades ```r gapminder %>% filter(country %in% c("Canada", "China", "Chile", "Iceland")) %>% ggplot(aes(year, lifeExp, color = log10(pop))) + geom_point(size=3) + my_theme ``` <img src="31-colour_files/figure-html/unnamed-chunk-5-1.svg" width="60%" style="display: block; margin: auto;" /> --- ### Continuous colour shades - diverging ```r p1 <- penguins %>% mutate(body_mass_centered = body_mass_g - mean(body_mass_g, na.rm=TRUE)) %>% ggplot(aes(flipper_length_mm, bill_length_mm, color = body_mass_centered)) + geom_point(size=3) + theme_bw() + # scale_color_distiller(type="div", palette="RdBu", limits = c(-2000,2000)) scale_color_fermenter(type="div", palette="RdBu", limits = c(-2000,2000)) ``` --- ### Continuous colour shades - diverging <img src="31-colour_files/figure-html/unnamed-chunk-7-1.svg" width="80%" style="display: block; margin: auto;" /> --- class: middle # Further reading * Course notes * Healy and Wilke sections on colour --- class: middle, inverse ## Task * Practice using colour * No assigned task