class: center, middle, inverse, title-slide # deep dive:
axes+annotation ### 2021-09-24 --- class: middle, inverse # Welcome --- ## Announcements - Revised proposals for my review: due Fri, Sep 24 (today) at 5pm - Planning for project presentations - A couple surveys coming your way! --- ## Agenda for today - Wrap up: Colors - Axes - Annotation --- ## Setup .midi[ ```r # load packages library(tidyverse) library(colorspace) library(colorblindr) # install_github("wilkelab/colorblindr") library(ggtext) library(scales) library(fs) library(openintro) library(palmerpenguins) library(dsbox) # set default theme for ggplot2 ggplot2::theme_set(ggplot2::theme_minimal(base_size = 16)) # set default figure parameters for knitr knitr::opts_chunk$set( fig.width = 8, fig.asp = 0.618, fig.retina = 3, dpi = 300, out.width = "60%" ) # dplyr print min and max options(dplyr.print_max = 6, dplyr.print_min = 6) ``` ] --- class: inverse, middle # Wrap up: Colors --- ## Color scales 1. Distinguish categories (qualitative) 2. Represent numeric values (sequential) 3. Represent numeric values (diverging) 4. Highlight --- ## The **colorspace** package Scale name: `scale_<aesthetic>_<datatype>_<colorscale>()` - `<aesthetic>`: name of the aesthetic (`fill`, `color`) - `<datatype>`: type of variable plotted (`discrete`, `continuous`, `binned`) - `<colorscale>`: type of the color scale (`qualitative`, `sequential`, `diverging`, `divergingx`) --- ## Qualitative palettes <img src="09-axes-annotation_files/figure-html/unnamed-chunk-2-1.png" width="85%" /> --- ## Sequential palettes <img src="09-axes-annotation_files/figure-html/unnamed-chunk-3-1.png" width="85%" /> --- ## Diverging palettes <img src="09-axes-annotation_files/figure-html/unnamed-chunk-4-1.png" width="85%" /> --- ## **ggplot2** + **colorspace** ```r p <- ggplot(penguins, aes(x = bill_length_mm, y = body_mass_g, color = species)) + geom_point(size = 3) + theme(legend.position = "top") ``` .pull-left[ ```r p + * scale_color_discrete_qualitative() ``` <img src="09-axes-annotation_files/figure-html/unnamed-chunk-6-1.png" width="100%" /> ] .pull-right[ ```r p + * scale_color_discrete_sequential() ``` <img src="09-axes-annotation_files/figure-html/unnamed-chunk-7-1.png" width="100%" /> ] --- ## Color palettes + accessibility At a minimum, use color palettes known to be colorblind friendly ```r p + * scale_color_OkabeIto() ``` <img src="09-axes-annotation_files/figure-html/unnamed-chunk-8-1.png" width="70%" /> --- ## Color palettes + accessibility While not a perfect solution, simulating color blindness to check that your palette is color blind friendly is a good first step (e.g., [SimDaltonism](https://michelf.ca/projects/sim-daltonism/) is what I use) .panelset[ .panel[.panel-name[Default] <img src="09-axes-annotation_files/figure-html/unnamed-chunk-9-1.png" width="60%" /> ] .panel[.panel-name[OkabeIto] <img src="09-axes-annotation_files/figure-html/unnamed-chunk-10-1.png" width="60%" /> ] ] --- ## Custom palettes - Create your own palette with `colorspace::hclcolorpicker()` - Keep chroma low! --- ## Color inspiration - [Pantone colors of the year](https://www.pantone.com/color-of-the-year-archive), e.g. for 2021 Ultimate Gray and Illuminating - Generate a palette from an image, e.g., with [coolors.co/image-picker](https://coolors.co/image-picker) <img src="images/nypl-palette.png" width="60%" style="display: block; margin: auto;" /> --- ## Colors for highlighting Keep context in mind, e.g., here we're using the blue from the Connecticut flag <img src="09-axes-annotation_files/figure-html/unnamed-chunk-12-1.png" width="80%" /> --- class: middle .hand[livecoding...] --- class: inverse, middle # Axes --- ## Axis breaks .task[ How can the following figure be improved with custom breaks in axes, if at all? ] <img src="09-axes-annotation_files/figure-html/unnamed-chunk-14-1.png" width="70%" /> --- ## Context matters ```r pac_plot + * scale_x_continuous(breaks = seq(from = 2000, to = 2020, by = 2)) ``` <img src="09-axes-annotation_files/figure-html/unnamed-chunk-15-1.png" width="70%" /> --- ## Conciseness matters ```r pac_plot + scale_x_continuous(breaks = seq(2000, 2020, 4)) ``` <img src="09-axes-annotation_files/figure-html/unnamed-chunk-16-1.png" width="70%" /> --- ## Precision matters ```r pac_plot + scale_x_continuous(breaks = seq(2000, 2020, 4)) + * labs(x = "Election year") ``` <img src="09-axes-annotation_files/figure-html/unnamed-chunk-17-1.png" width="70%" /> --- class: inverse # Annotation --- ## `geom_text()` Can be useful when individual observations are identifiable, but can also get overwhelming... .task[ How would you improve this visualization? ] .panelset[ .panel[.panel-name[Plots] .pull-left[ <img src="09-axes-annotation_files/figure-html/unnamed-chunk-18-1.png" width="100%" /> ] .pull-right[ <img src="09-axes-annotation_files/figure-html/unnamed-chunk-19-1.png" width="100%" /> ] ] .panel[.panel-name[Discuss] <iframe src="https://app.sli.do/event/rxg9buzy" height="100%" width="100%" frameBorder="0" style="min-height: 560px;" title="Slido"></iframe> ] ]