class: monash-bg-blue center middle hide-slide-number <div class="bg-black white" style="width:45%;right:0;bottom:0;padding-left:5px;border: solid 4px white;margin: auto;"> <i class="fas fa-exclamation-circle"></i> These slides are viewed best by Chrome and occasionally need to be refreshed if elements did not load properly. See here for <a href=part2-session1.pdf>PDF <i class="fas fa-file-pdf"></i></a>. </div> .white[Push the **right arrow key** to see the next slide.] --- count: false background-image: url(images/d2bg3.jpg) background-size: cover class: hide-slide-number title-slide <div class="grid-row" style="grid: 1fr / 2fr;"> .item.center[ # <span style="text-shadow: 2px 2px 30px white;">Data Visualization with R <br> Workshop Part 2</span> <!-- ## <span style="color:yellow;text-shadow: 2px 2px 30px black;">Review of Grammar of Graphics</span> --> ] .center.shade_black.animated.bounceInUp.slower[ <br><br> ## Review of Grammar of Graphics <br> Presented by Di Cook Department of Econometrics and Business Statistics <img src="images/monash-one-line-reversed.png" style="width:500px"><br>
<i class="fas fa-envelope faa-float animated "></i>
dicook@monash.edu
<i class="fab fa-twitter faa-float animated faa-fast "></i>
@visnut .bottom_abs.width100.bg-black[ 6th Dec 2021 @ Statistical Society of Australia NSW Branch | Zoom ] ] </div> --- class: font_smaller # <img src="images/1920px-World_Health_Organization_Logo.svg.png" width="50px" style="vertical-align: middle;"> Tuberculosis incidence The TB data is from the [WHO]( https://www.who.int/tb/country/data/download/en/). .font_small[
] <div class="tag center animated rubberBand" style="position:absolute;top:2%;left:12%;transform:rotate(-3deg);"> demo data for today </div> --- class: myquestion <br><br><br><br> - Is the data in tidy form? -- - What are the variables in this data? -- - How many variables are there? -- country (name, iso3), year, sex, age -- <br> .color-box[Reshape your data into tidy form so that it is easy, and clear how the variables are maped into elements of the plot.] --- class: center # <img src="images/1920px-World_Health_Organization_Logo.svg.png" width="50px" style="vertical-align: middle;"> Tidying the data .font_small[
] --- .font_small[ ```r ggplot(tb_oz, aes(x = year, y = count, fill = sex)) + * geom_bar(stat = "identity", position = "fill") + facet_wrap(~age_group, ncol = 6) + scale_fill_brewer(name = "Sex", palette = "Dark2") + ylab("Proportion") ``` <br> <br> <img src="images/day2-session1/unnamed-chunk-4-1.png" width="90%" style="display: block; margin: auto;" /> ] -- .corner-box[ 1. Generally, proportion is higher for males 2. Relative proportion is higher for older males 3. Quite variable proportions from year to year ] --- class: question center middle What don't we learn from this plot? -- .color-box[Information about counts is lost] --- .font_small[ ```r ggplot(tb_oz, aes(x = year, y = count, colour = sex)) + * geom_point() + * geom_smooth(se = F) + facet_wrap(~age_group, ncol = 6) + scale_colour_brewer(name = "Sex", palette = "Dark2") ``` <br> <br> <img src="images/day2-session1/unnamed-chunk-5-1.png" width="90%" style="display: block; margin: auto;" /> ] --- # <img src="images/1920px-World_Health_Organization_Logo.svg.png" width="50px" style="vertical-align: middle;"> What do we learn? - Generally, counts are quite varied from year to year, but relatively stable -- - Increasing trend in counts for both males and females under 35 -- - Counts for males almost always higher than females -- --- .font_small[ ```r tb_oz %>% filter(year == 2010) %>% ggplot(aes(x = 1, y = count, fill = sex)) + * geom_bar(stat = "identity", position = "fill") + facet_wrap(~age_group, ncol = 6) + scale_fill_brewer(name = "Sex", palette = "Dark2") + xlab("") + ylab("") + * coord_polar(theta = "y") ``` <br> <br> <img src="images/day2-session1/unnamed-chunk-6-1.png" width="90%" style="display: block; margin: auto;" /> ] --- # <img src="images/1920px-World_Health_Organization_Logo.svg.png" width="50px" style="vertical-align: middle;"> What do we learn? In 2010, - there were almost no 45-54 year old women with TB -- - there were more 24-35 year old women with TB than men -- - generally more males than females had TB -- --- class: question center <br><br><br> How many plots should you usually do? -- .corner-box[**Lots!** In order to understand your data, look at it in many different ways. Like you might do to explore some new object.] --- class: exercise middle hide-slide-number <i class="fas fa-users"></i> # <i class="fas fa-code"></i> Open `part2-exercise-01.Rmd` <center>
15
:
00
</center> --- class: font_smaller background-color: #e5e5e5 # Session Information .scroll-350[ ```r devtools::session_info() ``` ``` ## β Session info π±π¨ π¦΅π½ π€Ύπ½ βββββββββββββββββββββββββββββββββββββββββββββββββ ## hash: flag: St. Lucia, leg: medium skin tone, person playing handball: medium skin tone ## ## setting value ## version R version 4.1.2 (2021-11-01) ## os macOS Big Sur 10.16 ## system x86_64, darwin17.0 ## ui X11 ## language (EN) ## collate en_AU.UTF-8 ## ctype en_AU.UTF-8 ## tz Australia/Melbourne ## date 2021-11-30 ## pandoc 2.11.4 @ /Applications/RStudio.app/Contents/MacOS/pandoc/ (via rmarkdown) ## ## β Packages βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ## package * version date (UTC) lib source ## anicon 0.1.0 2021-11-30 [1] Github (emitanaka/anicon@0b756df) ## assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.1.0) ## backports 1.3.0 2021-10-27 [1] CRAN (R 4.1.0) ## bit 4.0.4 2020-08-04 [1] CRAN (R 4.1.0) ## bit64 4.0.5 2020-08-30 [1] CRAN (R 4.1.0) ## broom 0.7.10 2021-10-31 [1] CRAN (R 4.1.0) ## bslib 0.3.1 2021-10-06 [1] CRAN (R 4.1.0) ## cachem 1.0.6 2021-08-19 [1] CRAN (R 4.1.0) ## callr 3.7.0 2021-04-20 [1] CRAN (R 4.1.0) ## cellranger 1.1.0 2016-07-27 [1] CRAN (R 4.1.0) ## cli 3.1.0 2021-10-27 [1] CRAN (R 4.1.0) ## colorspace 2.0-2 2021-06-24 [1] CRAN (R 4.1.0) ## countdown 0.3.5 2021-11-30 [1] Github (gadenbuie/countdown@a544fa4) ## crayon 1.4.2 2021-10-29 [1] CRAN (R 4.1.0) ## crosstalk 1.2.0 2021-11-04 [1] CRAN (R 4.1.0) ## DBI 1.1.1 2021-01-15 [1] CRAN (R 4.1.0) ## dbplyr 2.1.1 2021-04-06 [1] CRAN (R 4.1.0) ## desc 1.4.0 2021-09-28 [1] CRAN (R 4.1.0) ## devtools 2.4.2 2021-06-07 [1] CRAN (R 4.1.0) ## digest 0.6.28 2021-09-23 [1] CRAN (R 4.1.0) ## dplyr * 1.0.7 2021-06-18 [1] CRAN (R 4.1.0) ## DT 0.20 2021-11-15 [1] CRAN (R 4.1.0) ## ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.1.0) ## evaluate 0.14 2019-05-28 [1] CRAN (R 4.1.0) ## fansi 0.5.0 2021-05-25 [1] CRAN (R 4.1.0) ## farver 2.1.0 2021-02-28 [1] CRAN (R 4.1.0) ## fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.1.0) ## forcats * 0.5.1 2021-01-27 [1] CRAN (R 4.1.0) ## fs 1.5.0 2020-07-31 [1] CRAN (R 4.1.0) ## generics 0.1.1 2021-10-25 [1] CRAN (R 4.1.0) ## ggplot2 * 3.3.5 2021-06-25 [1] CRAN (R 4.1.0) ## glue 1.5.0 2021-11-07 [1] CRAN (R 4.1.0) ## gtable 0.3.0 2019-03-25 [1] CRAN (R 4.1.0) ## haven 2.4.3 2021-08-04 [1] CRAN (R 4.1.0) ## here 1.0.1 2020-12-13 [1] CRAN (R 4.1.0) ## highr 0.9 2021-04-16 [1] CRAN (R 4.1.0) ## hms 1.1.1 2021-09-26 [1] CRAN (R 4.1.0) ## htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.1.0) ## htmlwidgets 1.5.4 2021-09-08 [1] CRAN (R 4.1.0) ## httr 1.4.2 2020-07-20 [1] CRAN (R 4.1.0) ## icon 0.1.0 2021-11-30 [1] Github (emitanaka/icon@8458546) ## jquerylib 0.1.4 2021-04-26 [1] CRAN (R 4.1.0) ## jsonlite 1.7.2 2020-12-09 [1] CRAN (R 4.1.0) ## knitr 1.36 2021-09-29 [1] CRAN (R 4.1.0) ## labeling 0.4.2 2020-10-20 [1] CRAN (R 4.1.0) ## lattice 0.20-45 2021-09-22 [1] CRAN (R 4.1.2) ## lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.1.0) ## lubridate 1.8.0 2021-10-07 [1] CRAN (R 4.1.0) ## magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.1.0) ## Matrix 1.3-4 2021-06-01 [1] CRAN (R 4.1.2) ## memoise 2.0.0 2021-01-26 [1] CRAN (R 4.1.0) ## mgcv 1.8-38 2021-10-06 [1] CRAN (R 4.1.2) ## modelr 0.1.8 2020-05-19 [1] CRAN (R 4.1.0) ## munsell 0.5.0 2018-06-12 [1] CRAN (R 4.1.0) ## nlme 3.1-153 2021-09-07 [1] CRAN (R 4.1.2) ## pillar 1.6.4 2021-10-18 [1] CRAN (R 4.1.0) ## pkgbuild 1.2.0 2020-12-15 [1] CRAN (R 4.1.0) ## pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.0) ## pkgload 1.2.3 2021-10-13 [1] CRAN (R 4.1.0) ## prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.1.0) ## processx 3.5.2 2021-04-30 [1] CRAN (R 4.1.0) ## ps 1.6.0 2021-02-28 [1] CRAN (R 4.1.0) ## purrr * 0.3.4 2020-04-17 [1] CRAN (R 4.1.0) ## R6 2.5.1 2021-08-19 [1] CRAN (R 4.1.0) ## RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 4.1.0) ## Rcpp 1.0.7 2021-07-07 [1] CRAN (R 4.1.0) ## readr * 2.1.0 2021-11-11 [1] CRAN (R 4.1.0) ## readxl 1.3.1 2019-03-13 [1] CRAN (R 4.1.0) ## remotes 2.4.1 2021-09-29 [1] CRAN (R 4.1.0) ## reprex 2.0.1 2021-08-05 [1] CRAN (R 4.1.0) ## rlang 0.4.12 2021-10-18 [1] CRAN (R 4.1.0) ## rmarkdown 2.11 2021-09-14 [1] CRAN (R 4.1.0) ## rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.1.0) ## rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.1.0) ## rvest 1.0.2 2021-10-16 [1] CRAN (R 4.1.0) ## sass 0.4.0 2021-05-12 [1] CRAN (R 4.1.0) ## scales 1.1.1 2020-05-11 [1] CRAN (R 4.1.0) ## sessioninfo 1.2.1 2021-11-02 [1] CRAN (R 4.1.0) ## stringi 1.7.5 2021-10-04 [1] CRAN (R 4.1.0) ## stringr * 1.4.0 2019-02-10 [1] CRAN (R 4.1.0) ## testthat 3.1.0 2021-10-04 [1] CRAN (R 4.1.0) ## tibble * 3.1.6 2021-11-07 [1] CRAN (R 4.1.0) ## tidyr * 1.1.4 2021-09-27 [1] CRAN (R 4.1.0) ## tidyselect 1.1.1 2021-04-30 [1] CRAN (R 4.1.0) ## tidyverse * 1.3.1 2021-04-15 [1] CRAN (R 4.1.0) ## tzdb 0.2.0 2021-10-27 [1] CRAN (R 4.1.0) ## usethis 2.1.3 2021-10-27 [1] CRAN (R 4.1.0) ## utf8 1.2.2 2021-07-24 [1] CRAN (R 4.1.0) ## vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.1.0) ## vroom 1.5.6 2021-11-10 [1] CRAN (R 4.1.0) ## whisker 0.4 2019-08-28 [1] CRAN (R 4.1.0) ## withr 2.4.2 2021-04-18 [1] CRAN (R 4.1.0) ## xaringan 0.22 2021-06-23 [1] CRAN (R 4.1.0) ## xfun 0.28 2021-11-04 [1] CRAN (R 4.1.0) ## xml2 1.3.2 2020-04-23 [1] CRAN (R 4.1.0) ## yaml 2.2.1 2020-02-01 [1] CRAN (R 4.1.0) ## ## [1] /Library/Frameworks/R.framework/Versions/4.1/Resources/library ## ## ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ``` ] These slides are licensed under <br><center><a href="https://creativecommons.org/licenses/by-sa/3.0/au/"><img src="images/cc.svg" style="height:2em;"/><img src="images/by.svg" style="height:2em;"/><img src="images/sa.svg" style="height:2em;"/></a></center>