class: center, middle, inverse, title-slide # Color and Themes ## Mini-Lecture 6 ### Ben Baumer ### SDS 192Feb 7, 2020(
http://beanumber.github.io/sds192/lectures/06-color.html
) --- class: inverse # Announcements - Office hours confusion (my mistake!) - Mondays from 1:20β2:35 - ~~Thursdays~~ Wednesdays from 2:00β3:30 - by appointment -- - Sign up for an account on [GitHub](http://www.github.com) -- - [DataFest](http://www.science.smith.edu/datafest/) info session Coming soon... ![](http://www.science.smith.edu/datafest/wp-content/uploads/sites/12/2015/02/cropped-DataFestHeader-noyear.png) --- class: center, middle, inverse # Color --- ## Three color schemes .pull-left[ - Sequential - Single hue - Multi-hue - Diverging - Categorical ] .pull-right[ ![](https://media.giphy.com/media/3oriO1VZF0t5PyQVlC/giphy.gif) ] -- Big Idea: color **choices matter** and there are better and worse choices --- ## Sequential, single hue .pull-left[ ![](figures/cali_single_hue-1.png)<!-- --> ] .pull-right[ - Map [**saturation**](https://en.wikipedia.org/wiki/Colorfulness) to numeric variable - No more than 5--6 levels - People interpret high saturation as more ] --- ## Sequential, single hue .pull-left[ ![](figures/cali_single_hue_discrete-1.png)<!-- --> ] .pull-right[ - Map [**saturation**](https://en.wikipedia.org/wiki/Colorfulness) to numeric variable - **No more than 5--6 levels** - People interpret high saturation as more ] --- ## Sequential, double hue .pull-left[ - Map [**hue**](https://en.wikipedia.org/wiki/Hue) to numeric variable - Generally, no more than 2 anchor colors - People interpret darker hue as more ] .pull-right[ ![](figures/cali-multihue-1.png)<!-- --> ] --- ## Diverging .pull-left[ ![](figures/cali-diverging-1.png)<!-- --> ] .pull-right[ - Two colors used to indicate extremes of a range - Neutral color in the middle - distinguish between *zero* and *missing* ] --- ## Categorical .pull-left[ - Different color = different category - choose colors that are - perceptually distant - roughly the same saturation ] .pull-right[ ![](figures/cali-categorical-1.png)<!-- --> ] --- ## Built-in color palettes - Cynthia Brewer .footnote[http://www.colorbrewer2.org] - `RColorBrewer` package - `scale_color_brewer()` function - [`viridis`](https://cran.r-project.org/web/packages/viridis/vignettes/intro-to-viridis.html) palettes mimic `matplotlib` Python library --- ## Sorry, no rainbows .pull-left[ ![](https://media.giphy.com/media/3o7aD0Meng5BT8IejK/giphy.gif) ] .pull-right[ - β π NO RAINBOWS!! - [Why rainbow colors arenβt the best option for data visualizations](https://www.poynter.org/archive/2013/why-rainbow-colors-arent-always-the-best-options-for-data-visualizations/) - [How The Rainbow Color Map Misleads](https://eagereyes.org/basics/rainbow-color-map) ] .footnote[https://policyviz.com/2018/08/07/dataviz-cheatsheet/] --- ## `ggplot2` default color ```r library(tidyverse) rand_data <- data.frame(x = rnorm(10000), y = rnorm(10000)) norm_plot <- ggplot(rand_data, aes(x = x, y = y)) + geom_hex() + coord_fixed() norm_plot ``` ![](figures/norm_plot-1.png)<!-- --> --- ## ColorBrewer `Purples` palette ```r norm_plot + scale_fill_distiller(palette = "Purples") ``` ![](figures/norm_plot_distiller-1.png)<!-- --> --- ## ColorBrewer `YlGn` palette ```r norm_plot + scale_fill_distiller(palette = "YlGn") ``` ![](figures/norm_plot_distiller2-1.png)<!-- --> --- ## Viridis palette ```r norm_plot + scale_fill_viridis_c() ``` ![](figures/norm_plot_viridis-1.png)<!-- --> --- class: center, middle # Themes --- ## Take any ggplot... ```r library(tidyverse) p1 <- ggplot(mtcars, aes(x = disp, y = mpg, color = factor(cyl))) + geom_point() p1 ``` ![](figures/gg1-1.png)<!-- --> --- ## ...and change themes with `ggthemes` ```r library(ggthemes) p1 + theme_wsj() ``` ![](figures/gg-theme-1.png)<!-- --> --- class: inverse # [Mini-project \#1](../mod_viz.html) - You've been practicing - reproducible workflow (i.e. R Markdown) - data graphic creation (i.e. `ggplot2`) - critical thinking about data graphics (i.e. taxonomy, etc.) - Now it's time to weave in - collaboration - iterative prototyping and editing - meaningful analysis - **Tip**: open a `New Project...` in RStudio --- class: inverse # Now 1. Lab \#4: ["ColorBrewer and `ggthemes`"](../lab-colorbrewer-ggthemes.html) 2. Homework \#2: - due **Thursday** just before midnight 3. Find your partners for mini-project \#1 - randomly assigned on Moodle (see `#mp1` channel) - Please read [code of conduct](https://dsc-wav.github.io/www/conduct.html)