class: center, middle, inverse, title-slide # Let them eat cake first! ##
What they forgot to teach you
about
teaching
R ###
wtf-teach.netlify.app
--- layout: true <div class="my-footer"> <span> <a href="http://wtf-teach.netlify.app/" target="_blank">wtf-teach.netlify.app</a> </span> </div> --- class: inverse, middle # Let's start with a question... --- class: middle, inverse ## How do you prefer your cake recipes? Words only, or words & pictures? .pull-left[ <img src="images/recipe-picture.png" width="60%" style="display: block; margin: auto;" /> ] .pull-right[ <img src="images/recipe-words.png" width="60%" style="display: block; margin: auto;" /> ] --- class: middle, inverse ## How do you prefer your cake recipes? Words only, or words & pictures? .pull-left[ <img src="01-cake_files/figure-html/recipe-picture-selected-1.png" width="60%" style="display: block; margin: auto;" /> ] .pull-right[ <img src="01-cake_files/figure-html/recipe-words-xed-1.png" width="60%" style="display: block; margin: auto;" /> ] --- .pull-left[ <img src="images/recipe-picture.png" width="250" height="150" style="display: block; margin: auto;" /> - Open today's demo project - Knit the document and discuss the visualisation you made with your neighbor - Then, change `Turkey` to a different country, and plot again ] .pull-right[ <img src="images/recipe-words.png" width="250" height="150" style="display: block; margin: auto;" /> .small[ ```r x <- 8 y <- "monkey" z <- FALSE class(x) ``` ``` ## [1] "numeric" ``` ```r class(y) ``` ``` ## [1] "character" ``` ```r class(z) ``` ``` ## [1] "logical" ``` ] ] --- class: middle ## .hand[ with with great examples, ] ## .hand[ comes a great amount of code... ] --- class: middle ## .hand[ but let’s focus on the task at hand... ] - Open today's demo project - Knit the document and discuss the visualisation you made with your neighbor - Then, **.pink[ change `Turkey` to a different country, and plot again]** --- .midi[ ```r un_votes %>% mutate(country = case_when( country == "United Kingdom of Great Britain and Northern Ireland" ~ "UK & NI", country == "United States of America" ~ "US", TRUE ~ country ) ) %>% inner_join(un_roll_calls, by = "rcid") %>% inner_join(un_roll_call_issues, by = "rcid") %>% filter(country %in% c("UK & NI", "US", "Turkey")) %>% mutate(year = year(date)) %>% group_by(country, year, issue) %>% summarize(percent_yes = mean(vote == "yes")) %>% ggplot(mapping = aes(x = year, y = percent_yes, color = country)) + geom_point(alpha = 0.4) + geom_smooth(method = "loess", se = FALSE) + facet_wrap(~issue) + scale_y_continuous(labels = percent) + labs( title = "Percentage of 'Yes' votes in the UN General Assembly", subtitle = "1946 to 2015", y = "% Yes", x = "Year", color = "Country" ) ``` ] --- .midi[ ```r un_votes %>% mutate(country = case_when( country == "United Kingdom of Great Britain and Northern Ireland" ~ "UK & NI", country == "United States of America" ~ "US", TRUE ~ country ) ) %>% inner_join(un_roll_calls, by = "rcid") %>% inner_join(un_roll_call_issues, by = "rcid") %>% * filter(country %in% c("UK & NI", "US", "Turkey")) %>% mutate(year = year(date)) %>% group_by(country, year, issue) %>% summarize(percent_yes = mean(vote == "yes")) %>% ggplot(mapping = aes(x = year, y = percent_yes, color = country)) + geom_point(alpha = 0.4) + geom_smooth(method = "loess", se = FALSE) + facet_wrap(~issue) + scale_y_continuous(labels = percent) + labs( title = "Percentage of 'Yes' votes in the UN General Assembly", subtitle = "1946 to 2015", y = "% Yes", x = "Year", color = "Country" ) ``` ] --- .midi[ ```r un_votes %>% mutate(country = case_when( country == "United Kingdom of Great Britain and Northern Ireland" ~ "UK & NI", country == "United States of America" ~ "US", TRUE ~ country ) ) %>% inner_join(un_roll_calls, by = "rcid") %>% inner_join(un_roll_call_issues, by = "rcid") %>% * filter(country %in% c("UK & NI", "US", "France")) %>% mutate(year = year(date)) %>% group_by(country, year, issue) %>% summarize(percent_yes = mean(vote == "yes")) %>% ggplot(mapping = aes(x = year, y = percent_yes, color = country)) + geom_point(alpha = 0.4) + geom_smooth(method = "loess", se = FALSE) + facet_wrap(~issue) + scale_y_continuous(labels = percent) + labs( title = "Percentage of 'Yes' votes in the UN General Assembly", subtitle = "1946 to 2015", y = "% Yes", x = "Year", color = "Country" ) ``` ] --- class: inverse, middle # Your turn --- class: inverse, middle # Back to the main course --- class: middle ## .hand[ non-trivial examples can be motivating, ] ## .hand[ but need to avoid ] 👇 .pull-left[ <img src="images/owl-step1.png" width="250" height="390" style="display: block; margin: auto 0 auto auto;" /> ] .pull-right[ <img src="images/owl-step2.png" width="250" height="390" style="display: block; margin: auto auto auto 0;" /> ] --- class: middle .center[ .three-column[ <img src="images/owl-step1.png" width="250" height="400" style="display: block; margin: auto;" /> ] .three-column[ ## .center[ .hand[ scaffold + layer ] ] ] .three-column[ <img src="images/owl-step2.png" width="250" height="400" style="display: block; margin: auto;" /> ] ] --- .small[ ```r *ggplot(un_uk_us_tr) ``` <img src="01-cake_files/figure-html/unnamed-chunk-5-1.png" width="80%" style="display: block; margin: auto;" /> ] --- .small[ ```r ggplot(un_uk_us_tr, * aes(x = year, y = percent_yes)) ``` <img src="01-cake_files/figure-html/unnamed-chunk-6-1.png" width="80%" style="display: block; margin: auto;" /> ] --- .small[ ```r ggplot(un_uk_us_tr, aes(x = year, y = percent_yes)) + * geom_point() ``` <img src="01-cake_files/figure-html/unnamed-chunk-7-1.png" width="80%" style="display: block; margin: auto;" /> ] --- .small[ ```r ggplot(un_uk_us_tr, aes(x = year, y = percent_yes)) + geom_point() + * facet_wrap(~issue) ``` <img src="01-cake_files/figure-html/unnamed-chunk-8-1.png" width="80%" style="display: block; margin: auto;" /> ] --- .small[ ```r ggplot(un_uk_us_tr, * aes(x = year, y = percent_yes, color = country)) + geom_point() + facet_wrap(~issue) ``` <img src="01-cake_files/figure-html/unnamed-chunk-9-1.png" width="80%" style="display: block; margin: auto;" /> ] --- .small[ ```r ggplot(un_uk_us_tr, aes(x = year, y = percent_yes, color = country)) + * geom_point(alpha = 0.4) + facet_wrap(~issue) ``` <img src="01-cake_files/figure-html/unnamed-chunk-10-1.png" width="80%" style="display: block; margin: auto;" /> ] --- .small[ ```r ggplot(un_uk_us_tr, aes(x = year, y = percent_yes, color = country)) + geom_point(alpha = 0.4) + * geom_smooth(method = "loess", se = FALSE) + facet_wrap(~issue) ``` <img src="01-cake_files/figure-html/unnamed-chunk-11-1.png" width="80%" style="display: block; margin: auto;" /> ] --- .small[ ```r ggplot(un_uk_us_tr, aes(x = year, y = percent_yes, color = country)) + geom_point(alpha = 0.4) + geom_smooth(method = "loess", se = FALSE) + facet_wrap(~issue) + * labs( * title = "Percentage of 'Yes' votes in the UN General Assembly", * subtitle = "1946 to 2015", * y = "% Yes", x = "Year", color = "Country" * ) ``` <img src="01-cake_files/figure-html/unnamed-chunk-12-1.png" width="80%" style="display: block; margin: auto;" /> ] --- .small[ ```r ggplot(un_uk_us_tr, aes(x = year, y = percent_yes, color = country)) + geom_point(alpha = 0.4) + geom_smooth(method = "loess", se = FALSE) + facet_wrap(~issue) + labs( title = "Percentage of 'Yes' votes in the UN General Assembly", subtitle = "1946 to 2015", y = "% Yes", x = "Year", color = "Country" ) + * scale_y_continuous(labels = label_percent()) ``` <img src="01-cake_files/figure-html/unnamed-chunk-13-1.png" width="80%" style="display: block; margin: auto;" /> ]