class: center middle main-title section-title-3 # Graphic design,<br>CRAP, and `theme()` .class-info[ <figure> <img src="img/00/ggplot-logo.png" alt="ggplot" title="ggplot" width="15%"> </figure> ] --- layout: true class: title title-3 --- # Why even care about design? .center[ <figure> <img src="img/02/why-design.png" alt="Why care about design?" title="Why care about design?" width="100%"> </figure> ] --- # Principles of design -- .box-inv-3.medium[There are thousands of books and<br>centuries of debate and theory about<br>what makes good design.] -- .box-3.medium[The easiest<br>and most memorable distillation<br>of these principles is **CRAP**.] --- # CRAP .pull-left[ .box-3[Use these principles as a checklist when creating and critiquing designed objects:] .box-1[Contrast] .box-inv-4[Repetition] .box-inv-1[Alignment] .box-4[Proximity] ] .pull-right.center[ <figure> <img src="img/02/williams-design-book.jpg" alt="Robin Williams's The Non-Designers Design Book" title="Robin Williams's The Non-Designers Design Book" width="65%"> <figcaption>Buy this book and your life will change forever.</figcaption> </figure> ] --- layout: true class: title title-1 --- name: contrast # Contrast .box-inv-1.large[If two items are not exactly<br>the same, make them different.<br>Really different.] -- .box-1.large[**Don't be a wimp.**] --- # Typographic contrast: Family .box-inv-1[Use contrasting type families] .box-1.small[<span style="font-family: 'EB Garamond'">Serif</span> + <span style="font-family: 'Oswald'">Sans serif</span>  <span style="font-family: 'Dancing Script'">Script</span> + <span style="font-family: 'EB Garamond'">Serif</span>  <span style="font-family: 'Alfa Slab One'">Slab</span> + <span style="font-family: 'Oswald'">Sans serif</span>  etc.] <table> <tr> <td class="cell-left">Serif</td> <td class="cell-left" style="font-family: 'EB Garamond'">Sphinx of black quartz, judge my vow</td> </tr> <tr> <td class="cell-left">Sans serif</td> <td class="cell-left" style="font-family: 'Oswald'">Sphinx of black quartz, judge my vow</td> </tr> <tr> <td class="cell-left">Slab serif</td> <td class="cell-left" style="font-family: 'Alfa Slab One'">Sphinx of black quartz, judge my vow</td> </tr> <tr> <td class="cell-left">Script</td> <td class="cell-left" style="font-family: 'Dancing Script'">Sphinx of black quartz, judge my vow</td> </tr> <tr> <td class="cell-left">Monospaced </td> <td class="cell-left" style="font-family: 'Inconsolata'">Sphinx of black quartz, judge my vow</td> </tr> </table> --- # Typographic constrast: Family .box-inv-1[Add contrast in family] .pull-left.frame[ <span style="font-size: 1em; font-family: 'EB Garamond';">Here’s a heading</span> <span style="font-size: 0.9em; font-family: 'Times', serif;">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</span> ] -- .pull-right.frame[ <span style="font-size: 1.1em; font-family: 'Alfa Slab One'; font-weight: 600;">Here’s a heading</span> <span style="font-size: 0.9em; font-family: 'Source Sans Pro'; font-weight: 300;">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</span> ] --- # Typographic contrast: Weight .box-inv-1[Use contrasting weights in same type family] .box-1.small[<span style="font-family: 'Source Sans Pro'; font-weight: 700;">Bold</span> + <span style="font-family: 'Source Sans Pro'; font-weight: 400;">Regular</span>  <span style="font-family: 'Source Sans Pro'; font-weight: 400;">Regular</span> + <span style="font-family: 'Source Sans Pro'; font-weight: 200;">Extra light</span>  <span style="font-family: 'Source Sans Pro'; font-weight: 900;">Black</span> + <span style="font-family: 'Source Sans Pro'; font-weight: 300;">Light</span>  etc.] <table> <tr> <td class="cell-left">Extra light </td> <td class="cell-left" style="font-family: 'Source Sans Pro'; font-weight: 200;">Sphinx of black quartz, judge my vow</td> </tr> <tr> <td class="cell-left">Light</td> <td class="cell-left" style="font-family: 'Source Sans Pro'; font-weight: 300;">Sphinx of black quartz, judge my vow</td> </tr> <tr> <td class="cell-left">Regular</td> <td class="cell-left" style="font-family: 'Source Sans Pro'; font-weight: 400;">Sphinx of black quartz, judge my vow</td> </tr> <tr> <td class="cell-left">Semi bold</td> <td class="cell-left" style="font-family: 'Source Sans Pro'; font-weight: 600;">Sphinx of black quartz, judge my vow</td> </tr> <tr> <td class="cell-left">Bold </td> <td class="cell-left" style="font-family: 'Source Sans Pro'; font-weight: 700;">Sphinx of black quartz, judge my vow</td> </tr> <tr> <td class="cell-left">Black</td> <td class="cell-left" style="font-family: 'Source Sans Pro'; font-weight: 900;">Sphinx of black quartz, judge my vow</td> </tr> </table> --- # Typographic constrast: Weight .box-inv-1[Add contrast in weight] .pull-left.frame[ <span style="font-size: 1em;">Here’s a heading</span> <span style="font-size: 0.9em;">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</span> ] -- .pull-right.frame[ <span style="font-size: 1.3em; font-family: 'Source Sans Pro'; font-weight: 600;">Here’s a heading</span> <span style="font-size: 0.9em; font-family: 'Source Sans Pro'; font-weight: 200;">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</span> ] --- # Size contrast .box-inv-1[Use contrasting sizes] -- .box-1[<span style="font-size: 3em;">Huge</span>  <span style="font-size: 2em;">Big</span>  Regular  <span style="font-size: 0.7em;">Small</span>  <span style="font-size: 0.3em;">Tiny</span>] --- # Color contrast .box-inv-1[Color theory] .box-1.tiny[[color.adobe.com](https://color.adobe.com)] .pull-left[ <figure> <img src="img/02/triad.png" alt="Triad" title="Triad" width="100%"> <figcaption>Triad</figcaption> </figure> <figure> <img src="img/02/monochromatic.png" alt="Monochromatic" title="Monochromatic" width="100%"> <figcaption>Monochromatic</figcaption> </figure> ] .pull-right[ <figure> <img src="img/02/complementary.png" alt="Complementary" title="Complementary" width="100%"> <figcaption>Complementary</figcaption> </figure> <figure> <img src="img/02/complementary-split.png" alt="Split complementary" title="Split complementary" width="100%"> <figcaption>Split complementary</figcaption> </figure> ] --- # Color contrast .center[ <figure> <img src="img/02/palette-atl-extracted.png" alt="Extracted colors" title="Extracted colors" width="50%"> <figcaption>Colors extracted from an image at <a href="https://color.adobe.com">color.adobe.com</a></figcaption> </figure> ] ??? Photo by [Brad Huchteman](https://unsplash.com/photos/sR1Kz2auNJE) on Unsplash --- # Usability and accessibility .box-inv-1.medium[Perceptually uniform colors] .box-1[Values close to each other use similar colors,<br>and values far from each other use different colors] -- .box-inv-1.medium[Colorblind-safe colors] .box-1[8% of men & 0.05% of women have some form of color blindness] .box-1[Colors should be distinguishable by people<br>with common forms of color blindness] --- # Perceptually uniform colors .pull-left[ <figure> <img src="img/02/palettes-typical.png" alt="Typical palettes" title="Typical palettes" width="100%"> <figcaption>Traditional palettes vs. viridis</figcaption> </figure> ] -- .pull-right[ <figure> <img src="img/02/palettes-deuteranopic.png" alt="Deuteranopic palettes" title="Deuteranopic palettes" width="100%"> <figcaption>Traditional palettes vs. viridis as seen with deuteranopia</figcaption> </figure> ] --- # Perceptually uniform colors .pull-left-3[ <figure> <img src="02_crap-themes_files/figure-html/ga1-1.png" width="360" style="display: block; margin: auto;" /> <figcaption>Georgia counties filled by area, rainbow palette (NOT GOOD)</figcaption> </figure> ] -- .pull-middle-3[ <figure> <img src="02_crap-themes_files/figure-html/ga2-1.png" width="360" style="display: block; margin: auto;" /> <figcaption>Georgia counties filled by area, viridis::viridis palette</figcaption> </figure> ] -- .pull-right-3[ <figure> <img src="02_crap-themes_files/figure-html/ga3-1.png" width="360" style="display: block; margin: auto;" /> <figcaption>Georgia counties filled by area, viridis::inferno palette</figcaption> </figure> ] --- layout: true class: title title-inv-4 --- name: repetition # Repetition .box-4.large[Repeat some aspect<br>of the design throughout<br>the entire piece.] --- # Things to repeat .box-4.medium[Colors] -- .box-4.medium[Fonts] .box-inv-4.sp-after[Families, weights, sizes] -- .box-4.medium[Graphical elements] -- .box-4.medium[Alignments] --- layout: false class: bg-full background-image: url("img/02/oxfam-annual-report.jpg") ??? Source: Pages 5 and 9 from Oxfam's 2019 Annual Report/: https://assets.oxfamamerica.org/media/documents/2019_Oxfam_America_Annual_Report_web.pdf If you want to see generally great examples of public sector designs, search for "<big charity or think tank name> annual report", like "red cross annual report" or "urban institute annual report" --- layout: true class: title title-inv-1 --- name: alignment # Alignment .box-1.large[Every item should have a<br>visual connection with<br>something else on the page.] --- # Alignment .pull-left[ <figure> <img src="img/02/alignment-bad.png" alt="Bad alignment" title="Bad alignment" width="100%"> <figcaption>Bad alignment</figcaption> </figure> ] -- .pull-right[ <figure> <img src="img/02/alignment-good.png" alt="Good alignment" title="Good alignment" width="100%"> <figcaption>Good alignment—everything is connected to something</figcaption> </figure> ] ??? Source: Robin Williams, *The Non-Designer's Design Book* --- # Alignment + repetition .box-1[Share lines and repeat alignments where possible.] .pull-left[ <figure> <img src="img/02/alignment-bad-annotated.png" alt="Bad alignment" title="Bad alignment" width="100%"> <figcaption>4 vertical alignments; 3 horizontal alignments</figcaption> </figure> ] .pull-right[ <figure> <img src="img/02/alignment-good-annotated.png" alt="Good alignment" title="Good alignment" width="100%"> <figcaption>1 shared vertical alignment; 2 horizontal alignments</figcaption> </figure> ] --- # Alignment + contrast .box-1[Center + left is super common, but has weak contrast] .box-inv-1[Mixing left and right alignment provides stronger contrast] .pull-left.frame[ <p style="font-size: 0.7em; text-align: center; font-weight: bold;">Chapter 1</p> <p style="font-size: 0.9em; text-align: center; margin-bottom: 1.5em;">Here’s a title</p> <p style="font-size: 0.65em;">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> ] -- .pull-right.frame[ <p style="font-size: 0.7em; text-align: right; font-weight: bold;">Chapter 1</p> <p style="font-size: 0.9em; text-align: right; margin-bottom: 1.5em">Here’s a title</p> <p style="font-size: 0.65em; text-align: justify; hyphens: manual;">Lorem ipsum dolor sit amet, con­sec­tetur adi­pis­icing elit, sed do eiusmod tempor in­ci­di­dunt ut labore et dolore magna aliqua.</p> ] --- layout: true class: title title-4 --- name: proximity # Proximity .box-inv-4.large[Group related items together.] --- # Proximity .box-inv-4[Use white space, color, location, contrast, repetition,<br>alignment, etc. to make visually distinct groupings] -- .pull-left[ <figure> <img src="img/02/proximity-bad.png" alt="Bad proximity" title="Bad proximity" width="100%"> <figcaption>Bad proximity; no logical groupings</figcaption> </figure> ] -- .pull-right[ <figure> <img src="img/02/proximity-good.png" alt="Good proximity" title="Good proximity" width="100%"> <figcaption>Good proximity; information visually grouped</figcaption> </figure> ] ??? Source: Robin Williams, *The Non-Designer's Design Book* --- layout: true class: title title-3 --- # CRAP review .pull-left[ .pull-left[ .box-1[Contrast] <figure> <img src="img/02/review-contrast.png" alt="Contrast" title="Contrast" width="100%"> </figure> ] .pull-right[ .box-inv-4[Repetition] <figure> <img src="img/02/review-repetition.png" alt="Repetition" title="Repetition" width="100%"> </figure> ] ] .pull-right[ .pull-left[ .box-inv-1[Alignment] <figure> <img src="img/02/review-alignment.png" alt="Alignment" title="Alignment" width="100%"> </figure> ] .pull-right[ .box-4[Proximity] <figure> <img src="img/02/review-proximity.png" alt="Proximity" title="Proximity" width="100%"> </figure> ] ] --- # Applying CRAP to ggplot .box-inv-3.medium[We can apply CRAP principles<br>to ggplot plots with `theme()`] .box-inv-3[`theme()` is exceptionally complex,<br>but smart people have made<br>well-designed themes already] .box-3.medium[`theme_*()`] --- # Like this! .left-code[ ```r library(hrbrthemes) ggplot(penguins, aes(x = body_mass_g, y = bill_depth_mm, color = species)) + geom_point(size = 2) + theme_ipsum_ps() ``` ] .right-plot[ ![](02_crap-themes_files/figure-html/hrbrlight-1.png) ] --- # And this! .left-code[ ```r library(hrbrthemes) ggplot(penguins, aes(x = body_mass_g, y = bill_depth_mm, color = species)) + geom_point(size = 2) + theme_modern_rc() ``` ] .right-plot[ ![](02_crap-themes_files/figure-html/hrbrdark-1.png) ] --- # Or this! .left-code[ ```r library(ggthemes) ggplot(penguins, aes(x = body_mass_g, y = bill_depth_mm, color = species)) + geom_point(size = 2) + scale_color_economist() + theme_economist() ``` ] .right-plot[ ![](02_crap-themes_files/figure-html/economist-1.png) ] --- # And even this! .left-code[ ```r library(ggpomological) ggplot(penguins, aes(x = body_mass_g, y = bill_depth_mm, color = species)) + geom_point(size = 2) + scale_color_pomological() + theme_pomological_fancy() ``` ] .right-plot[ ![](02_crap-themes_files/figure-html/pomological-1.png) ] --- layout: false class: title title-3 section-title-inv-3 # Your turn #1 .box-3[Experiment with different `theme_*()`<br>functions by adding them to the plot] .box-3.small[I have already had you load a few theme-specific<br>packages like **ggthemes**, **hrbrthemes**, and **tvthemes**] .box-3.small[Start typing `theme_` and you'll get a popup of all the possible themes you can use] .box-3.small[Or google "r tvthemes" to find the documentation and examples]
05
:
00
--- layout: true class: title title-3 --- # One magic, powerful function .box-inv-3.huge[`theme()`] --- # Theme system .center[ <figure> <a href="https://henrywang.nl/ggplot2-theme-elements-demonstration/" target="_blank"><img src="img/02/theme_elements-1024x755.png" alt="ggplot theme elements" title="ggplot theme elements" width="65%"></a> </figure> ] ??? By [Henry Wang](https://henrywang.nl/ggplot2-theme-elements-demonstration/) --- # Theme elements .box-inv-3.medium[Each element in the plot can be targeted] -- .box-3[Plot title = `plot.title`] -- .box-3[Grid lines = `panel.grid`] -- .box-3[Legend background = `legend.background`] --- # Theme functions .box-inv-3.medium[Use special functions to<br>manipulate specific elements] -- .box-3[Text-based things = `element_text()`] -- .box-3[Rectangular things (backgrounds) = `element_rect()`] -- .box-3[Line-based things (axis lines, grid lines) = `element_line()`] -- .box-3[Disable element completely = `element_blank()`] --- # Pre-made themes .box-inv-3.medium[The `theme()` function has<br>**94** possible arguments(!!!)] -- .box-inv-3.small.sp-after[You can get hyper-specific with things like<br>`axis.ticks.length.x.bottom`] -- .box-inv-3.medium[`theme()` can be intimidating!] -- .box-inv-3.medium[Use pre-made ones and adjust as needed] --- # ggThemeAssist .center[ <figure> <img src="img/02/ggThemeAssist2.gif" alt="ggThemeAssit" title="ggThemeAssit" width="70%"> <figcaption><a href="https://github.com/calligross/ggthemeassist" target="_blank">ggThemeAssist</a></figcaption> </figure> ] --- layout: false class: title title-3 section-title-inv-3 # Your turn #2 .box-3.medium[Use `theme()` to do the following:] - Make the title bold - Make the axis titles left-aligned and bold - Put the legend at the bottom - Remove minor gridlines
05
:
00
--- class: section-title-inv-3 .left-code[ ```r ggplot(penguins, aes(x = body_mass_g, y = bill_depth_mm, color = species)) + geom_point() + labs(title = "Bills are taller in heavier penguins", subtitle = "Gentoo penguins are special", x = "Weight (g)", y = "Bill depth (mm)", color = "Species") + theme_bw() + theme(plot.title = element_text(face = "bold"), axis.title = element_text(hjust = 0, face = "bold"), legend.position = "bottom", panel.grid.minor = element_blank()) ``` ] .right-plot[ ![](02_crap-themes_files/figure-html/your-turn-2-1.png) ] --- class: title title-3 section-title-inv-3 # Your turn #3 .box-3.medium[Use `theme()` to violate every principle of CRAP and make the ugliest plot possible.]
08
:
00
--- class: title title-3 # Next up .box-inv-3.medium[Animated and interactive plots]