class: center, middle, inverse, title-slide .title[ # Visualizations and the Grammar of Graphics ] .author[ ### INFO 5940
Cornell University ] --- class: inverse, middle # Why visualize data? --- class: center, middle | ID| `\(N\)`| `\(\bar{X}\)`| `\(\bar{Y}\)`| `\(\sigma_{X}\)`| `\(\sigma_{Y}\)`| `\(R\)`| |--:|---:|---------:|---------:|------------:|------------:|----------:| | 1| 142| 54.26610| 47.83472| 16.76983| 26.93974| -0.0641284| | 2| 142| 54.26873| 47.83082| 16.76924| 26.93573| -0.0685864| | 3| 142| 54.26732| 47.83772| 16.76001| 26.93004| -0.0683434| | 4| 142| 54.26327| 47.83225| 16.76514| 26.93540| -0.0644719| | 5| 142| 54.26030| 47.83983| 16.76774| 26.93019| -0.0603414| | 6| 142| 54.26144| 47.83025| 16.76590| 26.93988| -0.0617148| | 7| 142| 54.26881| 47.83545| 16.76670| 26.94000| -0.0685042| | 8| 142| 54.26785| 47.83590| 16.76676| 26.93610| -0.0689797| | 9| 142| 54.26588| 47.83150| 16.76885| 26.93861| -0.0686092| | 10| 142| 54.26734| 47.83955| 16.76896| 26.93027| -0.0629611| | 11| 142| 54.26993| 47.83699| 16.76996| 26.93768| -0.0694456| | 12| 142| 54.26692| 47.83160| 16.77000| 26.93790| -0.0665752| | 13| 142| 54.26015| 47.83972| 16.76996| 26.93000| -0.0655833| --- class: center, middle <img src="index_files/figure-html/datasaurus-lm-1.png" width="90%" style="display: block; margin: auto;" /> --- class: center, middle <img src="index_files/figure-html/datasaurus-graph-1.gif" width="90%" style="display: block; margin: auto;" /> --- class: center, middle <img src="index_files/figure-html/datasaurus-graph-static-1.png" width="90%" style="display: block; margin: auto;" /> --- class: inverse, middle # The grammar of graphics --- ## Grammar > The whole system and structure of a language or of languages in general, usually taken as consisting of syntax and morphology (including inflections) and sometimes also phonology and semantics. -- ### Grammar of graphics * "The fundamental principles or rules of an art or science" * A grammar used to describe and create a wide range of statistical graphics * Layered grammar of graphics --- <img src="https://raw.githubusercontent.com/allisonhorst/stats-illustrations/main/rstats-artwork/ggplot2_masterpiece.png" alt="A fuzzy monster in a beret and scarf, critiquing their own column graph ona canvas in front of them while other assistant monsters (also in berets) carry overboxes full of elements that can be used to customize a graph (like themes andgeometric shapes). In the background is a wall with framed data visualizations.Stylized text reads 'ggplot2: build a data masterpiece.'" width="60%" style="display: block; margin: auto;" /> .footnote[Source: [Allison Horst](https://github.com/allisonhorst/stats-illustrations)] --- class: inverse, middle # Applying the grammar of graphics to an historic data visualization --- class: middle <img src="../../../../../../../../img/minard.png" width="90%" style="display: block; margin: auto;" /> .footnote[Source: [Wikipedia](https://en.wikipedia.org/wiki/File:Minard.png)] --- ## Building Minard's map in R .pull-left[ ### `troops` ``` ## # A tibble: 51 × 4 ## long lat survivors direction ## <dbl> <dbl> <dbl> <chr> ## 1 24 54.9 340000 A ## 2 24.5 55 340000 A ## 3 25.5 54.5 340000 A ## 4 26 54.7 320000 A ## 5 27 54.8 300000 A ## 6 28 54.9 280000 A ## 7 28.5 55 240000 A ## 8 29 55.1 210000 A ## 9 30 55.2 180000 A ## 10 30.3 55.3 175000 A ## # … with 41 more rows ``` ] .pull-right[ ### `cities` ``` ## # A tibble: 20 × 3 ## long lat city ## <dbl> <dbl> <chr> ## 1 24 55 Kowno ## 2 25.3 54.7 Wilna ## 3 26.4 54.4 Smorgoni ## 4 26.8 54.3 Moiodexno ## 5 27.7 55.2 Gloubokoe ## 6 27.6 53.9 Minsk ## 7 28.5 54.3 Studienska ## 8 28.7 55.5 Polotzk ## 9 29.2 54.4 Bobr ## 10 30.2 55.3 Witebsk ## # … with 10 more rows ``` ] --- ## Minard's grammar .pull-left[ * Troops * Latitude * Longitude * Survivors * Advance/retreat * Cities * Latitude * Longitude * City name ] .pull-right[ * Layer * Data * Mapping * Statistical transformation (stat) * Geometric object (geom) * Position adjustment (position) * Scale * Coordinate system * Faceting ]
10
:
00
--- # Exercise: Gapminder <img src="index_files/figure-html/gapminder-over-time-1.gif" width="80%" style="display: block; margin: auto;" /> --- class: inverse, middle # Wrap-up --- # Wrap-up - Get registered for the course - Log in to [GitHub Enterprise](https://github.coecis.cornell.edu/) - Demonstrate the homework workflow