class: center, middle, inverse, title-slide # presentation ready plots ### 2021-09-29 --- class: middle, inverse # Welcome --- ## Announcements I Project presentations on Friday - Bring a laptop to fill out feedback forms - One more team evaluation to be filled out promptly after class - Presentation order, with latest start-by times: - 12:05 - Ctrl+Alt+Elite - 12:15 - Team 5 Look Alive - 12:25 - Mr. Palmer's Penguins - 12:35 - R-mageddon - 12:45 - 7 Up - 12:55 - The Outliers - 13:05 - Dorian's Gs - 13:15 - The Scatterplots .note[ We might go over by 10 mins max on Friday. I promise to give you back your 10 minutes today or another day. Let me know if this presents a big issue for getting to your next class. ] --- ## Announcements II - After fall break: - Reading quiz 3 due Wed, Oct 6 - New teams! - Take note of Project 2 presentation date: must be in class in person to present or present live via Zoom in the case of isolation - If you have topics you'd like to see covered in the second half of the class that are already on the [schedule](https://www.vizdata.org/schedule.html), let me know! We might be able to shuffle things around / squeeze them in. --- ## Setup .midi[ ```r # load packages library(tidyverse) library(colorspace) library(ggtext) library(scales) library(ggrepel) # 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) ``` ] --- ## Agenda for today - Midterm feedback summary - Wrap up: Annotation - Telling a story - Plots on slides --- class: inverse, middle # Midterm feedback summary --- ## An opportunity to talk more dataviz? ```r midterm_eval <- tibble::tribble( ~class_pace, ~class_time, "About right", "More lecture", "About right", "More live coding", "About right", "More live coding", "About right", "More live coding", "About right", "More live coding", "About right", "More live coding", "About right", "More working in teams", "About right", "No change, keep it as is", "About right", "No change, keep it as is", "About right", "No change, keep it as is", "Too fast", "More live coding", "Too fast", "No change, keep it as is", "Too slow", "More live coding" ) ``` --- ## Class pace 1 .pull-left[ ```r ggplot(midterm_eval, aes(x = class_pace)) + geom_bar() ``` ] .pull-right[ <img src="10-presentation-plots_files/figure-html/unnamed-chunk-3-1.png" width="100%" /> ] --- ## Class pace 2 .pull-left[ ```r ggplot(midterm_eval, aes(x = class_pace)) + geom_bar() + * scale_y_continuous(breaks = seq(0, 10, 2)) ``` ] .pull-right[ <img src="10-presentation-plots_files/figure-html/unnamed-chunk-4-1.png" width="100%" /> ] --- ## Class pace 3 .pull-left[ ```r ggplot(midterm_eval, * aes(y = factor(1), * fill = class_pace) ) + * geom_bar(position = "fill") ``` ] .pull-right[ <img src="10-presentation-plots_files/figure-html/unnamed-chunk-5-1.png" width="100%" /> ] --- ## Class pace 4 .pull-left[ ```r midterm_eval %>% * mutate( * class_pace = fct_relevel(class_pace, * "Too fast", * "About right", * "Too slow") * ) %>% ggplot(aes(y = factor(1), fill = class_pace)) + geom_bar(position = "fill") ``` ] .pull-right[ <img src="10-presentation-plots_files/figure-html/unnamed-chunk-6-1.png" width="100%" /> ] --- ## Class pace 5 .pull-left[ ```r midterm_eval %>% mutate(class_pace = fct_relevel(class_pace, "Too fast", "About right", "Too slow")) %>% ggplot( * aes(y = "Class pace", fill = class_pace) ) + geom_bar(position = "fill") ``` ] .pull-right[ <img src="10-presentation-plots_files/figure-html/unnamed-chunk-7-1.png" width="100%" /> ] --- ## Class pace 6 .pull-left[ ```r midterm_eval %>% mutate(class_pace = fct_relevel(class_pace, "Too fast", "About right", "Too slow")) %>% ggplot(aes(y = "Class pace", fill = class_pace)) + geom_bar(position = "fill") + * labs( * x = "Percentage", * y = NULL, * fill = NULL * ) ``` ] .pull-right[ <img src="10-presentation-plots_files/figure-html/unnamed-chunk-8-1.png" width="100%" /> ] --- ## Class pace 7 .pull-left[ ```r midterm_eval %>% mutate(class_pace = fct_relevel(class_pace, "Too fast", "About right", "Too slow")) %>% ggplot(aes(y = "Class pace", fill = class_pace)) + geom_bar(position = "fill") + labs(x = "Percentage", y = NULL, fill = NULL) + * theme(legend.position = "bottom") ``` ] .pull-right[ <img src="10-presentation-plots_files/figure-html/unnamed-chunk-9-1.png" width="100%" /> ] --- ## Class pace 8 .pull-left[ ```r midterm_eval %>% mutate(class_pace = fct_relevel(class_pace, "Too fast", "About right", "Too slow")) %>% ggplot(aes(y = "Class pace", fill = class_pace)) + geom_bar(position = "fill") + labs(x = "Percentage", y = NULL, fill = NULL) + theme(legend.position = "bottom") + * scale_fill_discrete( * guide = guide_legend(reverse = TRUE) * ) ``` ] .pull-right[ <img src="10-presentation-plots_files/figure-html/unnamed-chunk-10-1.png" width="100%" /> ] --- ## Class pace 9 .pull-left[ ```r midterm_eval %>% mutate(class_pace = fct_relevel(class_pace, "Too fast", "About right", "Too slow")) %>% ggplot(aes(y = "Class pace", fill = class_pace)) + geom_bar(position = "fill") + labs(x = "Percentage", y = NULL, fill = NULL) + theme(legend.position = "bottom") + scale_fill_discrete(guide = guide_legend(reverse = TRUE)) + * scale_x_continuous( * labels = label_percent() * ) ``` ] .pull-right[ <img src="10-presentation-plots_files/figure-html/unnamed-chunk-11-1.png" width="100%" /> ] --- ## Class pace 10 .pull-left[ ```r midterm_eval %>% mutate(class_pace = fct_relevel(class_pace, "Too fast", "About right", "Too slow")) %>% ggplot(aes(y = "Class pace", fill = class_pace)) + geom_bar(position = "fill") + labs(x = "Percentage", y = NULL, fill = NULL) + theme(legend.position = "bottom") + * scale_fill_discrete_diverging( guide = guide_legend(reverse = TRUE) ) + scale_x_continuous(labels = label_percent()) ``` ] .pull-right[ <img src="10-presentation-plots_files/figure-html/unnamed-chunk-12-1.png" width="100%" /> ] --- ## Class pace 11 .pull-left[ ```r midterm_eval %>% mutate(class_pace = fct_relevel(class_pace, "Too fast", "About right", "Too slow")) %>% ggplot(aes(y = "Class pace", fill = class_pace)) + geom_bar(position = "fill") + labs(x = "Percentage", y = NULL, fill = NULL) + theme(legend.position = "bottom") + scale_fill_discrete_diverging(guide = guide_legend(reverse = TRUE)) + scale_x_continuous( labels = label_percent(), * position = "top" ) ``` ] .pull-right[ <img src="10-presentation-plots_files/figure-html/unnamed-chunk-13-1.png" width="100%" /> ] --- ## Class pace 12 No change in code, only adjust `fig.asp` to 0.4. .pull-left[ ```r midterm_eval %>% mutate(class_pace = fct_relevel(class_pace, "Too fast", "About right", "Too slow")) %>% ggplot(aes(y = "Class pace", fill = class_pace)) + geom_bar(position = "fill") + labs(x = "Percentage", y = NULL, fill = NULL) + theme(legend.position = "bottom") + scale_fill_discrete_diverging(guide = guide_legend(reverse = TRUE)) + scale_x_continuous(labels = label_percent(), position = "top" ) ``` ] .pull-right[ <img src="10-presentation-plots_files/figure-html/unnamed-chunk-14-1.png" width="100%" /> ] --- ## Class time .panelset.sideways[ .panel[.panel-name[Code] ```r midterm_eval %>% mutate( class_time = str_remove(class_time, ", keep it as is"), class_time = fct_relevel(class_time, "More lecture", "No change", "More live coding", "More working in teams") ) %>% ggplot(aes(y = "Class time", fill = class_time)) + geom_bar(position = "fill") + labs( x = "Percentage", y = NULL, fill = NULL ) + theme( legend.position = "bottom", legend.direction = "vertical" ) + scale_fill_manual( values = c("#BCC1D4", "#E2E2E2", "#D6BCC0", "#8E063B"), guide = guide_legend(nrow = 2, reverse = TRUE) ) + scale_x_continuous(labels = label_percent(), position = "top") ``` ] .panel[.panel-name[Plot] <img src="10-presentation-plots_files/figure-html/unnamed-chunk-15-1.png" width="100%" /> ] ] --- ## Other feedback - Need more practice: - Scaling - Data cleaning/transformation - Planning a unique visualization -- - Time spend: - ~6 hrs/week on average out of class - 3.75 hrs/week in class - Total: ~9.75 hrs/week -- - Misc: - Grading: - HW: Randomly assign to graders (TAs) for each assignment - Project: Averaged across all graders (TAs + prof) - Release assignments earlier - Tips for creating a web (GitHub) portfolio --- class: inverse, middle # Wrap up: Annotation --- ## Explanations -> annotations **Rule of thumb:** If you feel the need to draw your audience's attention to a particular feature of the plot, experiment with doing so using annotation instead of in words. --- ## Rewind: Sizes of planes ```r rdu_flights_2020 <- read_csv(here::here("data/rdu-flights-2020.csv")) rdu_planes_2020 <- read_csv(here::here("data/rdu-planes-2020.csv")) ``` ```r rdu_flights_planes <- rdu_flights_2020 %>% inner_join(rdu_planes_2020, by = "tailnum") %>% mutate( size = case_when( seats <= 30 ~ "Small", seats >= 31 & seats <= 110 ~ "Medium", seats >= 111 & seats <= 210 ~ "Large", seats > 211 ~ "Jumbo" ), size = fct_relevel(size, "Small", "Medium", "Large", "Jumbo") ) ``` --- .task[ How can we improve this visualization, in terms of color, axes, and annotation? ] .panelset.sideways[ .panel[.panel-name[Plot] <img src="10-presentation-plots_files/figure-html/planes-1.png" width="100%" /> ] .panel[.panel-name[Code] ```r rdu_flights_planes %>% count(hour, size) %>% ggplot(aes(x = hour, y = n, color = size)) + geom_line() + labs( x = "Hour of day", y = "Number of flights", color = "Size of plane", title = "Number of flights out of RDU in 2020", subtitle = "By size of plane", caption = "Source: FAA Aircraft Registry and\nBureau of Transportation Statistics" ) ``` ] .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> ] ] --- class: middle .large[.hand[livecoding...]] <br> > Code along at `vizdata-f21/exercise-03`, then `rdu-flights` --- class: middle # Telling a story --- ## Multiple ways of telling a story - Sequential plots: Motivation, then resolution - A single plot: Resolution, and hidden in it motivation <br> .note[ **Project note:** you're asked to create two plots per question. One possible approach: Start with a plot showing the raw data, and show derived quantities (e.g. percent increases, averages, coefficients of fitted models) in the subsequent plot. ] --- ## Simplicity vs. complexity > When you’re trying to show too much data at once you may end up not showing anything. - Never assume your audience can rapidly process complex visual displays - Don't add variables to your plot that are tangential to your story - Don't jump straight to a highly complex figure; first show an easily digestible subset (e.g., show one facet first) - Aim for memorable, but clear <br> .note[ **Project note:** Make sure to leave time to iterate on your plots after you practice your presentation. If certain plots are getting too wordy to explain, take time to simplify them! ] --- ## Consistency vs. repetitiveness > Be consistent but don’t be repetitive. - Use consistent features throughout plots (e.g., same color represents same level on all plots) - Aim to use a different type of visualization for each distinct analysis <br> .note[ **Project note:** If possible, ask a friend who is not in the class to listen to your presentation and then ask them what they remember. Then, ask yourself: is that what you wanted them to remember? ] --- class: middle # Plots on slides --- ## Fitting your figures on a slide - Use a setup chunk for consistent `dpi`, `fig.asp`, `out.width` etc. - But, remember that you might want different `fig.asp` and `out.width` for faceted plots - For a "zoomed out" look, increase `fig.width` .pull-left[ <img src="10-presentation-plots_files/figure-html/unnamed-chunk-20-1.png" width="100%" /> ] .pull-right[ <img src="10-presentation-plots_files/figure-html/unnamed-chunk-21-1.png" width="100%" /> ] --- ## Multiple figures on a slide - Use `.pull-left` and `.pull-right` environments (example in slide template) - Use `out.width= "50%"` in a chunk that creates two plots to have each span half the slide and be placed next to each other (or `out.width = "33%"` for three plots, etc.) - Use the [**patchwork**](https://patchwork.data-imaginist.com/) package (details on this later in the semester, but feel free to look into it yourself!) - Possibly, use pivoting to reshape your data and then use facets --- ## Like something you saw in my slides? <br> Look into the source code at https://github.com/vizdata-f21/slides.