class: center, middle, inverse, title-slide # multiple series ### Gina Reynolds --- ```r library(tidyverse) library(gapminder) ``` --- class: inverse, center, middle name: mult_series ## a few series --- class: split-40 count: false .left-code-time_series_multi_build-auto[ ```r *gapminder ``` ] .right-output-time_series_multi_build-auto[ ``` # A tibble: 1,704 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Afghanistan Asia 1952 28.8 8425333 779. 2 Afghanistan Asia 1957 30.3 9240934 821. 3 Afghanistan Asia 1962 32.0 10267083 853. 4 Afghanistan Asia 1967 34.0 11537966 836. 5 Afghanistan Asia 1972 36.1 13079460 740. 6 Afghanistan Asia 1977 38.4 14880372 786. 7 Afghanistan Asia 1982 39.9 12881816 978. 8 Afghanistan Asia 1987 40.8 13867957 852. 9 Afghanistan Asia 1992 41.7 16317921 649. 10 Afghanistan Asia 1997 41.8 22227415 635. # … with 1,694 more rows ``` ] --- class: split-40 count: false .left-code-time_series_multi_build-auto[ ```r gapminder %>% * filter(continent == "Oceania") ``` ] .right-output-time_series_multi_build-auto[ ``` # A tibble: 24 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Australia Oceania 1952 69.1 8691212 10040. 2 Australia Oceania 1957 70.3 9712569 10950. 3 Australia Oceania 1962 70.9 10794968 12217. 4 Australia Oceania 1967 71.1 11872264 14526. 5 Australia Oceania 1972 71.9 13177000 16789. 6 Australia Oceania 1977 73.5 14074100 18334. 7 Australia Oceania 1982 74.7 15184200 19477. 8 Australia Oceania 1987 76.3 16257249 21889. 9 Australia Oceania 1992 77.6 17481977 23425. 10 Australia Oceania 1997 78.8 18565243 26998. # … with 14 more rows ``` ] --- class: split-40 count: false .left-code-time_series_multi_build-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% * mutate(gdp = pop * gdpPercap) ``` ] .right-output-time_series_multi_build-auto[ ``` # A tibble: 24 x 7 country continent year lifeExp pop gdpPercap gdp <fct> <fct> <int> <dbl> <int> <dbl> <dbl> 1 Australia Oceania 1952 69.1 8691212 10040. 87256254102. 2 Australia Oceania 1957 70.3 9712569 10950. 106349227169. 3 Australia Oceania 1962 70.9 10794968 12217. 131884573002. 4 Australia Oceania 1967 71.1 11872264 14526. 172457986742. 5 Australia Oceania 1972 71.9 13177000 16789. 221223770658. 6 Australia Oceania 1977 73.5 14074100 18334. 258037329175. 7 Australia Oceania 1982 74.7 15184200 19477. 295742804309. 8 Australia Oceania 1987 76.3 16257249 21889. 355853119294. 9 Australia Oceania 1992 77.6 17481977 23425. 409511234952. 10 Australia Oceania 1997 78.8 18565243 26998. 501223252921. # … with 14 more rows ``` ] --- class: split-40 count: false .left-code-time_series_multi_build-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(gdp = pop * gdpPercap) %>% * ggplot() ``` ] .right-output-time_series_multi_build-auto[ <img src="geoms_multi_series_files/figure-html/time_series_multi_build_auto_4_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_multi_build-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(gdp = pop * gdpPercap) %>% ggplot() + * aes(x = year) ``` ] .right-output-time_series_multi_build-auto[ <img src="geoms_multi_series_files/figure-html/time_series_multi_build_auto_5_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_multi_build-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(gdp = pop * gdpPercap) %>% ggplot() + aes(x = year) + * aes(y = gdp) ``` ] .right-output-time_series_multi_build-auto[ <img src="geoms_multi_series_files/figure-html/time_series_multi_build_auto_6_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_multi_build-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(gdp = pop * gdpPercap) %>% ggplot() + aes(x = year) + aes(y = gdp) + * geom_point() ``` ] .right-output-time_series_multi_build-auto[ <img src="geoms_multi_series_files/figure-html/time_series_multi_build_auto_7_output-1.png" width="100%" /> ] <style> .left-code-time_series_multi_build-auto { color: #777; width: 49%; height: 92%; float: left; font-size: 80% } .right-output-time_series_multi_build-auto { width: 50%; float: right; padding-left: 1%; } </style> --- class: split-40 count: false .left-code-time_series_multi-rotate[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(gdp = pop * gdpPercap) %>% ggplot() + aes(x = year) + aes(y = gdp) + geom_point() + geom_line(aes(linetype = country, color = country)) + theme_minimal() ``` ] .right-output-time_series_multi-rotate[ <img src="geoms_multi_series_files/figure-html/time_series_multi_rotate_1_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_multi-rotate[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(gdp = pop * gdpPercap) %>% ggplot() + aes(x = year) + aes(y = gdp) + geom_point() + * ggforce::geom_bspline(aes(linetype = country)) + theme_minimal() ``` ] .right-output-time_series_multi-rotate[ <img src="geoms_multi_series_files/figure-html/time_series_multi_rotate_2_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_multi-rotate[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(gdp = pop * gdpPercap) %>% ggplot() + aes(x = year) + aes(y = gdp) + geom_point() + * geom_col(aes(fill = country), position = "dodge", alpha = .4) + theme_minimal() ``` ] .right-output-time_series_multi-rotate[ <img src="geoms_multi_series_files/figure-html/time_series_multi_rotate_3_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_multi-rotate[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(gdp = pop * gdpPercap) %>% ggplot() + aes(x = year) + aes(y = gdp) + geom_point() + * geom_col(aes(fill = country), alpha = .4) + theme_minimal() ``` ] .right-output-time_series_multi-rotate[ <img src="geoms_multi_series_files/figure-html/time_series_multi_rotate_4_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_multi-rotate[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(gdp = pop * gdpPercap) %>% ggplot() + aes(x = year) + aes(y = gdp) + geom_point() + * geom_area(aes(fill = country), alpha = .4) + theme_minimal() ``` ] .right-output-time_series_multi-rotate[ <img src="geoms_multi_series_files/figure-html/time_series_multi_rotate_5_output-1.png" width="100%" /> ] <style> .left-code-time_series_multi-rotate { color: #777; width: 49%; height: 92%; float: left; font-size: 80% } .right-output-time_series_multi-rotate { width: 50%; float: right; padding-left: 1%; } </style> --- --- class: inverse, center, middle # Many series --- class: split-40 count: false .left-code-aes_group-auto[ ```r *gapminder ``` ] .right-output-aes_group-auto[ ``` # A tibble: 1,704 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Afghanistan Asia 1952 28.8 8425333 779. 2 Afghanistan Asia 1957 30.3 9240934 821. 3 Afghanistan Asia 1962 32.0 10267083 853. 4 Afghanistan Asia 1967 34.0 11537966 836. 5 Afghanistan Asia 1972 36.1 13079460 740. 6 Afghanistan Asia 1977 38.4 14880372 786. 7 Afghanistan Asia 1982 39.9 12881816 978. 8 Afghanistan Asia 1987 40.8 13867957 852. 9 Afghanistan Asia 1992 41.7 16317921 649. 10 Afghanistan Asia 1997 41.8 22227415 635. # … with 1,694 more rows ``` ] --- class: split-40 count: false .left-code-aes_group-auto[ ```r gapminder %>% * filter(continent %in% c("Americas", "Oceania")) ``` ] .right-output-aes_group-auto[ ``` # A tibble: 324 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Argentina Americas 1952 62.5 17876956 5911. 2 Argentina Americas 1957 64.4 19610538 6857. 3 Argentina Americas 1962 65.1 21283783 7133. 4 Argentina Americas 1967 65.6 22934225 8053. 5 Argentina Americas 1972 67.1 24779799 9443. 6 Argentina Americas 1977 68.5 26983828 10079. 7 Argentina Americas 1982 69.9 29341374 8998. 8 Argentina Americas 1987 70.8 31620918 9140. 9 Argentina Americas 1992 71.9 33958947 9308. 10 Argentina Americas 1997 73.3 36203463 10967. # … with 314 more rows ``` ] --- class: split-40 count: false .left-code-aes_group-auto[ ```r gapminder %>% filter(continent %in% c("Americas", "Oceania")) %>% * ggplot() ``` ] .right-output-aes_group-auto[ <img src="geoms_multi_series_files/figure-html/aes_group_auto_3_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-aes_group-auto[ ```r gapminder %>% filter(continent %in% c("Americas", "Oceania")) %>% ggplot() + * aes(x = year) ``` ] .right-output-aes_group-auto[ <img src="geoms_multi_series_files/figure-html/aes_group_auto_4_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-aes_group-auto[ ```r gapminder %>% filter(continent %in% c("Americas", "Oceania")) %>% ggplot() + aes(x = year) + * aes(y = lifeExp) ``` ] .right-output-aes_group-auto[ <img src="geoms_multi_series_files/figure-html/aes_group_auto_5_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-aes_group-auto[ ```r gapminder %>% filter(continent %in% c("Americas", "Oceania")) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + * geom_point() ``` ] .right-output-aes_group-auto[ <img src="geoms_multi_series_files/figure-html/aes_group_auto_6_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-aes_group-auto[ ```r gapminder %>% filter(continent %in% c("Americas", "Oceania")) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + geom_point() + * geom_line() ``` ] .right-output-aes_group-auto[ <img src="geoms_multi_series_files/figure-html/aes_group_auto_7_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-aes_group-auto[ ```r gapminder %>% filter(continent %in% c("Americas", "Oceania")) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + geom_point() + geom_line() + * aes(color = country) ``` ] .right-output-aes_group-auto[ <img src="geoms_multi_series_files/figure-html/aes_group_auto_8_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-aes_group-auto[ ```r gapminder %>% filter(continent %in% c("Americas", "Oceania")) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + geom_point() + geom_line() + aes(color = country) + * scale_color_discrete(guide = F) ``` ] .right-output-aes_group-auto[ <img src="geoms_multi_series_files/figure-html/aes_group_auto_9_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-aes_group-auto[ ```r gapminder %>% filter(continent %in% c("Americas", "Oceania")) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + geom_point() + geom_line() + aes(color = country) + scale_color_discrete(guide = F) + * aes(color = NULL) ``` ] .right-output-aes_group-auto[ <img src="geoms_multi_series_files/figure-html/aes_group_auto_10_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-aes_group-auto[ ```r gapminder %>% filter(continent %in% c("Americas", "Oceania")) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + geom_point() + geom_line() + aes(color = country) + scale_color_discrete(guide = F) + aes(color = NULL) + * aes(group = country) ``` ] .right-output-aes_group-auto[ <img src="geoms_multi_series_files/figure-html/aes_group_auto_11_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-aes_group-auto[ ```r gapminder %>% filter(continent %in% c("Americas", "Oceania")) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + geom_point() + geom_line() + aes(color = country) + scale_color_discrete(guide = F) + aes(color = NULL) + aes(group = country) + * geom_point(data = . %>% # using global data * filter(country %in% # filtering to * c("New Zealand","Chile")), # NZ and Chile * color = "plum4", * size = 4) ``` ] .right-output-aes_group-auto[ <img src="geoms_multi_series_files/figure-html/aes_group_auto_12_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-aes_group-auto[ ```r gapminder %>% filter(continent %in% c("Americas", "Oceania")) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + geom_point() + geom_line() + aes(color = country) + scale_color_discrete(guide = F) + aes(color = NULL) + aes(group = country) + geom_point(data = . %>% # using global data filter(country %in% # filtering to c("New Zealand","Chile")), # NZ and Chile color = "plum4", size = 4) + * geom_line(data = . %>% * filter(country %in% * c("New Zealand","Chile")), * color = "plum4", * size = 2) ``` ] .right-output-aes_group-auto[ <img src="geoms_multi_series_files/figure-html/aes_group_auto_13_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-aes_group-auto[ ```r gapminder %>% filter(continent %in% c("Americas", "Oceania")) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + geom_point() + geom_line() + aes(color = country) + scale_color_discrete(guide = F) + aes(color = NULL) + aes(group = country) + geom_point(data = . %>% # using global data filter(country %in% # filtering to c("New Zealand","Chile")), # NZ and Chile color = "plum4", size = 4) + geom_line(data = . %>% filter(country %in% c("New Zealand","Chile")), color = "plum4", size = 2) + * geom_text(data = . %>% * filter(country %in% * c("New Zealand","Chile")) %>% * group_by(country) %>% * slice(3), * aes(label = country), * nudge_y = 2, hjust = .7, * color = "plum4", size = 5, * fontface = "bold") ``` ] .right-output-aes_group-auto[ <img src="geoms_multi_series_files/figure-html/aes_group_auto_14_output-1.png" width="100%" /> ] <style> .left-code-aes_group-auto { color: #777; width: 49%; height: 92%; float: left; font-size: 80% } .right-output-aes_group-auto { width: 50%; float: right; padding-left: 1%; } </style> --- class: split-40 count: false .left-code-difference_ribbon-auto[ ```r *gapminder ``` ] .right-output-difference_ribbon-auto[ ``` # A tibble: 1,704 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Afghanistan Asia 1952 28.8 8425333 779. 2 Afghanistan Asia 1957 30.3 9240934 821. 3 Afghanistan Asia 1962 32.0 10267083 853. 4 Afghanistan Asia 1967 34.0 11537966 836. 5 Afghanistan Asia 1972 36.1 13079460 740. 6 Afghanistan Asia 1977 38.4 14880372 786. 7 Afghanistan Asia 1982 39.9 12881816 978. 8 Afghanistan Asia 1987 40.8 13867957 852. 9 Afghanistan Asia 1992 41.7 16317921 649. 10 Afghanistan Asia 1997 41.8 22227415 635. # … with 1,694 more rows ``` ] --- class: split-40 count: false .left-code-difference_ribbon-auto[ ```r gapminder %>% * filter(continent == "Oceania") ``` ] .right-output-difference_ribbon-auto[ ``` # A tibble: 24 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Australia Oceania 1952 69.1 8691212 10040. 2 Australia Oceania 1957 70.3 9712569 10950. 3 Australia Oceania 1962 70.9 10794968 12217. 4 Australia Oceania 1967 71.1 11872264 14526. 5 Australia Oceania 1972 71.9 13177000 16789. 6 Australia Oceania 1977 73.5 14074100 18334. 7 Australia Oceania 1982 74.7 15184200 19477. 8 Australia Oceania 1987 76.3 16257249 21889. 9 Australia Oceania 1992 77.6 17481977 23425. 10 Australia Oceania 1997 78.8 18565243 26998. # … with 14 more rows ``` ] --- class: split-40 count: false .left-code-difference_ribbon-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% * mutate(pop_millions = pop/1000000) ``` ] .right-output-difference_ribbon-auto[ ``` # A tibble: 24 x 7 country continent year lifeExp pop gdpPercap pop_millions <fct> <fct> <int> <dbl> <int> <dbl> <dbl> 1 Australia Oceania 1952 69.1 8691212 10040. 8.69 2 Australia Oceania 1957 70.3 9712569 10950. 9.71 3 Australia Oceania 1962 70.9 10794968 12217. 10.8 4 Australia Oceania 1967 71.1 11872264 14526. 11.9 5 Australia Oceania 1972 71.9 13177000 16789. 13.2 6 Australia Oceania 1977 73.5 14074100 18334. 14.1 7 Australia Oceania 1982 74.7 15184200 19477. 15.2 8 Australia Oceania 1987 76.3 16257249 21889. 16.3 9 Australia Oceania 1992 77.6 17481977 23425. 17.5 10 Australia Oceania 1997 78.8 18565243 26998. 18.6 # … with 14 more rows ``` ] --- class: split-40 count: false .left-code-difference_ribbon-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) -> *gm_oceania ``` ] .right-output-difference_ribbon-auto[ ] --- class: split-40 count: false .left-code-difference_ribbon-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) -> gm_oceania *gm_oceania ``` ] .right-output-difference_ribbon-auto[ ``` # A tibble: 24 x 7 country continent year lifeExp pop gdpPercap pop_millions <fct> <fct> <int> <dbl> <int> <dbl> <dbl> 1 Australia Oceania 1952 69.1 8691212 10040. 8.69 2 Australia Oceania 1957 70.3 9712569 10950. 9.71 3 Australia Oceania 1962 70.9 10794968 12217. 10.8 4 Australia Oceania 1967 71.1 11872264 14526. 11.9 5 Australia Oceania 1972 71.9 13177000 16789. 13.2 6 Australia Oceania 1977 73.5 14074100 18334. 14.1 7 Australia Oceania 1982 74.7 15184200 19477. 15.2 8 Australia Oceania 1987 76.3 16257249 21889. 16.3 9 Australia Oceania 1992 77.6 17481977 23425. 17.5 10 Australia Oceania 1997 78.8 18565243 26998. 18.6 # … with 14 more rows ``` ] --- class: split-40 count: false .left-code-difference_ribbon-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) -> gm_oceania gm_oceania %>% * select(-gdpPercap, -lifeExp, - pop) ``` ] .right-output-difference_ribbon-auto[ ``` # A tibble: 24 x 4 country continent year pop_millions <fct> <fct> <int> <dbl> 1 Australia Oceania 1952 8.69 2 Australia Oceania 1957 9.71 3 Australia Oceania 1962 10.8 4 Australia Oceania 1967 11.9 5 Australia Oceania 1972 13.2 6 Australia Oceania 1977 14.1 7 Australia Oceania 1982 15.2 8 Australia Oceania 1987 16.3 9 Australia Oceania 1992 17.5 10 Australia Oceania 1997 18.6 # … with 14 more rows ``` ] --- class: split-40 count: false .left-code-difference_ribbon-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) -> gm_oceania gm_oceania %>% select(-gdpPercap, -lifeExp, - pop) %>% * pivot_wider(names_from = country, * values_from = pop_millions) ``` ] .right-output-difference_ribbon-auto[ ``` # A tibble: 12 x 4 continent year Australia `New Zealand` <fct> <int> <dbl> <dbl> 1 Oceania 1952 8.69 1.99 2 Oceania 1957 9.71 2.23 3 Oceania 1962 10.8 2.49 4 Oceania 1967 11.9 2.73 5 Oceania 1972 13.2 2.93 6 Oceania 1977 14.1 3.16 7 Oceania 1982 15.2 3.21 8 Oceania 1987 16.3 3.32 9 Oceania 1992 17.5 3.44 10 Oceania 1997 18.6 3.68 11 Oceania 2002 19.5 3.91 12 Oceania 2007 20.4 4.12 ``` ] --- class: split-40 count: false .left-code-difference_ribbon-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) -> gm_oceania gm_oceania %>% select(-gdpPercap, -lifeExp, - pop) %>% pivot_wider(names_from = country, values_from = pop_millions) -> *gm_oceania_pop_millions_wide ``` ] .right-output-difference_ribbon-auto[ ] --- class: split-40 count: false .left-code-difference_ribbon-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) -> gm_oceania gm_oceania %>% select(-gdpPercap, -lifeExp, - pop) %>% pivot_wider(names_from = country, values_from = pop_millions) -> gm_oceania_pop_millions_wide *gm_oceania # global data ``` ] .right-output-difference_ribbon-auto[ ``` # A tibble: 24 x 7 country continent year lifeExp pop gdpPercap pop_millions <fct> <fct> <int> <dbl> <int> <dbl> <dbl> 1 Australia Oceania 1952 69.1 8691212 10040. 8.69 2 Australia Oceania 1957 70.3 9712569 10950. 9.71 3 Australia Oceania 1962 70.9 10794968 12217. 10.8 4 Australia Oceania 1967 71.1 11872264 14526. 11.9 5 Australia Oceania 1972 71.9 13177000 16789. 13.2 6 Australia Oceania 1977 73.5 14074100 18334. 14.1 7 Australia Oceania 1982 74.7 15184200 19477. 15.2 8 Australia Oceania 1987 76.3 16257249 21889. 16.3 9 Australia Oceania 1992 77.6 17481977 23425. 17.5 10 Australia Oceania 1997 78.8 18565243 26998. 18.6 # … with 14 more rows ``` ] --- class: split-40 count: false .left-code-difference_ribbon-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) -> gm_oceania gm_oceania %>% select(-gdpPercap, -lifeExp, - pop) %>% pivot_wider(names_from = country, values_from = pop_millions) -> gm_oceania_pop_millions_wide gm_oceania %>% # global data * ggplot() ``` ] .right-output-difference_ribbon-auto[ <img src="geoms_multi_series_files/figure-html/difference_ribbon_auto_10_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-difference_ribbon-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) -> gm_oceania gm_oceania %>% select(-gdpPercap, -lifeExp, - pop) %>% pivot_wider(names_from = country, values_from = pop_millions) -> gm_oceania_pop_millions_wide gm_oceania %>% # global data ggplot() + * aes(x = year) ``` ] .right-output-difference_ribbon-auto[ <img src="geoms_multi_series_files/figure-html/difference_ribbon_auto_11_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-difference_ribbon-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) -> gm_oceania gm_oceania %>% select(-gdpPercap, -lifeExp, - pop) %>% pivot_wider(names_from = country, values_from = pop_millions) -> gm_oceania_pop_millions_wide gm_oceania %>% # global data ggplot() + aes(x = year) + * aes(y = pop_millions) ``` ] .right-output-difference_ribbon-auto[ <img src="geoms_multi_series_files/figure-html/difference_ribbon_auto_12_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-difference_ribbon-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) -> gm_oceania gm_oceania %>% select(-gdpPercap, -lifeExp, - pop) %>% pivot_wider(names_from = country, values_from = pop_millions) -> gm_oceania_pop_millions_wide gm_oceania %>% # global data ggplot() + aes(x = year) + aes(y = pop_millions) + * geom_line(aes(linetype = country), * color = "plum4") ``` ] .right-output-difference_ribbon-auto[ <img src="geoms_multi_series_files/figure-html/difference_ribbon_auto_13_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-difference_ribbon-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) -> gm_oceania gm_oceania %>% select(-gdpPercap, -lifeExp, - pop) %>% pivot_wider(names_from = country, values_from = pop_millions) -> gm_oceania_pop_millions_wide gm_oceania %>% # global data ggplot() + aes(x = year) + aes(y = pop_millions) + geom_line(aes(linetype = country), color = "plum4") + * geom_ribbon(data = gm_oceania_pop_millions_wide, # local data * aes(ymin = `New Zealand`, # poorly named var like this one has space * ymax = Australia, # must be surrounded by back ticks * y = NULL), # without this geom ribbon is wondering about y equals year * fill = "plum4", * alpha = .1) ``` ] .right-output-difference_ribbon-auto[ <img src="geoms_multi_series_files/figure-html/difference_ribbon_auto_14_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-difference_ribbon-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) -> gm_oceania gm_oceania %>% select(-gdpPercap, -lifeExp, - pop) %>% pivot_wider(names_from = country, values_from = pop_millions) -> gm_oceania_pop_millions_wide gm_oceania %>% # global data ggplot() + aes(x = year) + aes(y = pop_millions) + geom_line(aes(linetype = country), color = "plum4") + geom_ribbon(data = gm_oceania_pop_millions_wide, # local data aes(ymin = `New Zealand`, # poorly named var like this one has space ymax = Australia, # must be surrounded by back ticks y = NULL), # without this geom ribbon is wondering about y equals year fill = "plum4", alpha = .1) + * scale_y_continuous(limits = c(0, 22)) ``` ] .right-output-difference_ribbon-auto[ <img src="geoms_multi_series_files/figure-html/difference_ribbon_auto_15_output-1.png" width="100%" /> ] <style> .left-code-difference_ribbon-auto { color: #777; width: 49%; height: 92%; float: left; font-size: 80% } .right-output-difference_ribbon-auto { width: 50%; float: right; padding-left: 1%; } </style> --- class: split-40 count: false .left-code-growth-auto[ ```r *gapminder ``` ] .right-output-growth-auto[ ``` # A tibble: 1,704 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Afghanistan Asia 1952 28.8 8425333 779. 2 Afghanistan Asia 1957 30.3 9240934 821. 3 Afghanistan Asia 1962 32.0 10267083 853. 4 Afghanistan Asia 1967 34.0 11537966 836. 5 Afghanistan Asia 1972 36.1 13079460 740. 6 Afghanistan Asia 1977 38.4 14880372 786. 7 Afghanistan Asia 1982 39.9 12881816 978. 8 Afghanistan Asia 1987 40.8 13867957 852. 9 Afghanistan Asia 1992 41.7 16317921 649. 10 Afghanistan Asia 1997 41.8 22227415 635. # … with 1,694 more rows ``` ] --- class: split-40 count: false .left-code-growth-auto[ ```r gapminder %>% * filter(continent == "Europe") ``` ] .right-output-growth-auto[ ``` # A tibble: 360 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Albania Europe 1952 55.2 1282697 1601. 2 Albania Europe 1957 59.3 1476505 1942. 3 Albania Europe 1962 64.8 1728137 2313. 4 Albania Europe 1967 66.2 1984060 2760. 5 Albania Europe 1972 67.7 2263554 3313. 6 Albania Europe 1977 68.9 2509048 3533. 7 Albania Europe 1982 70.4 2780097 3631. 8 Albania Europe 1987 72 3075321 3739. 9 Albania Europe 1992 71.6 3326498 2497. 10 Albania Europe 1997 73.0 3428038 3193. # … with 350 more rows ``` ] --- class: split-40 count: false .left-code-growth-auto[ ```r gapminder %>% filter(continent == "Europe") %>% * filter(year %in% c(1972, 2002)) ``` ] .right-output-growth-auto[ ``` # A tibble: 60 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Albania Europe 1972 67.7 2263554 3313. 2 Albania Europe 2002 75.7 3508512 4604. 3 Austria Europe 1972 70.6 7544201 16662. 4 Austria Europe 2002 79.0 8148312 32418. 5 Belgium Europe 1972 71.4 9709100 16672. 6 Belgium Europe 2002 78.3 10311970 30486. 7 Bosnia and Herzegovina Europe 1972 67.4 3819000 2860. 8 Bosnia and Herzegovina Europe 2002 74.1 4165416 6019. 9 Bulgaria Europe 1972 70.9 8576200 6597. 10 Bulgaria Europe 2002 72.1 7661799 7697. # … with 50 more rows ``` ] --- class: split-40 count: false .left-code-growth-auto[ ```r gapminder %>% filter(continent == "Europe") %>% filter(year %in% c(1972, 2002)) %>% * mutate(country = reorder(country, lifeExp, mean)) ``` ] .right-output-growth-auto[ ``` # A tibble: 60 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Albania Europe 1972 67.7 2263554 3313. 2 Albania Europe 2002 75.7 3508512 4604. 3 Austria Europe 1972 70.6 7544201 16662. 4 Austria Europe 2002 79.0 8148312 32418. 5 Belgium Europe 1972 71.4 9709100 16672. 6 Belgium Europe 2002 78.3 10311970 30486. 7 Bosnia and Herzegovina Europe 1972 67.4 3819000 2860. 8 Bosnia and Herzegovina Europe 2002 74.1 4165416 6019. 9 Bulgaria Europe 1972 70.9 8576200 6597. 10 Bulgaria Europe 2002 72.1 7661799 7697. # … with 50 more rows ``` ] --- class: split-40 count: false .left-code-growth-auto[ ```r gapminder %>% filter(continent == "Europe") %>% filter(year %in% c(1972, 2002)) %>% mutate(country = reorder(country, lifeExp, mean)) -> *gap_72_02_europe ``` ] .right-output-growth-auto[ ] --- class: split-40 count: false .left-code-growth-auto[ ```r gapminder %>% filter(continent == "Europe") %>% filter(year %in% c(1972, 2002)) %>% mutate(country = reorder(country, lifeExp, mean)) -> gap_72_02_europe *gap_72_02_europe ``` ] .right-output-growth-auto[ ``` # A tibble: 60 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Albania Europe 1972 67.7 2263554 3313. 2 Albania Europe 2002 75.7 3508512 4604. 3 Austria Europe 1972 70.6 7544201 16662. 4 Austria Europe 2002 79.0 8148312 32418. 5 Belgium Europe 1972 71.4 9709100 16672. 6 Belgium Europe 2002 78.3 10311970 30486. 7 Bosnia and Herzegovina Europe 1972 67.4 3819000 2860. 8 Bosnia and Herzegovina Europe 2002 74.1 4165416 6019. 9 Bulgaria Europe 1972 70.9 8576200 6597. 10 Bulgaria Europe 2002 72.1 7661799 7697. # … with 50 more rows ``` ] --- class: split-40 count: false .left-code-growth-auto[ ```r gapminder %>% filter(continent == "Europe") %>% filter(year %in% c(1972, 2002)) %>% mutate(country = reorder(country, lifeExp, mean)) -> gap_72_02_europe gap_72_02_europe %>% * select(-gdpPercap, -pop) ``` ] .right-output-growth-auto[ ``` # A tibble: 60 x 4 country continent year lifeExp <fct> <fct> <int> <dbl> 1 Albania Europe 1972 67.7 2 Albania Europe 2002 75.7 3 Austria Europe 1972 70.6 4 Austria Europe 2002 79.0 5 Belgium Europe 1972 71.4 6 Belgium Europe 2002 78.3 7 Bosnia and Herzegovina Europe 1972 67.4 8 Bosnia and Herzegovina Europe 2002 74.1 9 Bulgaria Europe 1972 70.9 10 Bulgaria Europe 2002 72.1 # … with 50 more rows ``` ] --- class: split-40 count: false .left-code-growth-auto[ ```r gapminder %>% filter(continent == "Europe") %>% filter(year %in% c(1972, 2002)) %>% mutate(country = reorder(country, lifeExp, mean)) -> gap_72_02_europe gap_72_02_europe %>% select(-gdpPercap, -pop) %>% * pivot_wider(names_from = year, * values_from = lifeExp) ``` ] .right-output-growth-auto[ ``` # A tibble: 30 x 4 country continent `1972` `2002` <fct> <fct> <dbl> <dbl> 1 Albania Europe 67.7 75.7 2 Austria Europe 70.6 79.0 3 Belgium Europe 71.4 78.3 4 Bosnia and Herzegovina Europe 67.4 74.1 5 Bulgaria Europe 70.9 72.1 6 Croatia Europe 69.6 74.9 7 Czech Republic Europe 70.3 75.5 8 Denmark Europe 73.5 77.2 9 Finland Europe 70.9 78.4 10 France Europe 72.4 79.6 # … with 20 more rows ``` ] --- class: split-40 count: false .left-code-growth-auto[ ```r gapminder %>% filter(continent == "Europe") %>% filter(year %in% c(1972, 2002)) %>% mutate(country = reorder(country, lifeExp, mean)) -> gap_72_02_europe gap_72_02_europe %>% select(-gdpPercap, -pop) %>% pivot_wider(names_from = year, values_from = lifeExp) -> *gap_72_02_europe_wide ``` ] .right-output-growth-auto[ ] --- class: split-40 count: false .left-code-growth-auto[ ```r gapminder %>% filter(continent == "Europe") %>% filter(year %in% c(1972, 2002)) %>% mutate(country = reorder(country, lifeExp, mean)) -> gap_72_02_europe gap_72_02_europe %>% select(-gdpPercap, -pop) %>% pivot_wider(names_from = year, values_from = lifeExp) -> gap_72_02_europe_wide *ggplot(data = gap_72_02_europe) ``` ] .right-output-growth-auto[ <img src="geoms_multi_series_files/figure-html/growth_auto_10_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-growth-auto[ ```r gapminder %>% filter(continent == "Europe") %>% filter(year %in% c(1972, 2002)) %>% mutate(country = reorder(country, lifeExp, mean)) -> gap_72_02_europe gap_72_02_europe %>% select(-gdpPercap, -pop) %>% pivot_wider(names_from = year, values_from = lifeExp) -> gap_72_02_europe_wide ggplot(data = gap_72_02_europe) + * aes(x = lifeExp) ``` ] .right-output-growth-auto[ <img src="geoms_multi_series_files/figure-html/growth_auto_11_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-growth-auto[ ```r gapminder %>% filter(continent == "Europe") %>% filter(year %in% c(1972, 2002)) %>% mutate(country = reorder(country, lifeExp, mean)) -> gap_72_02_europe gap_72_02_europe %>% select(-gdpPercap, -pop) %>% pivot_wider(names_from = year, values_from = lifeExp) -> gap_72_02_europe_wide ggplot(data = gap_72_02_europe) + aes(x = lifeExp) + * aes(y = country) ``` ] .right-output-growth-auto[ <img src="geoms_multi_series_files/figure-html/growth_auto_12_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-growth-auto[ ```r gapminder %>% filter(continent == "Europe") %>% filter(year %in% c(1972, 2002)) %>% mutate(country = reorder(country, lifeExp, mean)) -> gap_72_02_europe gap_72_02_europe %>% select(-gdpPercap, -pop) %>% pivot_wider(names_from = year, values_from = lifeExp) -> gap_72_02_europe_wide ggplot(data = gap_72_02_europe) + aes(x = lifeExp) + aes(y = country) + * geom_point() ``` ] .right-output-growth-auto[ <img src="geoms_multi_series_files/figure-html/growth_auto_13_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-growth-auto[ ```r gapminder %>% filter(continent == "Europe") %>% filter(year %in% c(1972, 2002)) %>% mutate(country = reorder(country, lifeExp, mean)) -> gap_72_02_europe gap_72_02_europe %>% select(-gdpPercap, -pop) %>% pivot_wider(names_from = year, values_from = lifeExp) -> gap_72_02_europe_wide ggplot(data = gap_72_02_europe) + aes(x = lifeExp) + aes(y = country) + geom_point() + * aes(color = factor(year)) ``` ] .right-output-growth-auto[ <img src="geoms_multi_series_files/figure-html/growth_auto_14_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-growth-auto[ ```r gapminder %>% filter(continent == "Europe") %>% filter(year %in% c(1972, 2002)) %>% mutate(country = reorder(country, lifeExp, mean)) -> gap_72_02_europe gap_72_02_europe %>% select(-gdpPercap, -pop) %>% pivot_wider(names_from = year, values_from = lifeExp) -> gap_72_02_europe_wide ggplot(data = gap_72_02_europe) + aes(x = lifeExp) + aes(y = country) + geom_point() + aes(color = factor(year)) + * geom_segment(data = gap_72_02_europe_wide, # poorly named columns ie starting w number # need to be surrouned by backtick * aes(x = `1972`, * xend = `2002`, * yend = country), * color = "plum3", * size = 1.5) ``` ] .right-output-growth-auto[ <img src="geoms_multi_series_files/figure-html/growth_auto_15_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-growth-auto[ ```r gapminder %>% filter(continent == "Europe") %>% filter(year %in% c(1972, 2002)) %>% mutate(country = reorder(country, lifeExp, mean)) -> gap_72_02_europe gap_72_02_europe %>% select(-gdpPercap, -pop) %>% pivot_wider(names_from = year, values_from = lifeExp) -> gap_72_02_europe_wide ggplot(data = gap_72_02_europe) + aes(x = lifeExp) + aes(y = country) + geom_point() + aes(color = factor(year)) + geom_segment(data = gap_72_02_europe_wide, # poorly named columns ie starting w number # need to be surrouned by backtick aes(x = `1972`, xend = `2002`, yend = country), color = "plum3", size = 1.5) + # point layer above not really needed - just for showing logic * geom_point(size = 4) ``` ] .right-output-growth-auto[ <img src="geoms_multi_series_files/figure-html/growth_auto_16_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-growth-auto[ ```r gapminder %>% filter(continent == "Europe") %>% filter(year %in% c(1972, 2002)) %>% mutate(country = reorder(country, lifeExp, mean)) -> gap_72_02_europe gap_72_02_europe %>% select(-gdpPercap, -pop) %>% pivot_wider(names_from = year, values_from = lifeExp) -> gap_72_02_europe_wide ggplot(data = gap_72_02_europe) + aes(x = lifeExp) + aes(y = country) + geom_point() + aes(color = factor(year)) + geom_segment(data = gap_72_02_europe_wide, # poorly named columns ie starting w number # need to be surrouned by backtick aes(x = `1972`, xend = `2002`, yend = country), color = "plum3", size = 1.5) + # point layer above not really needed - just for showing logic geom_point(size = 4) + * scale_color_manual(values = c("plum3", "plum4")) ``` ] .right-output-growth-auto[ <img src="geoms_multi_series_files/figure-html/growth_auto_17_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-growth-auto[ ```r gapminder %>% filter(continent == "Europe") %>% filter(year %in% c(1972, 2002)) %>% mutate(country = reorder(country, lifeExp, mean)) -> gap_72_02_europe gap_72_02_europe %>% select(-gdpPercap, -pop) %>% pivot_wider(names_from = year, values_from = lifeExp) -> gap_72_02_europe_wide ggplot(data = gap_72_02_europe) + aes(x = lifeExp) + aes(y = country) + geom_point() + aes(color = factor(year)) + geom_segment(data = gap_72_02_europe_wide, # poorly named columns ie starting w number # need to be surrouned by backtick aes(x = `1972`, xend = `2002`, yend = country), color = "plum3", size = 1.5) + # point layer above not really needed - just for showing logic geom_point(size = 4) + scale_color_manual(values = c("plum3", "plum4")) + * theme(legend.position = c(.15,.85)) ``` ] .right-output-growth-auto[ <img src="geoms_multi_series_files/figure-html/growth_auto_18_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-growth-auto[ ```r gapminder %>% filter(continent == "Europe") %>% filter(year %in% c(1972, 2002)) %>% mutate(country = reorder(country, lifeExp, mean)) -> gap_72_02_europe gap_72_02_europe %>% select(-gdpPercap, -pop) %>% pivot_wider(names_from = year, values_from = lifeExp) -> gap_72_02_europe_wide ggplot(data = gap_72_02_europe) + aes(x = lifeExp) + aes(y = country) + geom_point() + aes(color = factor(year)) + geom_segment(data = gap_72_02_europe_wide, # poorly named columns ie starting w number # need to be surrouned by backtick aes(x = `1972`, xend = `2002`, yend = country), color = "plum3", size = 1.5) + # point layer above not really needed - just for showing logic geom_point(size = 4) + scale_color_manual(values = c("plum3", "plum4")) + theme(legend.position = c(.15,.85)) + * labs(color = NULL, y = NULL) ``` ] .right-output-growth-auto[ <img src="geoms_multi_series_files/figure-html/growth_auto_19_output-1.png" width="100%" /> ] <style> .left-code-growth-auto { color: #777; width: 49%; height: 92%; float: left; font-size: 80% } .right-output-growth-auto { width: 50%; float: right; padding-left: 1%; } </style> --- name: group ## The group aesthetic and geometric objects --- Using geom_line(), you can use many of the same aesthetics as before as well as one special aesthetic: `group`. > Lines and paths fall somewhere in between: each overall line is composed of a set of straight segments, but each segment represents two points. --- Hadley Wickham Group is like a declaration that instead of plotting the entire data set all together, instead you will plot many small data sets, each defined by the categorical variable "mapped" to `group`. Let's see how this works with the following example. --- name: many_series class: inverse, middle, center # Many series --- The geometric object `line` connects all points as it moves along the x axis. If a group is not defined, the geom_line is hard to interpret, as seen before group is added. We also see that mapping discrete data to the color or linetype aesthetics has a similar effect to declaring that there are groups in the data. Another thing we observe in the last addition to the last plot is adding an additional geometric layer. The point layer, because it follows the line layer, appears on top of the line layer. --- class: split-40 count: false .left-code-time_series_heat-auto[ ```r *gapminder ``` ] .right-output-time_series_heat-auto[ ``` # A tibble: 1,704 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Afghanistan Asia 1952 28.8 8425333 779. 2 Afghanistan Asia 1957 30.3 9240934 821. 3 Afghanistan Asia 1962 32.0 10267083 853. 4 Afghanistan Asia 1967 34.0 11537966 836. 5 Afghanistan Asia 1972 36.1 13079460 740. 6 Afghanistan Asia 1977 38.4 14880372 786. 7 Afghanistan Asia 1982 39.9 12881816 978. 8 Afghanistan Asia 1987 40.8 13867957 852. 9 Afghanistan Asia 1992 41.7 16317921 649. 10 Afghanistan Asia 1997 41.8 22227415 635. # … with 1,694 more rows ``` ] --- class: split-40 count: false .left-code-time_series_heat-auto[ ```r gapminder %>% * filter(continent == "Europe") ``` ] .right-output-time_series_heat-auto[ ``` # A tibble: 360 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Albania Europe 1952 55.2 1282697 1601. 2 Albania Europe 1957 59.3 1476505 1942. 3 Albania Europe 1962 64.8 1728137 2313. 4 Albania Europe 1967 66.2 1984060 2760. 5 Albania Europe 1972 67.7 2263554 3313. 6 Albania Europe 1977 68.9 2509048 3533. 7 Albania Europe 1982 70.4 2780097 3631. 8 Albania Europe 1987 72 3075321 3739. 9 Albania Europe 1992 71.6 3326498 2497. 10 Albania Europe 1997 73.0 3428038 3193. # … with 350 more rows ``` ] --- class: split-40 count: false .left-code-time_series_heat-auto[ ```r gapminder %>% filter(continent == "Europe") %>% * ggplot() ``` ] .right-output-time_series_heat-auto[ <img src="geoms_multi_series_files/figure-html/time_series_heat_auto_3_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_heat-auto[ ```r gapminder %>% filter(continent == "Europe") %>% ggplot() + * aes(x = factor(year)) ``` ] .right-output-time_series_heat-auto[ <img src="geoms_multi_series_files/figure-html/time_series_heat_auto_4_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_heat-auto[ ```r gapminder %>% filter(continent == "Europe") %>% ggplot() + aes(x = factor(year)) + * aes(y = country) ``` ] .right-output-time_series_heat-auto[ <img src="geoms_multi_series_files/figure-html/time_series_heat_auto_5_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_heat-auto[ ```r gapminder %>% filter(continent == "Europe") %>% ggplot() + aes(x = factor(year)) + aes(y = country) + * geom_tile(color = "grey80") ``` ] .right-output-time_series_heat-auto[ <img src="geoms_multi_series_files/figure-html/time_series_heat_auto_6_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_heat-auto[ ```r gapminder %>% filter(continent == "Europe") %>% ggplot() + aes(x = factor(year)) + aes(y = country) + geom_tile(color = "grey80") + * aes(fill = lifeExp) ``` ] .right-output-time_series_heat-auto[ <img src="geoms_multi_series_files/figure-html/time_series_heat_auto_7_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_heat-auto[ ```r gapminder %>% filter(continent == "Europe") %>% ggplot() + aes(x = factor(year)) + aes(y = country) + geom_tile(color = "grey80") + aes(fill = lifeExp) + * scale_fill_viridis_c(option = "magma") ``` ] .right-output-time_series_heat-auto[ <img src="geoms_multi_series_files/figure-html/time_series_heat_auto_8_output-1.png" width="100%" /> ] <style> .left-code-time_series_heat-auto { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-output-time_series_heat-auto { width: 60%; float: right; padding-left: 1%; } </style> --- class: split-40 count: false .left-code-polar_bar-auto[ ```r *gapminder ``` ] .right-output-polar_bar-auto[ ``` # A tibble: 1,704 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Afghanistan Asia 1952 28.8 8425333 779. 2 Afghanistan Asia 1957 30.3 9240934 821. 3 Afghanistan Asia 1962 32.0 10267083 853. 4 Afghanistan Asia 1967 34.0 11537966 836. 5 Afghanistan Asia 1972 36.1 13079460 740. 6 Afghanistan Asia 1977 38.4 14880372 786. 7 Afghanistan Asia 1982 39.9 12881816 978. 8 Afghanistan Asia 1987 40.8 13867957 852. 9 Afghanistan Asia 1992 41.7 16317921 649. 10 Afghanistan Asia 1997 41.8 22227415 635. # … with 1,694 more rows ``` ] --- class: split-40 count: false .left-code-polar_bar-auto[ ```r gapminder %>% * filter(continent == "Oceania") ``` ] .right-output-polar_bar-auto[ ``` # A tibble: 24 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Australia Oceania 1952 69.1 8691212 10040. 2 Australia Oceania 1957 70.3 9712569 10950. 3 Australia Oceania 1962 70.9 10794968 12217. 4 Australia Oceania 1967 71.1 11872264 14526. 5 Australia Oceania 1972 71.9 13177000 16789. 6 Australia Oceania 1977 73.5 14074100 18334. 7 Australia Oceania 1982 74.7 15184200 19477. 8 Australia Oceania 1987 76.3 16257249 21889. 9 Australia Oceania 1992 77.6 17481977 23425. 10 Australia Oceania 1997 78.8 18565243 26998. # … with 14 more rows ``` ] --- class: split-40 count: false .left-code-polar_bar-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% * mutate(pop_millions = pop/1000000) ``` ] .right-output-polar_bar-auto[ ``` # A tibble: 24 x 7 country continent year lifeExp pop gdpPercap pop_millions <fct> <fct> <int> <dbl> <int> <dbl> <dbl> 1 Australia Oceania 1952 69.1 8691212 10040. 8.69 2 Australia Oceania 1957 70.3 9712569 10950. 9.71 3 Australia Oceania 1962 70.9 10794968 12217. 10.8 4 Australia Oceania 1967 71.1 11872264 14526. 11.9 5 Australia Oceania 1972 71.9 13177000 16789. 13.2 6 Australia Oceania 1977 73.5 14074100 18334. 14.1 7 Australia Oceania 1982 74.7 15184200 19477. 15.2 8 Australia Oceania 1987 76.3 16257249 21889. 16.3 9 Australia Oceania 1992 77.6 17481977 23425. 17.5 10 Australia Oceania 1997 78.8 18565243 26998. 18.6 # … with 14 more rows ``` ] --- class: split-40 count: false .left-code-polar_bar-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) %>% * arrange(-pop) ``` ] .right-output-polar_bar-auto[ ``` # A tibble: 24 x 7 country continent year lifeExp pop gdpPercap pop_millions <fct> <fct> <int> <dbl> <int> <dbl> <dbl> 1 Australia Oceania 2007 81.2 20434176 34435. 20.4 2 Australia Oceania 2002 80.4 19546792 30688. 19.5 3 Australia Oceania 1997 78.8 18565243 26998. 18.6 4 Australia Oceania 1992 77.6 17481977 23425. 17.5 5 Australia Oceania 1987 76.3 16257249 21889. 16.3 6 Australia Oceania 1982 74.7 15184200 19477. 15.2 7 Australia Oceania 1977 73.5 14074100 18334. 14.1 8 Australia Oceania 1972 71.9 13177000 16789. 13.2 9 Australia Oceania 1967 71.1 11872264 14526. 11.9 10 Australia Oceania 1962 70.9 10794968 12217. 10.8 # … with 14 more rows ``` ] --- class: split-40 count: false .left-code-polar_bar-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) %>% arrange(-pop) %>% * ggplot() ``` ] .right-output-polar_bar-auto[ <img src="geoms_multi_series_files/figure-html/polar_bar_auto_5_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-polar_bar-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) %>% arrange(-pop) %>% ggplot() + * aes(x = year) ``` ] .right-output-polar_bar-auto[ <img src="geoms_multi_series_files/figure-html/polar_bar_auto_6_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-polar_bar-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) %>% arrange(-pop) %>% ggplot() + aes(x = year) + * aes(y = pop_millions) ``` ] .right-output-polar_bar-auto[ <img src="geoms_multi_series_files/figure-html/polar_bar_auto_7_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-polar_bar-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) %>% arrange(-pop) %>% ggplot() + aes(x = year) + aes(y = pop_millions) + * geom_col(width = 4, position = "dodge") ``` ] .right-output-polar_bar-auto[ <img src="geoms_multi_series_files/figure-html/polar_bar_auto_8_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-polar_bar-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) %>% arrange(-pop) %>% ggplot() + aes(x = year) + aes(y = pop_millions) + geom_col(width = 4, position = "dodge") + * coord_polar() ``` ] .right-output-polar_bar-auto[ <img src="geoms_multi_series_files/figure-html/polar_bar_auto_9_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-polar_bar-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) %>% arrange(-pop) %>% ggplot() + aes(x = year) + aes(y = pop_millions) + geom_col(width = 4, position = "dodge") + coord_polar() + * scale_y_continuous(limits = c(-10, 25)) ``` ] .right-output-polar_bar-auto[ <img src="geoms_multi_series_files/figure-html/polar_bar_auto_10_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-polar_bar-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) %>% arrange(-pop) %>% ggplot() + aes(x = year) + aes(y = pop_millions) + geom_col(width = 4, position = "dodge") + coord_polar() + scale_y_continuous(limits = c(-10, 25)) + * scale_x_continuous(breaks = seq(1952, 2007, by = 5), * limits = c(1950, 2010)) ``` ] .right-output-polar_bar-auto[ <img src="geoms_multi_series_files/figure-html/polar_bar_auto_11_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-polar_bar-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) %>% arrange(-pop) %>% ggplot() + aes(x = year) + aes(y = pop_millions) + geom_col(width = 4, position = "dodge") + coord_polar() + scale_y_continuous(limits = c(-10, 25)) + scale_x_continuous(breaks = seq(1952, 2007, by = 5), limits = c(1950, 2010)) + * aes(fill = country) ``` ] .right-output-polar_bar-auto[ <img src="geoms_multi_series_files/figure-html/polar_bar_auto_12_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-polar_bar-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) %>% arrange(-pop) %>% ggplot() + aes(x = year) + aes(y = pop_millions) + geom_col(width = 4, position = "dodge") + coord_polar() + scale_y_continuous(limits = c(-10, 25)) + scale_x_continuous(breaks = seq(1952, 2007, by = 5), limits = c(1950, 2010)) + aes(fill = country) + * geom_text(data = . %>% * filter(country == "Australia"), * aes(label = year, * y = pop_millions + 3), * fontface = "bold", * color = "navy") ``` ] .right-output-polar_bar-auto[ <img src="geoms_multi_series_files/figure-html/polar_bar_auto_13_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-polar_bar-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) %>% arrange(-pop) %>% ggplot() + aes(x = year) + aes(y = pop_millions) + geom_col(width = 4, position = "dodge") + coord_polar() + scale_y_continuous(limits = c(-10, 25)) + scale_x_continuous(breaks = seq(1952, 2007, by = 5), limits = c(1950, 2010)) + aes(fill = country) + geom_text(data = . %>% filter(country == "Australia"), aes(label = year, y = pop_millions + 3), fontface = "bold", color = "navy") + * theme_void() ``` ] .right-output-polar_bar-auto[ <img src="geoms_multi_series_files/figure-html/polar_bar_auto_14_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-polar_bar-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) %>% arrange(-pop) %>% ggplot() + aes(x = year) + aes(y = pop_millions) + geom_col(width = 4, position = "dodge") + coord_polar() + scale_y_continuous(limits = c(-10, 25)) + scale_x_continuous(breaks = seq(1952, 2007, by = 5), limits = c(1950, 2010)) + aes(fill = country) + geom_text(data = . %>% filter(country == "Australia"), aes(label = year, y = pop_millions + 3), fontface = "bold", color = "navy") + theme_void() + * theme(legend.position = c(.8,.8)) ``` ] .right-output-polar_bar-auto[ <img src="geoms_multi_series_files/figure-html/polar_bar_auto_15_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-polar_bar-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% mutate(pop_millions = pop/1000000) %>% arrange(-pop) %>% ggplot() + aes(x = year) + aes(y = pop_millions) + geom_col(width = 4, position = "dodge") + coord_polar() + scale_y_continuous(limits = c(-10, 25)) + scale_x_continuous(breaks = seq(1952, 2007, by = 5), limits = c(1950, 2010)) + aes(fill = country) + geom_text(data = . %>% filter(country == "Australia"), aes(label = year, y = pop_millions + 3), fontface = "bold", color = "navy") + theme_void() + theme(legend.position = c(.8,.8)) + * labs(fill = NULL) ``` ] .right-output-polar_bar-auto[ <img src="geoms_multi_series_files/figure-html/polar_bar_auto_16_output-1.png" width="100%" /> ] <style> .left-code-polar_bar-auto { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-output-polar_bar-auto { width: 60%; float: right; padding-left: 1%; } </style> --- # ranks of a series --- class: split-40 count: false .left-code-time_series_bump-auto[ ```r *gapminder ``` ] .right-output-time_series_bump-auto[ ``` # A tibble: 1,704 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Afghanistan Asia 1952 28.8 8425333 779. 2 Afghanistan Asia 1957 30.3 9240934 821. 3 Afghanistan Asia 1962 32.0 10267083 853. 4 Afghanistan Asia 1967 34.0 11537966 836. 5 Afghanistan Asia 1972 36.1 13079460 740. 6 Afghanistan Asia 1977 38.4 14880372 786. 7 Afghanistan Asia 1982 39.9 12881816 978. 8 Afghanistan Asia 1987 40.8 13867957 852. 9 Afghanistan Asia 1992 41.7 16317921 649. 10 Afghanistan Asia 1997 41.8 22227415 635. # … with 1,694 more rows ``` ] --- class: split-40 count: false .left-code-time_series_bump-auto[ ```r gapminder %>% * filter(country %in% c("Austria", "Belgium", * "Norway", "Netherlands", * "Spain", "Italy","France")) ``` ] .right-output-time_series_bump-auto[ ``` # A tibble: 84 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Austria Europe 1952 66.8 6927772 6137. 2 Austria Europe 1957 67.5 6965860 8843. 3 Austria Europe 1962 69.5 7129864 10751. 4 Austria Europe 1967 70.1 7376998 12835. 5 Austria Europe 1972 70.6 7544201 16662. 6 Austria Europe 1977 72.2 7568430 19749. 7 Austria Europe 1982 73.2 7574613 21597. 8 Austria Europe 1987 74.9 7578903 23688. 9 Austria Europe 1992 76.0 7914969 27042. 10 Austria Europe 1997 77.5 8069876 29096. # … with 74 more rows ``` ] --- class: split-40 count: false .left-code-time_series_bump-auto[ ```r gapminder %>% filter(country %in% c("Austria", "Belgium", "Norway", "Netherlands", "Spain", "Italy","France")) %>% * filter(year > 1980) ``` ] .right-output-time_series_bump-auto[ ``` # A tibble: 42 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Austria Europe 1982 73.2 7574613 21597. 2 Austria Europe 1987 74.9 7578903 23688. 3 Austria Europe 1992 76.0 7914969 27042. 4 Austria Europe 1997 77.5 8069876 29096. 5 Austria Europe 2002 79.0 8148312 32418. 6 Austria Europe 2007 79.8 8199783 36126. 7 Belgium Europe 1982 73.9 9856303 20980. 8 Belgium Europe 1987 75.4 9870200 22526. 9 Belgium Europe 1992 76.5 10045622 25576. 10 Belgium Europe 1997 77.5 10199787 27561. # … with 32 more rows ``` ] --- class: split-40 count: false .left-code-time_series_bump-auto[ ```r gapminder %>% filter(country %in% c("Austria", "Belgium", "Norway", "Netherlands", "Spain", "Italy","France")) %>% filter(year > 1980) %>% * group_by(year) ``` ] .right-output-time_series_bump-auto[ ``` # A tibble: 42 x 6 # Groups: year [6] country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Austria Europe 1982 73.2 7574613 21597. 2 Austria Europe 1987 74.9 7578903 23688. 3 Austria Europe 1992 76.0 7914969 27042. 4 Austria Europe 1997 77.5 8069876 29096. 5 Austria Europe 2002 79.0 8148312 32418. 6 Austria Europe 2007 79.8 8199783 36126. 7 Belgium Europe 1982 73.9 9856303 20980. 8 Belgium Europe 1987 75.4 9870200 22526. 9 Belgium Europe 1992 76.5 10045622 25576. 10 Belgium Europe 1997 77.5 10199787 27561. # … with 32 more rows ``` ] --- class: split-40 count: false .left-code-time_series_bump-auto[ ```r gapminder %>% filter(country %in% c("Austria", "Belgium", "Norway", "Netherlands", "Spain", "Italy","France")) %>% filter(year > 1980) %>% group_by(year) %>% * arrange(lifeExp) ``` ] .right-output-time_series_bump-auto[ ``` # A tibble: 42 x 6 # Groups: year [6] country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Austria Europe 1982 73.2 7574613 21597. 2 Belgium Europe 1982 73.9 9856303 20980. 3 France Europe 1982 74.9 54433565 20294. 4 Austria Europe 1987 74.9 7578903 23688. 5 Italy Europe 1982 75.0 56535636 16537. 6 Belgium Europe 1987 75.4 9870200 22526. 7 Norway Europe 1987 75.9 4186147 31541. 8 Norway Europe 1982 76.0 4114787 26299. 9 Austria Europe 1992 76.0 7914969 27042. 10 Netherlands Europe 1982 76.0 14310401 21399. # … with 32 more rows ``` ] --- class: split-40 count: false .left-code-time_series_bump-auto[ ```r gapminder %>% filter(country %in% c("Austria", "Belgium", "Norway", "Netherlands", "Spain", "Italy","France")) %>% filter(year > 1980) %>% group_by(year) %>% arrange(lifeExp) %>% * mutate(rank_life_exp = 1:n()) ``` ] .right-output-time_series_bump-auto[ ``` # A tibble: 42 x 7 # Groups: year [6] country continent year lifeExp pop gdpPercap rank_life_exp <fct> <fct> <int> <dbl> <int> <dbl> <int> 1 Austria Europe 1982 73.2 7574613 21597. 1 2 Belgium Europe 1982 73.9 9856303 20980. 2 3 France Europe 1982 74.9 54433565 20294. 3 4 Austria Europe 1987 74.9 7578903 23688. 1 5 Italy Europe 1982 75.0 56535636 16537. 4 6 Belgium Europe 1987 75.4 9870200 22526. 2 7 Norway Europe 1987 75.9 4186147 31541. 3 8 Norway Europe 1982 76.0 4114787 26299. 5 9 Austria Europe 1992 76.0 7914969 27042. 1 10 Netherlands Europe 1982 76.0 14310401 21399. 6 # … with 32 more rows ``` ] --- class: split-40 count: false .left-code-time_series_bump-auto[ ```r gapminder %>% filter(country %in% c("Austria", "Belgium", "Norway", "Netherlands", "Spain", "Italy","France")) %>% filter(year > 1980) %>% group_by(year) %>% arrange(lifeExp) %>% mutate(rank_life_exp = 1:n()) %>% * ungroup() ``` ] .right-output-time_series_bump-auto[ ``` # A tibble: 42 x 7 country continent year lifeExp pop gdpPercap rank_life_exp <fct> <fct> <int> <dbl> <int> <dbl> <int> 1 Austria Europe 1982 73.2 7574613 21597. 1 2 Belgium Europe 1982 73.9 9856303 20980. 2 3 France Europe 1982 74.9 54433565 20294. 3 4 Austria Europe 1987 74.9 7578903 23688. 1 5 Italy Europe 1982 75.0 56535636 16537. 4 6 Belgium Europe 1987 75.4 9870200 22526. 2 7 Norway Europe 1987 75.9 4186147 31541. 3 8 Norway Europe 1982 76.0 4114787 26299. 5 9 Austria Europe 1992 76.0 7914969 27042. 1 10 Netherlands Europe 1982 76.0 14310401 21399. 6 # … with 32 more rows ``` ] --- class: split-40 count: false .left-code-time_series_bump-auto[ ```r gapminder %>% filter(country %in% c("Austria", "Belgium", "Norway", "Netherlands", "Spain", "Italy","France")) %>% filter(year > 1980) %>% group_by(year) %>% arrange(lifeExp) %>% mutate(rank_life_exp = 1:n()) %>% ungroup() %>% * ggplot() ``` ] .right-output-time_series_bump-auto[ <img src="geoms_multi_series_files/figure-html/time_series_bump_auto_8_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_bump-auto[ ```r gapminder %>% filter(country %in% c("Austria", "Belgium", "Norway", "Netherlands", "Spain", "Italy","France")) %>% filter(year > 1980) %>% group_by(year) %>% arrange(lifeExp) %>% mutate(rank_life_exp = 1:n()) %>% ungroup() %>% ggplot() + * aes(x = year) ``` ] .right-output-time_series_bump-auto[ <img src="geoms_multi_series_files/figure-html/time_series_bump_auto_9_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_bump-auto[ ```r gapminder %>% filter(country %in% c("Austria", "Belgium", "Norway", "Netherlands", "Spain", "Italy","France")) %>% filter(year > 1980) %>% group_by(year) %>% arrange(lifeExp) %>% mutate(rank_life_exp = 1:n()) %>% ungroup() %>% ggplot() + aes(x = year) + * aes(y = rank_life_exp) ``` ] .right-output-time_series_bump-auto[ <img src="geoms_multi_series_files/figure-html/time_series_bump_auto_10_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_bump-auto[ ```r gapminder %>% filter(country %in% c("Austria", "Belgium", "Norway", "Netherlands", "Spain", "Italy","France")) %>% filter(year > 1980) %>% group_by(year) %>% arrange(lifeExp) %>% mutate(rank_life_exp = 1:n()) %>% ungroup() %>% ggplot() + aes(x = year) + aes(y = rank_life_exp) + * geom_point(size = 6) ``` ] .right-output-time_series_bump-auto[ <img src="geoms_multi_series_files/figure-html/time_series_bump_auto_11_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_bump-auto[ ```r gapminder %>% filter(country %in% c("Austria", "Belgium", "Norway", "Netherlands", "Spain", "Italy","France")) %>% filter(year > 1980) %>% group_by(year) %>% arrange(lifeExp) %>% mutate(rank_life_exp = 1:n()) %>% ungroup() %>% ggplot() + aes(x = year) + aes(y = rank_life_exp) + geom_point(size = 6) + * aes(color = country) ``` ] .right-output-time_series_bump-auto[ <img src="geoms_multi_series_files/figure-html/time_series_bump_auto_12_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_bump-auto[ ```r gapminder %>% filter(country %in% c("Austria", "Belgium", "Norway", "Netherlands", "Spain", "Italy","France")) %>% filter(year > 1980) %>% group_by(year) %>% arrange(lifeExp) %>% mutate(rank_life_exp = 1:n()) %>% ungroup() %>% ggplot() + aes(x = year) + aes(y = rank_life_exp) + geom_point(size = 6) + aes(color = country) + * ggbump::geom_bump(size = 2, smooth = 8) ``` ] .right-output-time_series_bump-auto[ <img src="geoms_multi_series_files/figure-html/time_series_bump_auto_13_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_bump-auto[ ```r gapminder %>% filter(country %in% c("Austria", "Belgium", "Norway", "Netherlands", "Spain", "Italy","France")) %>% filter(year > 1980) %>% group_by(year) %>% arrange(lifeExp) %>% mutate(rank_life_exp = 1:n()) %>% ungroup() %>% ggplot() + aes(x = year) + aes(y = rank_life_exp) + geom_point(size = 6) + aes(color = country) + ggbump::geom_bump(size = 2, smooth = 8) + * scale_x_continuous(limits = c(1970, 2020), * breaks = seq(1982, 2007, * by = 5)) ``` ] .right-output-time_series_bump-auto[ <img src="geoms_multi_series_files/figure-html/time_series_bump_auto_14_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_bump-auto[ ```r gapminder %>% filter(country %in% c("Austria", "Belgium", "Norway", "Netherlands", "Spain", "Italy","France")) %>% filter(year > 1980) %>% group_by(year) %>% arrange(lifeExp) %>% mutate(rank_life_exp = 1:n()) %>% ungroup() %>% ggplot() + aes(x = year) + aes(y = rank_life_exp) + geom_point(size = 6) + aes(color = country) + ggbump::geom_bump(size = 2, smooth = 8) + scale_x_continuous(limits = c(1970, 2020), breaks = seq(1982, 2007, by = 5)) + * geom_text(data = . %>% * filter(year == min(year)), * aes(x = year - 2.5, label = country), * size = 5, hjust = 1) ``` ] .right-output-time_series_bump-auto[ <img src="geoms_multi_series_files/figure-html/time_series_bump_auto_15_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_bump-auto[ ```r gapminder %>% filter(country %in% c("Austria", "Belgium", "Norway", "Netherlands", "Spain", "Italy","France")) %>% filter(year > 1980) %>% group_by(year) %>% arrange(lifeExp) %>% mutate(rank_life_exp = 1:n()) %>% ungroup() %>% ggplot() + aes(x = year) + aes(y = rank_life_exp) + geom_point(size = 6) + aes(color = country) + ggbump::geom_bump(size = 2, smooth = 8) + scale_x_continuous(limits = c(1970, 2020), breaks = seq(1982, 2007, by = 5)) + geom_text(data = . %>% filter(year == min(year)), aes(x = year - 2.5, label = country), size = 5, hjust = 1) + * geom_text(data = . %>% * filter(year == max(year)), * aes(x = year + 2.5, label = country), * size = 5, hjust = 0) ``` ] .right-output-time_series_bump-auto[ <img src="geoms_multi_series_files/figure-html/time_series_bump_auto_16_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_bump-auto[ ```r gapminder %>% filter(country %in% c("Austria", "Belgium", "Norway", "Netherlands", "Spain", "Italy","France")) %>% filter(year > 1980) %>% group_by(year) %>% arrange(lifeExp) %>% mutate(rank_life_exp = 1:n()) %>% ungroup() %>% ggplot() + aes(x = year) + aes(y = rank_life_exp) + geom_point(size = 6) + aes(color = country) + ggbump::geom_bump(size = 2, smooth = 8) + scale_x_continuous(limits = c(1970, 2020), breaks = seq(1982, 2007, by = 5)) + geom_text(data = . %>% filter(year == min(year)), aes(x = year - 2.5, label = country), size = 5, hjust = 1) + geom_text(data = . %>% filter(year == max(year)), aes(x = year + 2.5, label = country), size = 5, hjust = 0) + * scale_color_manual(values = paletteer::paletteer_d("basetheme::brutal", 7)) ``` ] .right-output-time_series_bump-auto[ <img src="geoms_multi_series_files/figure-html/time_series_bump_auto_17_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_bump-auto[ ```r gapminder %>% filter(country %in% c("Austria", "Belgium", "Norway", "Netherlands", "Spain", "Italy","France")) %>% filter(year > 1980) %>% group_by(year) %>% arrange(lifeExp) %>% mutate(rank_life_exp = 1:n()) %>% ungroup() %>% ggplot() + aes(x = year) + aes(y = rank_life_exp) + geom_point(size = 6) + aes(color = country) + ggbump::geom_bump(size = 2, smooth = 8) + scale_x_continuous(limits = c(1970, 2020), breaks = seq(1982, 2007, by = 5)) + geom_text(data = . %>% filter(year == min(year)), aes(x = year - 2.5, label = country), size = 5, hjust = 1) + geom_text(data = . %>% filter(year == max(year)), aes(x = year + 2.5, label = country), size = 5, hjust = 0) + scale_color_manual(values = paletteer::paletteer_d("basetheme::brutal", 7)) + * theme_minimal() ``` ] .right-output-time_series_bump-auto[ <img src="geoms_multi_series_files/figure-html/time_series_bump_auto_18_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-time_series_bump-auto[ ```r gapminder %>% filter(country %in% c("Austria", "Belgium", "Norway", "Netherlands", "Spain", "Italy","France")) %>% filter(year > 1980) %>% group_by(year) %>% arrange(lifeExp) %>% mutate(rank_life_exp = 1:n()) %>% ungroup() %>% ggplot() + aes(x = year) + aes(y = rank_life_exp) + geom_point(size = 6) + aes(color = country) + ggbump::geom_bump(size = 2, smooth = 8) + scale_x_continuous(limits = c(1970, 2020), breaks = seq(1982, 2007, by = 5)) + geom_text(data = . %>% filter(year == min(year)), aes(x = year - 2.5, label = country), size = 5, hjust = 1) + geom_text(data = . %>% filter(year == max(year)), aes(x = year + 2.5, label = country), size = 5, hjust = 0) + scale_color_manual(values = paletteer::paletteer_d("basetheme::brutal", 7)) + theme_minimal() + * theme(legend.position = "none") ``` ] .right-output-time_series_bump-auto[ <img src="geoms_multi_series_files/figure-html/time_series_bump_auto_19_output-1.png" width="100%" /> ] <style> .left-code-time_series_bump-auto { color: #777; width: 49%; height: 92%; float: left; font-size: 80% } .right-output-time_series_bump-auto { width: 50%; float: right; padding-left: 1%; } </style> --- class: split-40 count: false .left-code-time_series_bump_line-1[ ```r gapminder %>% filter(country %in% c("Austria", "Belgium", "Norway", "Netherlands", "Spain", "Italy","France")) %>% filter(year > 1980) %>% group_by(year) %>% arrange(lifeExp) %>% mutate(rank_life_exp = 1:n()) %>% ungroup() %>% ggplot() + aes(x = year) + aes(y = rank_life_exp) + aes(color = country) + * geom_line(size = 2, smooth = 8) + * geom_point(size = 6, shape = 21, fill = "white", stroke = 2) + scale_x_continuous(limits = c(1970, 2020), breaks = seq(1982, 2007, by = 5)) + geom_text(data = . %>% filter(year == min(year)), aes(x = year - 2.5, label = country), size = 5, hjust = 1) + geom_text(data = . %>% filter(year == max(year)), aes(x = year + 2.5, label = country), size = 5, hjust = 0) + scale_color_manual(values = paletteer::paletteer_d("basetheme::brutal", 7)) + theme_minimal() + theme(legend.position = "none") ``` ] .right-output-time_series_bump_line-1[ <img src="geoms_multi_series_files/figure-html/time_series_bump_line_1_1_output-1.png" width="100%" /> ] <style> .left-code-time_series_bump_line-1 { color: #777; width: 49%; height: 92%; float: left; font-size: 80% } .right-output-time_series_bump_line-1 { width: 50%; float: right; padding-left: 1%; } </style> --- class: split-40 count: false .left-code-slope_plot-auto[ ```r *gapminder ``` ] .right-output-slope_plot-auto[ ``` # A tibble: 1,704 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Afghanistan Asia 1952 28.8 8425333 779. 2 Afghanistan Asia 1957 30.3 9240934 821. 3 Afghanistan Asia 1962 32.0 10267083 853. 4 Afghanistan Asia 1967 34.0 11537966 836. 5 Afghanistan Asia 1972 36.1 13079460 740. 6 Afghanistan Asia 1977 38.4 14880372 786. 7 Afghanistan Asia 1982 39.9 12881816 978. 8 Afghanistan Asia 1987 40.8 13867957 852. 9 Afghanistan Asia 1992 41.7 16317921 649. 10 Afghanistan Asia 1997 41.8 22227415 635. # … with 1,694 more rows ``` ] --- class: split-40 count: false .left-code-slope_plot-auto[ ```r gapminder %>% * filter(country %in% c("Belgium", "Norway", "Spain")) ``` ] .right-output-slope_plot-auto[ ``` # A tibble: 36 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Belgium Europe 1952 68 8730405 8343. 2 Belgium Europe 1957 69.2 8989111 9715. 3 Belgium Europe 1962 70.2 9218400 10991. 4 Belgium Europe 1967 70.9 9556500 13149. 5 Belgium Europe 1972 71.4 9709100 16672. 6 Belgium Europe 1977 72.8 9821800 19118. 7 Belgium Europe 1982 73.9 9856303 20980. 8 Belgium Europe 1987 75.4 9870200 22526. 9 Belgium Europe 1992 76.5 10045622 25576. 10 Belgium Europe 1997 77.5 10199787 27561. # … with 26 more rows ``` ] --- class: split-40 count: false .left-code-slope_plot-auto[ ```r gapminder %>% filter(country %in% c("Belgium", "Norway", "Spain")) %>% * filter(year > 1990) ``` ] .right-output-slope_plot-auto[ ``` # A tibble: 12 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Belgium Europe 1992 76.5 10045622 25576. 2 Belgium Europe 1997 77.5 10199787 27561. 3 Belgium Europe 2002 78.3 10311970 30486. 4 Belgium Europe 2007 79.4 10392226 33693. 5 Norway Europe 1992 77.3 4286357 33966. 6 Norway Europe 1997 78.3 4405672 41283. 7 Norway Europe 2002 79.0 4535591 44684. 8 Norway Europe 2007 80.2 4627926 49357. 9 Spain Europe 1992 77.6 39549438 18603. 10 Spain Europe 1997 78.8 39855442 20445. 11 Spain Europe 2002 79.8 40152517 24835. 12 Spain Europe 2007 80.9 40448191 28821. ``` ] --- class: split-40 count: false .left-code-slope_plot-auto[ ```r gapminder %>% filter(country %in% c("Belgium", "Norway", "Spain")) %>% filter(year > 1990) %>% * ggplot() ``` ] .right-output-slope_plot-auto[ <img src="geoms_multi_series_files/figure-html/slope_plot_auto_4_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-slope_plot-auto[ ```r gapminder %>% filter(country %in% c("Belgium", "Norway", "Spain")) %>% filter(year > 1990) %>% ggplot() + * aes(x = year) ``` ] .right-output-slope_plot-auto[ <img src="geoms_multi_series_files/figure-html/slope_plot_auto_5_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-slope_plot-auto[ ```r gapminder %>% filter(country %in% c("Belgium", "Norway", "Spain")) %>% filter(year > 1990) %>% ggplot() + aes(x = year) + * aes(y = lifeExp) ``` ] .right-output-slope_plot-auto[ <img src="geoms_multi_series_files/figure-html/slope_plot_auto_6_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-slope_plot-auto[ ```r gapminder %>% filter(country %in% c("Belgium", "Norway", "Spain")) %>% filter(year > 1990) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + * aes(color = country) ``` ] .right-output-slope_plot-auto[ <img src="geoms_multi_series_files/figure-html/slope_plot_auto_7_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-slope_plot-auto[ ```r gapminder %>% filter(country %in% c("Belgium", "Norway", "Spain")) %>% filter(year > 1990) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + aes(color = country) + * geom_line(size = 2, smooth = 8) ``` ] .right-output-slope_plot-auto[ <img src="geoms_multi_series_files/figure-html/slope_plot_auto_8_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-slope_plot-auto[ ```r gapminder %>% filter(country %in% c("Belgium", "Norway", "Spain")) %>% filter(year > 1990) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + aes(color = country) + geom_line(size = 2, smooth = 8) + * geom_label(aes(label = round(lifeExp, 1)), * color = "darkgrey", stroke = "red", check_overlap = T) ``` ] .right-output-slope_plot-auto[ <img src="geoms_multi_series_files/figure-html/slope_plot_auto_9_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-slope_plot-auto[ ```r gapminder %>% filter(country %in% c("Belgium", "Norway", "Spain")) %>% filter(year > 1990) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + aes(color = country) + geom_line(size = 2, smooth = 8) + geom_label(aes(label = round(lifeExp, 1)), color = "darkgrey", stroke = "red", check_overlap = T) + * scale_x_continuous(limits = c(1985, 2012), breaks = seq(1992, 2007, by = 5)) ``` ] .right-output-slope_plot-auto[ <img src="geoms_multi_series_files/figure-html/slope_plot_auto_10_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-slope_plot-auto[ ```r gapminder %>% filter(country %in% c("Belgium", "Norway", "Spain")) %>% filter(year > 1990) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + aes(color = country) + geom_line(size = 2, smooth = 8) + geom_label(aes(label = round(lifeExp, 1)), color = "darkgrey", stroke = "red", check_overlap = T) + scale_x_continuous(limits = c(1985, 2012), breaks = seq(1992, 2007, by = 5)) + * geom_text(data = . %>% filter(year == min(year)), * aes(x = year - 1.5, label = country), * size = 5, hjust = 1) ``` ] .right-output-slope_plot-auto[ <img src="geoms_multi_series_files/figure-html/slope_plot_auto_11_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-slope_plot-auto[ ```r gapminder %>% filter(country %in% c("Belgium", "Norway", "Spain")) %>% filter(year > 1990) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + aes(color = country) + geom_line(size = 2, smooth = 8) + geom_label(aes(label = round(lifeExp, 1)), color = "darkgrey", stroke = "red", check_overlap = T) + scale_x_continuous(limits = c(1985, 2012), breaks = seq(1992, 2007, by = 5)) + geom_text(data = . %>% filter(year == min(year)), aes(x = year - 1.5, label = country), size = 5, hjust = 1) + * geom_text(data = . %>% filter(year == max(year)), * aes(x = year + 1.5, label = country), * size = 5, hjust = 0) ``` ] .right-output-slope_plot-auto[ <img src="geoms_multi_series_files/figure-html/slope_plot_auto_12_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-slope_plot-auto[ ```r gapminder %>% filter(country %in% c("Belgium", "Norway", "Spain")) %>% filter(year > 1990) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + aes(color = country) + geom_line(size = 2, smooth = 8) + geom_label(aes(label = round(lifeExp, 1)), color = "darkgrey", stroke = "red", check_overlap = T) + scale_x_continuous(limits = c(1985, 2012), breaks = seq(1992, 2007, by = 5)) + geom_text(data = . %>% filter(year == min(year)), aes(x = year - 1.5, label = country), size = 5, hjust = 1) + geom_text(data = . %>% filter(year == max(year)), aes(x = year + 1.5, label = country), size = 5, hjust = 0) + * scale_color_manual(values = paletteer::paletteer_d("basetheme::brutal", 7)) ``` ] .right-output-slope_plot-auto[ <img src="geoms_multi_series_files/figure-html/slope_plot_auto_13_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-slope_plot-auto[ ```r gapminder %>% filter(country %in% c("Belgium", "Norway", "Spain")) %>% filter(year > 1990) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + aes(color = country) + geom_line(size = 2, smooth = 8) + geom_label(aes(label = round(lifeExp, 1)), color = "darkgrey", stroke = "red", check_overlap = T) + scale_x_continuous(limits = c(1985, 2012), breaks = seq(1992, 2007, by = 5)) + geom_text(data = . %>% filter(year == min(year)), aes(x = year - 1.5, label = country), size = 5, hjust = 1) + geom_text(data = . %>% filter(year == max(year)), aes(x = year + 1.5, label = country), size = 5, hjust = 0) + scale_color_manual(values = paletteer::paletteer_d("basetheme::brutal", 7)) + * theme_minimal() ``` ] .right-output-slope_plot-auto[ <img src="geoms_multi_series_files/figure-html/slope_plot_auto_14_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-slope_plot-auto[ ```r gapminder %>% filter(country %in% c("Belgium", "Norway", "Spain")) %>% filter(year > 1990) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + aes(color = country) + geom_line(size = 2, smooth = 8) + geom_label(aes(label = round(lifeExp, 1)), color = "darkgrey", stroke = "red", check_overlap = T) + scale_x_continuous(limits = c(1985, 2012), breaks = seq(1992, 2007, by = 5)) + geom_text(data = . %>% filter(year == min(year)), aes(x = year - 1.5, label = country), size = 5, hjust = 1) + geom_text(data = . %>% filter(year == max(year)), aes(x = year + 1.5, label = country), size = 5, hjust = 0) + scale_color_manual(values = paletteer::paletteer_d("basetheme::brutal", 7)) + theme_minimal() + * theme(panel.grid.major.y = element_blank()) ``` ] .right-output-slope_plot-auto[ <img src="geoms_multi_series_files/figure-html/slope_plot_auto_15_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-slope_plot-auto[ ```r gapminder %>% filter(country %in% c("Belgium", "Norway", "Spain")) %>% filter(year > 1990) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + aes(color = country) + geom_line(size = 2, smooth = 8) + geom_label(aes(label = round(lifeExp, 1)), color = "darkgrey", stroke = "red", check_overlap = T) + scale_x_continuous(limits = c(1985, 2012), breaks = seq(1992, 2007, by = 5)) + geom_text(data = . %>% filter(year == min(year)), aes(x = year - 1.5, label = country), size = 5, hjust = 1) + geom_text(data = . %>% filter(year == max(year)), aes(x = year + 1.5, label = country), size = 5, hjust = 0) + scale_color_manual(values = paletteer::paletteer_d("basetheme::brutal", 7)) + theme_minimal() + theme(panel.grid.major.y = element_blank()) + * theme(panel.grid.minor.y = element_blank()) ``` ] .right-output-slope_plot-auto[ <img src="geoms_multi_series_files/figure-html/slope_plot_auto_16_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-slope_plot-auto[ ```r gapminder %>% filter(country %in% c("Belgium", "Norway", "Spain")) %>% filter(year > 1990) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + aes(color = country) + geom_line(size = 2, smooth = 8) + geom_label(aes(label = round(lifeExp, 1)), color = "darkgrey", stroke = "red", check_overlap = T) + scale_x_continuous(limits = c(1985, 2012), breaks = seq(1992, 2007, by = 5)) + geom_text(data = . %>% filter(year == min(year)), aes(x = year - 1.5, label = country), size = 5, hjust = 1) + geom_text(data = . %>% filter(year == max(year)), aes(x = year + 1.5, label = country), size = 5, hjust = 0) + scale_color_manual(values = paletteer::paletteer_d("basetheme::brutal", 7)) + theme_minimal() + theme(panel.grid.major.y = element_blank()) + theme(panel.grid.minor.y = element_blank()) + * theme(panel.grid.minor.x = element_blank()) ``` ] .right-output-slope_plot-auto[ <img src="geoms_multi_series_files/figure-html/slope_plot_auto_17_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-slope_plot-auto[ ```r gapminder %>% filter(country %in% c("Belgium", "Norway", "Spain")) %>% filter(year > 1990) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + aes(color = country) + geom_line(size = 2, smooth = 8) + geom_label(aes(label = round(lifeExp, 1)), color = "darkgrey", stroke = "red", check_overlap = T) + scale_x_continuous(limits = c(1985, 2012), breaks = seq(1992, 2007, by = 5)) + geom_text(data = . %>% filter(year == min(year)), aes(x = year - 1.5, label = country), size = 5, hjust = 1) + geom_text(data = . %>% filter(year == max(year)), aes(x = year + 1.5, label = country), size = 5, hjust = 0) + scale_color_manual(values = paletteer::paletteer_d("basetheme::brutal", 7)) + theme_minimal() + theme(panel.grid.major.y = element_blank()) + theme(panel.grid.minor.y = element_blank()) + theme(panel.grid.minor.x = element_blank()) + * theme(panel.grid.major.x = element_blank()) ``` ] .right-output-slope_plot-auto[ <img src="geoms_multi_series_files/figure-html/slope_plot_auto_18_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-slope_plot-auto[ ```r gapminder %>% filter(country %in% c("Belgium", "Norway", "Spain")) %>% filter(year > 1990) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + aes(color = country) + geom_line(size = 2, smooth = 8) + geom_label(aes(label = round(lifeExp, 1)), color = "darkgrey", stroke = "red", check_overlap = T) + scale_x_continuous(limits = c(1985, 2012), breaks = seq(1992, 2007, by = 5)) + geom_text(data = . %>% filter(year == min(year)), aes(x = year - 1.5, label = country), size = 5, hjust = 1) + geom_text(data = . %>% filter(year == max(year)), aes(x = year + 1.5, label = country), size = 5, hjust = 0) + scale_color_manual(values = paletteer::paletteer_d("basetheme::brutal", 7)) + theme_minimal() + theme(panel.grid.major.y = element_blank()) + theme(panel.grid.minor.y = element_blank()) + theme(panel.grid.minor.x = element_blank()) + theme(panel.grid.major.x = element_blank()) + * theme(axis.text.y = element_blank()) ``` ] .right-output-slope_plot-auto[ <img src="geoms_multi_series_files/figure-html/slope_plot_auto_19_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-slope_plot-auto[ ```r gapminder %>% filter(country %in% c("Belgium", "Norway", "Spain")) %>% filter(year > 1990) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + aes(color = country) + geom_line(size = 2, smooth = 8) + geom_label(aes(label = round(lifeExp, 1)), color = "darkgrey", stroke = "red", check_overlap = T) + scale_x_continuous(limits = c(1985, 2012), breaks = seq(1992, 2007, by = 5)) + geom_text(data = . %>% filter(year == min(year)), aes(x = year - 1.5, label = country), size = 5, hjust = 1) + geom_text(data = . %>% filter(year == max(year)), aes(x = year + 1.5, label = country), size = 5, hjust = 0) + scale_color_manual(values = paletteer::paletteer_d("basetheme::brutal", 7)) + theme_minimal() + theme(panel.grid.major.y = element_blank()) + theme(panel.grid.minor.y = element_blank()) + theme(panel.grid.minor.x = element_blank()) + theme(panel.grid.major.x = element_blank()) + theme(axis.text.y = element_blank()) + * theme(axis.ticks.y = element_blank()) ``` ] .right-output-slope_plot-auto[ <img src="geoms_multi_series_files/figure-html/slope_plot_auto_20_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-slope_plot-auto[ ```r gapminder %>% filter(country %in% c("Belgium", "Norway", "Spain")) %>% filter(year > 1990) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + aes(color = country) + geom_line(size = 2, smooth = 8) + geom_label(aes(label = round(lifeExp, 1)), color = "darkgrey", stroke = "red", check_overlap = T) + scale_x_continuous(limits = c(1985, 2012), breaks = seq(1992, 2007, by = 5)) + geom_text(data = . %>% filter(year == min(year)), aes(x = year - 1.5, label = country), size = 5, hjust = 1) + geom_text(data = . %>% filter(year == max(year)), aes(x = year + 1.5, label = country), size = 5, hjust = 0) + scale_color_manual(values = paletteer::paletteer_d("basetheme::brutal", 7)) + theme_minimal() + theme(panel.grid.major.y = element_blank()) + theme(panel.grid.minor.y = element_blank()) + theme(panel.grid.minor.x = element_blank()) + theme(panel.grid.major.x = element_blank()) + theme(axis.text.y = element_blank()) + theme(axis.ticks.y = element_blank()) + * theme(legend.position = "none") ``` ] .right-output-slope_plot-auto[ <img src="geoms_multi_series_files/figure-html/slope_plot_auto_21_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-slope_plot-auto[ ```r gapminder %>% filter(country %in% c("Belgium", "Norway", "Spain")) %>% filter(year > 1990) %>% ggplot() + aes(x = year) + aes(y = lifeExp) + aes(color = country) + geom_line(size = 2, smooth = 8) + geom_label(aes(label = round(lifeExp, 1)), color = "darkgrey", stroke = "red", check_overlap = T) + scale_x_continuous(limits = c(1985, 2012), breaks = seq(1992, 2007, by = 5)) + geom_text(data = . %>% filter(year == min(year)), aes(x = year - 1.5, label = country), size = 5, hjust = 1) + geom_text(data = . %>% filter(year == max(year)), aes(x = year + 1.5, label = country), size = 5, hjust = 0) + scale_color_manual(values = paletteer::paletteer_d("basetheme::brutal", 7)) + theme_minimal() + theme(panel.grid.major.y = element_blank()) + theme(panel.grid.minor.y = element_blank()) + theme(panel.grid.minor.x = element_blank()) + theme(panel.grid.major.x = element_blank()) + theme(axis.text.y = element_blank()) + theme(axis.ticks.y = element_blank()) + theme(legend.position = "none") + * labs(x = NULL, y = NULL) ``` ] .right-output-slope_plot-auto[ <img src="geoms_multi_series_files/figure-html/slope_plot_auto_22_output-1.png" width="100%" /> ] <style> .left-code-slope_plot-auto { color: #777; width: 60%; height: 92%; float: left; font-size: 80% } .right-output-slope_plot-auto { width: 39%; float: right; padding-left: 1%; } </style> --- class: split-40 count: false .left-code-waffle-auto[ ```r *gapminder ``` ] .right-output-waffle-auto[ ``` # A tibble: 1,704 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Afghanistan Asia 1952 28.8 8425333 779. 2 Afghanistan Asia 1957 30.3 9240934 821. 3 Afghanistan Asia 1962 32.0 10267083 853. 4 Afghanistan Asia 1967 34.0 11537966 836. 5 Afghanistan Asia 1972 36.1 13079460 740. 6 Afghanistan Asia 1977 38.4 14880372 786. 7 Afghanistan Asia 1982 39.9 12881816 978. 8 Afghanistan Asia 1987 40.8 13867957 852. 9 Afghanistan Asia 1992 41.7 16317921 649. 10 Afghanistan Asia 1997 41.8 22227415 635. # … with 1,694 more rows ``` ] --- class: split-40 count: false .left-code-waffle-auto[ ```r gapminder %>% * filter(continent == "Oceania") ``` ] .right-output-waffle-auto[ ``` # A tibble: 24 x 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Australia Oceania 1952 69.1 8691212 10040. 2 Australia Oceania 1957 70.3 9712569 10950. 3 Australia Oceania 1962 70.9 10794968 12217. 4 Australia Oceania 1967 71.1 11872264 14526. 5 Australia Oceania 1972 71.9 13177000 16789. 6 Australia Oceania 1977 73.5 14074100 18334. 7 Australia Oceania 1982 74.7 15184200 19477. 8 Australia Oceania 1987 76.3 16257249 21889. 9 Australia Oceania 1992 77.6 17481977 23425. 10 Australia Oceania 1997 78.8 18565243 26998. # … with 14 more rows ``` ] --- class: split-40 count: false .left-code-waffle-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% * ggplot() ``` ] .right-output-waffle-auto[ <img src="geoms_multi_series_files/figure-html/waffle_auto_3_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-waffle-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% ggplot() + * waffle::geom_waffle(aes(values = pop/1000000, * fill = country), * color = "white", * size = .25, * n_rows = 3, flip = T) ``` ] .right-output-waffle-auto[ <img src="geoms_multi_series_files/figure-html/waffle_auto_4_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-waffle-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% ggplot() + waffle::geom_waffle(aes(values = pop/1000000, fill = country), color = "white", size = .25, n_rows = 3, flip = T) + * coord_equal() ``` ] .right-output-waffle-auto[ <img src="geoms_multi_series_files/figure-html/waffle_auto_5_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-waffle-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% ggplot() + waffle::geom_waffle(aes(values = pop/1000000, fill = country), color = "white", size = .25, n_rows = 3, flip = T) + coord_equal() + * facet_wrap(~ year, nrow = 1, strip.position = "bottom") ``` ] .right-output-waffle-auto[ <img src="geoms_multi_series_files/figure-html/waffle_auto_6_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-waffle-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% ggplot() + waffle::geom_waffle(aes(values = pop/1000000, fill = country), color = "white", size = .25, n_rows = 3, flip = T) + coord_equal() + facet_wrap(~ year, nrow = 1, strip.position = "bottom") + * theme_void() ``` ] .right-output-waffle-auto[ <img src="geoms_multi_series_files/figure-html/waffle_auto_7_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-waffle-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% ggplot() + waffle::geom_waffle(aes(values = pop/1000000, fill = country), color = "white", size = .25, n_rows = 3, flip = T) + coord_equal() + facet_wrap(~ year, nrow = 1, strip.position = "bottom") + theme_void() + * labs(title = "Population (millions)") ``` ] .right-output-waffle-auto[ <img src="geoms_multi_series_files/figure-html/waffle_auto_8_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-waffle-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% ggplot() + waffle::geom_waffle(aes(values = pop/1000000, fill = country), color = "white", size = .25, n_rows = 3, flip = T) + coord_equal() + facet_wrap(~ year, nrow = 1, strip.position = "bottom") + theme_void() + labs(title = "Population (millions)") + * labs(fill = NULL) ``` ] .right-output-waffle-auto[ <img src="geoms_multi_series_files/figure-html/waffle_auto_9_output-1.png" width="100%" /> ] --- class: split-40 count: false .left-code-waffle-auto[ ```r gapminder %>% filter(continent == "Oceania") %>% ggplot() + waffle::geom_waffle(aes(values = pop/1000000, fill = country), color = "white", size = .25, n_rows = 3, flip = T) + coord_equal() + facet_wrap(~ year, nrow = 1, strip.position = "bottom") + theme_void() + labs(title = "Population (millions)") + labs(fill = NULL) + * theme(legend.position = "bottom") ``` ] .right-output-waffle-auto[ <img src="geoms_multi_series_files/figure-html/waffle_auto_10_output-1.png" width="100%" /> ] <style> .left-code-waffle-auto { color: #777; width: 60%; height: 92%; float: left; font-size: 80% } .right-output-waffle-auto { width: 39%; float: right; padding-left: 1%; } </style> --- [Racing bar chart](https://evamaerey.github.io/flipbooks/racing_bars/racing_barcharts.html#34) is concerned with ranks and values. --- <!-- --- --> <!-- class: middle, center, inverse --> <!-- # geom stats --> <!-- -- --> <!-- ### identity --> <!-- -- --> <!-- ### count --> <!-- --- --> <!-- ```{r stat, include=F} --> <!-- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-03-03/game_goals.csv') -> --> <!-- game_goals --> <!-- game_goals %>% --> <!-- count(season) %>% --> <!-- full_join(tibble(season = 1980:2020)) %>% --> <!-- ggplot() + --> <!-- aes(x = season) + --> <!-- aes(y = n) + --> <!-- geom_col() + # stat is identity --> <!-- geom_point() + # stat is identity --> <!-- geom_line() + # stat is identity --> <!-- geom_area(alpha = .2, # stat is identity --> <!-- fill = "magenta") + --> <!-- aes(fill = season) + --> <!-- aes(xend = season) + --> <!-- aes(yend = 0) + --> <!-- geom_segment(linetype = "dotted") -> --> <!-- you_aggregate_then_plot --> <!-- game_goals %>% --> <!-- ggplot() + --> <!-- aes(x = season) + --> <!-- geom_bar() + # a version of geom column --> <!-- geom_point(stat = "count") + --> <!-- geom_line(stat = "count") + --> <!-- geom_area(stat = "count", --> <!-- alpha = .2, --> <!-- fill = "magenta") + --> <!-- aes(fill = season) -> # not completely grasping why fill cant work here --> <!-- ggplot_aggregates_for_you --> <!-- ``` --> <!-- --- --> <!-- ```{r bar_discrete_continuous, include = F} --> <!-- tibble(my_var = c(1, 2.5, 2.5, 2.5, --> <!-- 7, 7.25, 7.25)) %>% --> <!-- ggplot() + --> <!-- aes(x = my_var) + --> <!-- geom_bar(fill = "blue", # default is --> <!-- alpha = .5, # widths adjusted so --> <!-- linetype = "dotted") + # no overlap --> <!-- geom_bar(alpha = .5, --> <!-- width = .6, #setting width --> <!-- fill = "orange") + --> <!-- # replacing previous aes x statement --> <!-- # each category take up horizontal space of 1 --> <!-- aes(x = as_factor(my_var)) --> <!-- ``` --> <!-- ## radar chart --> <!-- ```{r} --> <!-- gapminder %>% --> <!-- filter(continent == "Oceania") %>% --> <!-- select(year, country, gdpPercap) %>% --> <!-- group_by(country) %>% --> <!-- mutate(row = row_number()) %>% --> <!-- mutate(dist = row/n()) %>% --> <!-- mutate(y_pos = gdpPercap*sin(2*pi*dist)) %>% --> <!-- mutate(x_pos = gdpPercap*cos(2*pi*dist)) -> --> <!-- prep --> <!-- tibble(y = (1:8 * 4000)) %>% --> <!-- crossing(x = 1:12) %>% --> <!-- group_by(y) %>% --> <!-- mutate(row = row_number()) %>% --> <!-- mutate(dist = row/n()) %>% --> <!-- mutate(y_pos = y*sin(2*pi*dist)) %>% --> <!-- mutate(x_pos = y*cos(2*pi*dist)) %>% --> <!-- ggplot() + --> <!-- aes(group = y) + --> <!-- aes(x = x_pos) + --> <!-- aes(y = y_pos) + --> <!-- geom_path() + --> <!-- geom_path(data = prep, aes(group = country), --> <!-- color = "purple", --> <!-- size = 4) --> <!-- options(scipen = 30) --> <!-- sin(pi*2*(1:6)/6) --> <!-- ``` --> <style type="text/css"> .remark-code{line-height: 1.5; font-size: 55%} </style>