class: center, middle, inverse, title-slide # Fundamentals of Data Visualization ### K Arnold, based on IntroDS.org --- ## Problem of Diverse Audiences * Some of you have seen R, visualization, etc. before. > "This is still just review" -- says several people * Some of you had CS 108 years ago... > "I'm totally lost" -- many people think, few say -> **Yejae office hour today 4:30-5:30p** -> My office hours **Fridays 3-4pm, Mondays 8-9am**. --- ## Q & A > *When to use Console vs Rmarkdown?* * **RMarkdown** is your source of truth. Use Console just to explore. * Something broke? **Restart R and Run All** > *Why two assignment operators?* * `<-` assigns variables in *current environment*: `data <- read_csv()` * `=` labels arguments to *functions*: `ggplot(data = dino_data)` * You can use `=` instead of `<-`, but we won't. --- ## Q & A > What is the difference between `.Rmd` and `.md`? * Usually: `Rmd` -> **knit** -> `.html` or `.pdf` * But `.html` doesn't show up nice in github * So we told Rmarkdown to make an `md`, which does show up nice. --- class: center, middle 🧶 **knit** ✅ **commit** ⬆️ **push** --- <img src="img/whole-game-01.png" width="100%" /> --- <img src="img/whole-game-02.png" width="100%" /> --- <img src="img/whole-game-03.png" width="100%" /> --- <img src="img/whole-game-04.png" width="100%" /> --- ## Asking good questions - Always include your code and the error - Create a minimum working example (we'll keep working on this throughout the semester) - Use code formatting --- class: center, middle <iframe width="560" height="315" src="https://www.youtube.com/embed/Z8t4k0Q8e8Y" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> --- ```r library(gapminder) library(ggplot2) ``` ```r gapminder %>% head(5) %>% knitr::kable() ``` |country |continent | year| lifeExp| pop| gdpPercap| |:-----------|:---------|----:|-------:|--------:|---------:| |Afghanistan |Asia | 1952| 28.801| 8425333| 779.4453| |Afghanistan |Asia | 1957| 30.332| 9240934| 820.8530| |Afghanistan |Asia | 1962| 31.997| 10267083| 853.1007| |Afghanistan |Asia | 1967| 34.020| 11537966| 836.1971| |Afghanistan |Asia | 1972| 36.088| 13079460| 739.9811| --- ### We'll make this chart <img src="w2d2-vis_files/figure-html/health-and-wealth-1.png" width="50%" style="display: block; margin: auto;" /> --- ## ggplot2 `\(\in\)` tidyverse .pull-left[ <img src="img/ggplot2-part-of-tidyverse.png" width="80%" /> ] .pull-right[ - **ggplot2** is tidyverse's data visualization package - The `gg` in "ggplot2" stands for Grammar of Graphics - It is inspired by the book **Grammar of Graphics** by Leland Wilkinson ] --- ## Grammar of Graphics Concisely describe the components of a graphic <img src="img/grammar-of-graphics.png" width="70%" style="display: block; margin: auto;" /> .tiny[ Source: [BloggoType](http://bloggotype.blogspot.com/2016/08/holiday-notes2-grammar-of-graphics.html) ] --- .pull-left[ <img src="img/channels-continuous-part1.png" width="90%" /> ] .pull-right[ <img src="img/channels-continuous-part2.png" width="90%" /> ] .tiny[ Source: https://socviz.co/lookatdata.html#channels-for-representing-data ] ---