class: center, middle, inverse, title-slide # Grammar of Graphics ## Mini-Lecture 5 ### Ben Baumer ### SDS 192Feb 5, 2020(
http://beanumber.github.io/sds192/lectures/05-ggplot.html
) --- class: center, middle, inverse # Announcements --- <iframe src="https://embed.polleverywhere.com/multiple_choice_polls/09hIqsHhAwVDtj0iJ4Aqh?controls=none&short_poll=true" width="800" height="600" frameBorder="0"></iframe> --- <iframe src="https://embed.polleverywhere.com/multiple_choice_polls/OhD4wlRf6Xbb1tbnWG7uy?controls=none&short_poll=true" width="800" height="600" frameBorder="0"></iframe> --- <iframe src="https://embed.polleverywhere.com/multiple_choice_polls/JVfJ121MJart2TfmT3p7q?controls=none&short_poll=true" width="800" height="600" frameBorder="0"></iframe> --- <iframe src="https://embed.polleverywhere.com/multiple_choice_polls/jYPWPvRGACvIuZee0KoMy?controls=none&short_poll=true" width="800" height="600" frameBorder="0"></iframe> --- class: center, middle, inverse # Slack review --- ## Magnitude of difference in perceptual hierarchy > One thing I was wondering about was the difference between our ability to perceive different visual cues in the hierarchy. For example, **how much** better is our ability to perceive position than our ability to perceive length? -- - It's all in the original paper: https://www.jstor.org/stable/pdf/2288400.pdf --- ## Color > I also thought that it is interesting how **color is often the most misused** out of the visual cues. It is still unclear to me how it can be misused a lot when color is visually appealing. -- - visual appeal vs. scientific import -- - more about color on Friday... --- ## Referring to the book/slides > I **relied heavily on the slides** from Friday in order to identify the necessary components of the graph taxonomies for all of the graphs > This lab was pretty straightforward. **Referring back to ch. 2.2 in the book** helped a lot with clarifying questions about how to label things and what to focus on -- - Many ways to learn in this class -- - Find a combination that works for you -- - **The lectures do NOT replace the reading!!** -- - Solutions to old labs post automatically retroactively --- ## Interactivity > One thing I am curious about is movement/animation and interactive data visualization--when you click through to the article for examples 1 and 2 they are interactive and move. In terms of the perceptual hierarchy, **where and how does movement fit in**? -- - I don't know. That's more of a Jordan Crouser question! - See also [Human-computer interaction](https://en.wikipedia.org/wiki/Human%E2%80%93computer_interaction) --- ## The big question > I'm wondering when we visualize data by ourselves, **how to choose** the proper visual cues when two of them share similar function? Besides paying attention to perceptual hierarchy, what other factors we should take care of? Like being attractive (using color)? Among those factors, **how** could we make the best choices? -- - data graphic design is an art and a science! --- class: center, middle, inverse # `ggplot2` ![](https://d21ii91i3y6o6h.cloudfront.net/gallery_images/from_proof/9296/small/1447173871/rstudio-hex-ggplot2-dot-psd.png) --- ## `ggplot2` - No one uses `ggplot1` - implementation of the *grammar of graphics* - [cheatsheet](https://github.com/rstudio/cheatsheets/raw/master/data-visualization-2.1.pdf) .footnote[https://ggplot2.tidyverse.org/] --- ## What is the "Grammar of Graphics"? Big idea: independently specify plot building blocks and combine them to create just about any kind of graphical display you want --- ## Building blocks of data graphics - data (obvi.) - `data` - geometric objects (the literal stuff we draw) - `geom_*()` - aesthetic mappings (how we draw that stuff) - `aes()` - scales (range of values, colors, etc.) - `scale_*()` - faceting (small multiples) - `facet_wrap()`, `facet_grid()` --- ## Basic template ```r library(tidyverse) ggplot(data = mtcars, aes(x = disp, y = mpg)) + geom_point() ``` ![](figures/gg-simple-1.png)<!-- --> --- ## More complicated ```r ggplot(data = mtcars, aes(x = disp, y = mpg, color = factor(cyl))) + geom_point() + geom_line() + facet_wrap(~am) + scale_colour_brewer(palette = "Set1") ``` ![](figures/gg-complex-1.png)<!-- --> --- class: center, middle # [Live Coding Demo] --- class: inverse ## Now 1. Lab \#3: ["Graphics with `ggplot2`"](lab-ggplot2.html) - a word on "Laptop time" 2. [Homework \#1](../hw/hw_ggplot.html) - due Sunday just before midnight - submit **R Markdown** file to Moodle