class: center, middle, inverse, title-slide # Data Visualization ## Dynamic graphics ### Andrew Irwin,
a.irwin@dal.ca
### Math & Stats, Dalhousie University ### 2021-03-12 (updated: 2021-03-09) --- class: middle # Plan * Advantages and disadvantages of dynamic graphics? * When should you use dynamic graphics? * Examples * Application in this course --- class: middle ### When and Why should you use dynamic graphics? * Interactivity * Show changes over time (in the data) over time (as perceived by the viewer) * Easy to make too complicated * Requires interaction and may not immediately make the point you want to make * Distracting --- class: middle ### Highlights and interaction [Link to interactive graphic](dynamic-graphics-1.html) ```r p1 <- penguins %>% plot_ly(x = ~ body_mass_g, y = ~ bill_length_mm) %>% add_markers(color = ~ species) p1 ```
```r htmlwidgets::saveWidget(as_widget(p1), "dynamic-graphics-1.html") ``` --- class: middle ### Animations Easy to create with `gganimate`. Make a regular ggplot, then use a variable to show how it changes over time. ```r penguins %>% ggplot(aes(bill_length_mm, bill_depth_mm, color = species)) + geom_point() + my_theme ``` <img src="26-dynamic-graphics_files/figure-html/unnamed-chunk-2-1.png" width="50%" height="50%" style="display: block; margin: auto;" /> --- class: middle ### Animations Easy to create with `gganimate`. Make a regular ggplot, then use a variable to show how it changes over time. Shown on next slide. ```r b = seq(2500, 6500, by = 500) anim1 <- penguins %>% mutate(size_class = cut(body_mass_g, breaks=b, dig.lab=4), group=1:n()) %>% ggplot(aes(bill_length_mm, bill_depth_mm, color = species, group=group)) + geom_point() + labs(title = "Body mass in the interval {closest_state}") + transition_states(size_class) + enter_fade() + exit_fade() + my_theme ``` --- class: middle ### Animations <img src="26-dynamic-graphics_files/figure-html/unnamed-chunk-4-1.gif" style="display: block; margin: auto;" /> --- class: middle ### Summary * Dynamic and interactive graphics can be fun to create * Making good use of these features requires practice * Use sparingly! Think of your audience and goals * Best example: animation of gapminder data over years --- class: middle # Further reading * Course notes --- class: middle, inverse ## Task * No task for this lesson