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[ 22nd Feb 2022 | methods@manchester | Zoom ] ] </div> --- class: font_smaller # <img src="images/1920px-World_Health_Organization_Logo.svg.png" width="50px" style="vertical-align: middle;"> Tuberculosis incidence <div class="tag center" style="position:absolute;top:2%;left:12%;transform:rotate(-3deg);"> demo data for today </div> The TB data is from the [WHO]( https://www.who.int/tb/country/data/download/en/). .font_small[
] -- <div class="tag center" style="position:absolute;top:40%;left:30%;"> is the data in tidy form? </div> -- <div class="tag center" style="position:absolute;top:40%;left:50%;background-color:#D93F00;color:#FFFFFF;"> no </div> -- <div class="tag center" style="position:absolute;top:50%;left:30%;"> what are the variables? </div> -- <div class="tag center" style="position:absolute;top:50%;left:50%;background-color:#D93F00;color:#FFFFFF;"> country, year, sex, age </div> -- <div class="tag center" style="position:absolute;top:60%;left:30%;"> how many variables are there? </div> -- <div class="tag center" style="position:absolute;top:60%;left:55%;background-color:#D93F00;color:#FFFFFF;"> four (five is ok) </div> -- <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;"> Tidy data .font_small[
] -- <div class="tag center" style="position:absolute;top:20%;left:75%;"> is count a variable? </div> -- <div class="tag center" style="position:absolute;top:30%;left:75%;background-color:#D93F00;color:#FFFFFF;"> no </div> --- .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;" /> ] -- --- What do we learn about the data? <div style="position:absolute;top:10%;left:10%;align:left;padding:20px;border: 2px solid black;background-color:#0081c7;"> 1. Generally, proportion is higher for males<br> 2. Relative proportion is higher for older males<br> 3. Quite variable proportions from year to year<br> </div> -- <div style="position:absolute;top:50%;left:20%;"> What does this plot hide from us? </div> -- <div style="position:absolute;top:60%;left:20%;background-color:#D93F00;color:#FFFFFF;border: 2px solid black;padding:10px;width:500px; align:center"> Information about counts is lost, thus reliability of the proportions is lost </div> --- .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? <br><br><br> - Generally, counts are quite varied from year to year, but relatively stable <br><br> - Increasing trend in counts for both males and females under 35<br><br> - 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? <br><br> In 2010,<br><br> - there were almost no 45-54 year old women with TB<br><br> - there were more 24-35 year old women with TB than men<br><br> - 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 ─────────────────────────────────────────────────────────────── ## setting value ## version R version 4.1.2 (2021-11-01) ## os macOS Big Sur 11.5.1 ## system aarch64, darwin20 ## ui X11 ## language (EN) ## collate en_AU.UTF-8 ## ctype en_AU.UTF-8 ## tz Australia/Melbourne ## date 2022-02-22 ## pandoc 2.16.2 @ /usr/local/bin/ (via rmarkdown) ## ## ─ Packages ─────────────────────────────────────────────────────────────────── ## package * version date (UTC) lib source ## anicon 0.1.0 2022-02-16 [1] Github (emitanaka/anicon@0b756df) ## assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.1.0) ## backports 1.4.1 2021-12-13 [1] CRAN (R 4.1.1) ## bit 4.0.4 2020-08-04 [1] CRAN (R 4.1.1) ## bit64 4.0.5 2020-08-30 [1] CRAN (R 4.1.0) ## brio 1.1.3 2021-11-30 [1] CRAN (R 4.1.1) ## broom 0.7.12 2022-01-28 [1] CRAN (R 4.1.1) ## bslib 0.3.1 2021-10-06 [1] CRAN (R 4.1.1) ## cachem 1.0.6 2021-08-19 [1] CRAN (R 4.1.1) ## 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.2.0 2022-02-14 [1] CRAN (R 4.1.2) ## colorspace 2.0-2 2021-06-24 [1] CRAN (R 4.1.1) ## countdown 0.3.5 2022-02-16 [1] Github (gadenbuie/countdown@a544fa4) ## crayon 1.5.0 2022-02-14 [1] CRAN (R 4.1.2) ## crosstalk 1.2.0 2021-11-04 [1] CRAN (R 4.1.1) ## DBI 1.1.2 2021-12-20 [1] CRAN (R 4.1.1) ## 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.1) ## devtools 2.4.3 2021-11-30 [1] CRAN (R 4.1.1) ## digest 0.6.29 2021-12-01 [1] CRAN (R 4.1.1) ## dplyr * 1.0.8 2022-02-08 [1] CRAN (R 4.1.1) ## DT 0.20 2021-11-15 [1] CRAN (R 4.1.1) ## 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 1.0.2 2022-01-14 [1] CRAN (R 4.1.1) ## 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.1) ## fs 1.5.2 2021-12-08 [1] CRAN (R 4.1.1) ## generics 0.1.2 2022-01-31 [1] CRAN (R 4.1.1) ## ggplot2 * 3.3.5 2021-06-25 [1] CRAN (R 4.1.1) ## glue 1.6.1 2022-01-22 [1] CRAN (R 4.1.1) ## gtable 0.3.0 2019-03-25 [1] CRAN (R 4.1.1) ## haven 2.4.3 2021-08-04 [1] CRAN (R 4.1.1) ## 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.1) ## htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.1.1) ## htmlwidgets 1.5.4 2021-09-08 [1] CRAN (R 4.1.1) ## httr 1.4.2 2020-07-20 [1] CRAN (R 4.1.0) ## icon 0.1.0 2022-02-16 [1] Github (emitanaka/icon@8458546) ## jquerylib 0.1.4 2021-04-26 [1] CRAN (R 4.1.0) ## jsonlite 1.7.3 2022-01-17 [1] CRAN (R 4.1.1) ## knitr 1.37 2021-12-16 [1] CRAN (R 4.1.1) ## 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.1) ## lubridate 1.8.0 2021-10-07 [1] CRAN (R 4.1.1) ## magrittr 2.0.2 2022-01-26 [1] CRAN (R 4.1.1) ## Matrix 1.3-4 2021-06-01 [1] CRAN (R 4.1.2) ## memoise 2.0.1 2021-11-26 [1] CRAN (R 4.1.1) ## 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.7.0 2022-02-01 [1] CRAN (R 4.1.1) ## pkgbuild 1.3.1 2021-12-20 [1] CRAN (R 4.1.1) ## pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.0) ## pkgload 1.2.4 2021-11-30 [1] CRAN (R 4.1.1) ## 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.1) ## RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 4.1.0) ## Rcpp 1.0.8 2022-01-13 [1] CRAN (R 4.1.1) ## readr * 2.1.2 2022-01-30 [1] CRAN (R 4.1.1) ## readxl 1.3.1 2019-03-13 [1] CRAN (R 4.1.0) ## remotes 2.4.2 2021-11-30 [1] CRAN (R 4.1.1) ## reprex 2.0.1 2021-08-05 [1] CRAN (R 4.1.1) ## rlang 1.0.1 2022-02-03 [1] CRAN (R 4.1.1) ## rmarkdown 2.11 2021-09-14 [1] CRAN (R 4.1.1) ## 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.1) ## 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.2 2021-12-06 [1] CRAN (R 4.1.1) ## stringi 1.7.6 2021-11-29 [1] CRAN (R 4.1.1) ## stringr * 1.4.0 2019-02-10 [1] CRAN (R 4.1.1) ## testthat 3.1.2 2022-01-20 [1] CRAN (R 4.1.1) ## tibble * 3.1.6 2021-11-07 [1] CRAN (R 4.1.1) ## tidyr * 1.2.0 2022-02-01 [1] CRAN (R 4.1.1) ## 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.1) ## usethis 2.1.5 2021-12-09 [1] CRAN (R 4.1.1) ## 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.7 2021-11-30 [1] CRAN (R 4.1.1) ## whisker 0.4 2019-08-28 [1] CRAN (R 4.1.0) ## withr 2.4.3 2021-11-30 [1] CRAN (R 4.1.1) ## xaringan 0.22 2021-06-23 [1] CRAN (R 4.1.0) ## xfun 0.29 2021-12-14 [1] CRAN (R 4.1.1) ## xml2 1.3.3 2021-11-30 [1] CRAN (R 4.1.1) ## yaml 2.2.2 2022-01-25 [1] CRAN (R 4.1.1) ## ## [1] /Library/Frameworks/R.framework/Versions/4.1-arm64/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>