class: inverse, left, bottom background-image: url(https://images.unsplash.com/photo-1543286386-713bdd548da4?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80) background-size: cover # .Large[ma206data Lesson 3] ## .small[Data Wrangling and Tidyverse Tutorial] #### .tiny[Dr. Evangeline Reynolds | 2022-08-18 |Image credit: William Iven, Upsplash] ??? --- # Warm-up -- ```r pressure ``` ``` ## temperature pressure ## 1 0 0.0002 ## 2 20 0.0012 ## 3 40 0.0060 ## 4 60 0.0300 ## 5 80 0.0900 ## 6 100 0.2700 ## 7 120 0.7500 ## 8 140 1.8500 ## 9 160 4.2000 ## 10 180 8.8000 ## 11 200 17.3000 ## 12 220 32.1000 ## 13 240 57.0000 ## 14 260 96.0000 ## 15 280 157.0000 ## 16 300 247.0000 ## 17 320 376.0000 ## 18 340 558.0000 ## 19 360 806.0000 ``` --- ### try out more geoms (more than one in a chart works) - #### geom_point() - #### geom_col() - #### geom_tile() -- ### use one of the pressure variables (temperature or pressure) instead of 'var_name' to explore a few more visual channels that can represent variables: - #### aes(alpha = var_name) - #### aes(fill = var_name) vs aes(color = var_name) -- ## Check how your neighbor is doing. --- # Attendance question -- ## What's your favorite data viz/analysis tool up to this point? (pen and paper, excel?, something else?) -- ## 'Bonus': What company, w/ data viz production based on 'the grammar of graphics' was bought for 15.7 billion dollars. -- # Add myself... --- # The "Grammar of Graphics" (1999) <img src="images/wilkinson_grammar_of_graphics.png" width="40%" /> --- ![](images/paste-99474543.png) Third wave data visualization, Meeks: https://www.youtube.com/watch?v=itChfcTx7aos --- # A data visualization is made up of ... -- ### .left[... geometric objects ...] -- ### .center[...that take on aesthetics (color, line width, x-position) ...] -- ### .center[...which represent variables ...] -- ### .right[...from a dataset (dataframe)] --- ## Elements of the Grammar of Graphics (choices) <img src="images/wilkinson_layers_grammar_of_graphics.png" width="957" /> --- <style type="text/css"> .remark-code{line-height: 1.5; font-size: 70%} @media print { .has-continuation { display: block; } } code.r.hljs.remark-code{ position: relative; overflow-x: hidden; } code.r.hljs.remark-code:hover{ overflow-x:visible; width: 500px; border-style: solid; } </style> --- | function | action | | --- | --- | | filter() | keep rows (if true) | | select() | keep variables (or drop them -var) | | mutate() | create a new variable | | case_when() | is used for “recoding” variable, often used with mutate() | | rename() | renaming variables | | arrange() | order rows based on a variable | | slice() | *keep or drop rows based on row number | --- <img src="lesson_03_data_wrangling_simulation_files/figure-html/wrangle-1.png" width="80%" /> --- class: inverse, center, middle # What manipulation is required? --- ```r # Original, full dataset library(gapminder) gapminder %>% filter(continent == "Europe") ``` ``` # A tibble: 360 × 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. 11 Albania Europe 2002 75.7 3508512 4604. 12 Albania Europe 2007 76.4 3600523 5937. 13 Austria Europe 1952 66.8 6927772 6137. 14 Austria Europe 1957 67.5 6965860 8843. 15 Austria Europe 1962 69.5 7129864 10751. 16 Austria Europe 1967 70.1 7376998 12835. 17 Austria Europe 1972 70.6 7544201 16662. 18 Austria Europe 1977 72.2 7568430 19749. 19 Austria Europe 1982 73.2 7574613 21597. 20 Austria Europe 1987 74.9 7578903 23688. 21 Austria Europe 1992 76.0 7914969 27042. 22 Austria Europe 1997 77.5 8069876 29096. 23 Austria Europe 2002 79.0 8148312 32418. 24 Austria Europe 2007 79.8 8199783 36126. 25 Belgium Europe 1952 68 8730405 8343. 26 Belgium Europe 1957 69.2 8989111 9715. 27 Belgium Europe 1962 70.2 9218400 10991. 28 Belgium Europe 1967 70.9 9556500 13149. 29 Belgium Europe 1972 71.4 9709100 16672. 30 Belgium Europe 1977 72.8 9821800 19118. 31 Belgium Europe 1982 73.9 9856303 20980. 32 Belgium Europe 1987 75.4 9870200 22526. 33 Belgium Europe 1992 76.5 10045622 25576. 34 Belgium Europe 1997 77.5 10199787 27561. 35 Belgium Europe 2002 78.3 10311970 30486. 36 Belgium Europe 2007 79.4 10392226 33693. 37 Bosnia and Herzegovina Europe 1952 53.8 2791000 974. 38 Bosnia and Herzegovina Europe 1957 58.4 3076000 1354. 39 Bosnia and Herzegovina Europe 1962 61.9 3349000 1710. 40 Bosnia and Herzegovina Europe 1967 64.8 3585000 2172. 41 Bosnia and Herzegovina Europe 1972 67.4 3819000 2860. 42 Bosnia and Herzegovina Europe 1977 69.9 4086000 3528. 43 Bosnia and Herzegovina Europe 1982 70.7 4172693 4127. 44 Bosnia and Herzegovina Europe 1987 71.1 4338977 4314. 45 Bosnia and Herzegovina Europe 1992 72.2 4256013 2547. 46 Bosnia and Herzegovina Europe 1997 73.2 3607000 4766. 47 Bosnia and Herzegovina Europe 2002 74.1 4165416 6019. 48 Bosnia and Herzegovina Europe 2007 74.9 4552198 7446. 49 Bulgaria Europe 1952 59.6 7274900 2444. 50 Bulgaria Europe 1957 66.6 7651254 3009. 51 Bulgaria Europe 1962 69.5 8012946 4254. 52 Bulgaria Europe 1967 70.4 8310226 5577. 53 Bulgaria Europe 1972 70.9 8576200 6597. 54 Bulgaria Europe 1977 70.8 8797022 7612. 55 Bulgaria Europe 1982 71.1 8892098 8224. # … with 305 more rows ``` --- count: false --- count: false --- count: false ``` # A tibble: 1,704 × 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. 11 Afghanistan Asia 2002 42.1 25268405 727. 12 Afghanistan Asia 2007 43.8 31889923 975. 13 Albania Europe 1952 55.2 1282697 1601. 14 Albania Europe 1957 59.3 1476505 1942. 15 Albania Europe 1962 64.8 1728137 2313. 16 Albania Europe 1967 66.2 1984060 2760. 17 Albania Europe 1972 67.7 2263554 3313. 18 Albania Europe 1977 68.9 2509048 3533. 19 Albania Europe 1982 70.4 2780097 3631. 20 Albania Europe 1987 72 3075321 3739. 21 Albania Europe 1992 71.6 3326498 2497. 22 Albania Europe 1997 73.0 3428038 3193. 23 Albania Europe 2002 75.7 3508512 4604. 24 Albania Europe 2007 76.4 3600523 5937. 25 Algeria Africa 1952 43.1 9279525 2449. 26 Algeria Africa 1957 45.7 10270856 3014. 27 Algeria Africa 1962 48.3 11000948 2551. 28 Algeria Africa 1967 51.4 12760499 3247. 29 Algeria Africa 1972 54.5 14760787 4183. 30 Algeria Africa 1977 58.0 17152804 4910. 31 Algeria Africa 1982 61.4 20033753 5745. 32 Algeria Africa 1987 65.8 23254956 5681. 33 Algeria Africa 1992 67.7 26298373 5023. 34 Algeria Africa 1997 69.2 29072015 4797. 35 Algeria Africa 2002 71.0 31287142 5288. 36 Algeria Africa 2007 72.3 33333216 6223. 37 Angola Africa 1952 30.0 4232095 3521. 38 Angola Africa 1957 32.0 4561361 3828. 39 Angola Africa 1962 34 4826015 4269. 40 Angola Africa 1967 36.0 5247469 5523. 41 Angola Africa 1972 37.9 5894858 5473. 42 Angola Africa 1977 39.5 6162675 3009. 43 Angola Africa 1982 39.9 7016384 2757. 44 Angola Africa 1987 39.9 7874230 2430. 45 Angola Africa 1992 40.6 8735988 2628. 46 Angola Africa 1997 41.0 9875024 2277. 47 Angola Africa 2002 41.0 10866106 2773. 48 Angola Africa 2007 42.7 12420476 4797. 49 Argentina Americas 1952 62.5 17876956 5911. 50 Argentina Americas 1957 64.4 19610538 6857. 51 Argentina Americas 1962 65.1 21283783 7133. 52 Argentina Americas 1967 65.6 22934225 8053. 53 Argentina Americas 1972 67.1 24779799 9443. 54 Argentina Americas 1977 68.5 26983828 10079. 55 Argentina Americas 1982 69.9 29341374 8998. # … with 1,649 more rows ``` --- count: false ``` # A tibble: 142 × 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Afghanistan Asia 2002 42.1 25268405 727. 2 Albania Europe 2002 75.7 3508512 4604. 3 Algeria Africa 2002 71.0 31287142 5288. 4 Angola Africa 2002 41.0 10866106 2773. 5 Argentina Americas 2002 74.3 38331121 8798. 6 Australia Oceania 2002 80.4 19546792 30688. 7 Austria Europe 2002 79.0 8148312 32418. 8 Bahrain Asia 2002 74.8 656397 23404. 9 Bangladesh Asia 2002 62.0 135656790 1136. 10 Belgium Europe 2002 78.3 10311970 30486. 11 Benin Africa 2002 54.4 7026113 1373. 12 Bolivia Americas 2002 63.9 8445134 3413. 13 Bosnia and Herzegovina Europe 2002 74.1 4165416 6019. 14 Botswana Africa 2002 46.6 1630347 11004. 15 Brazil Americas 2002 71.0 179914212 8131. 16 Bulgaria Europe 2002 72.1 7661799 7697. 17 Burkina Faso Africa 2002 50.6 12251209 1038. 18 Burundi Africa 2002 47.4 7021078 446. 19 Cambodia Asia 2002 56.8 12926707 896. 20 Cameroon Africa 2002 49.9 15929988 1934. 21 Canada Americas 2002 79.8 31902268 33329. 22 Central African Republic Africa 2002 43.3 4048013 739. 23 Chad Africa 2002 50.5 8835739 1156. 24 Chile Americas 2002 77.9 15497046 10779. 25 China Asia 2002 72.0 1280400000 3119. 26 Colombia Americas 2002 71.7 41008227 5755. 27 Comoros Africa 2002 63.0 614382 1076. 28 Congo, Dem. Rep. Africa 2002 45.0 55379852 241. 29 Congo, Rep. Africa 2002 53.0 3328795 3484. 30 Costa Rica Americas 2002 78.1 3834934 7723. 31 Cote d'Ivoire Africa 2002 46.8 16252726 1649. 32 Croatia Europe 2002 74.9 4481020 11628. 33 Cuba Americas 2002 77.2 11226999 6341. 34 Czech Republic Europe 2002 75.5 10256295 17596. 35 Denmark Europe 2002 77.2 5374693 32167. 36 Djibouti Africa 2002 53.4 447416 1908. 37 Dominican Republic Americas 2002 70.8 8650322 4564. 38 Ecuador Americas 2002 74.2 12921234 5773. 39 Egypt Africa 2002 69.8 73312559 4755. 40 El Salvador Americas 2002 70.7 6353681 5352. 41 Equatorial Guinea Africa 2002 49.3 495627 7703. 42 Eritrea Africa 2002 55.2 4414865 765. 43 Ethiopia Africa 2002 50.7 67946797 530. 44 Finland Europe 2002 78.4 5193039 28205. 45 France Europe 2002 79.6 59925035 28926. 46 Gabon Africa 2002 56.8 1299304 12522. 47 Gambia Africa 2002 58.0 1457766 661. 48 Germany Europe 2002 78.7 82350671 30036. 49 Ghana Africa 2002 58.5 20550751 1112. 50 Greece Europe 2002 78.3 10603863 22514. 51 Guatemala Americas 2002 69.0 11178650 4858. 52 Guinea Africa 2002 53.7 8807818 946. 53 Guinea-Bissau Africa 2002 45.5 1332459 576. 54 Haiti Americas 2002 58.1 7607651 1270. 55 Honduras Americas 2002 68.6 6677328 3100. # … with 87 more rows ``` --- count: false ``` # A tibble: 30 × 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Albania Europe 2002 75.7 3508512 4604. 2 Austria Europe 2002 79.0 8148312 32418. 3 Belgium Europe 2002 78.3 10311970 30486. 4 Bosnia and Herzegovina Europe 2002 74.1 4165416 6019. 5 Bulgaria Europe 2002 72.1 7661799 7697. 6 Croatia Europe 2002 74.9 4481020 11628. 7 Czech Republic Europe 2002 75.5 10256295 17596. 8 Denmark Europe 2002 77.2 5374693 32167. 9 Finland Europe 2002 78.4 5193039 28205. 10 France Europe 2002 79.6 59925035 28926. 11 Germany Europe 2002 78.7 82350671 30036. 12 Greece Europe 2002 78.3 10603863 22514. 13 Hungary Europe 2002 72.6 10083313 14844. 14 Iceland Europe 2002 80.5 288030 31163. 15 Ireland Europe 2002 77.8 3879155 34077. 16 Italy Europe 2002 80.2 57926999 27968. 17 Montenegro Europe 2002 74.0 720230 6557. 18 Netherlands Europe 2002 78.5 16122830 33725. 19 Norway Europe 2002 79.0 4535591 44684. 20 Poland Europe 2002 74.7 38625976 12002. 21 Portugal Europe 2002 77.3 10433867 19971. 22 Romania Europe 2002 71.3 22404337 7885. 23 Serbia Europe 2002 73.2 10111559 7236. 24 Slovak Republic Europe 2002 73.8 5410052 13639. 25 Slovenia Europe 2002 76.7 2011497 20660. 26 Spain Europe 2002 79.8 40152517 24835. 27 Sweden Europe 2002 80.0 8954175 29342. 28 Switzerland Europe 2002 80.6 7361757 34481. 29 Turkey Europe 2002 70.8 67308928 6508. 30 United Kingdom Europe 2002 78.5 59912431 29479. ``` --- count: false ``` # A tibble: 30 × 5 country continent year pop gdpPercap <fct> <fct> <int> <int> <dbl> 1 Albania Europe 2002 3508512 4604. 2 Austria Europe 2002 8148312 32418. 3 Belgium Europe 2002 10311970 30486. 4 Bosnia and Herzegovina Europe 2002 4165416 6019. 5 Bulgaria Europe 2002 7661799 7697. 6 Croatia Europe 2002 4481020 11628. 7 Czech Republic Europe 2002 10256295 17596. 8 Denmark Europe 2002 5374693 32167. 9 Finland Europe 2002 5193039 28205. 10 France Europe 2002 59925035 28926. 11 Germany Europe 2002 82350671 30036. 12 Greece Europe 2002 10603863 22514. 13 Hungary Europe 2002 10083313 14844. 14 Iceland Europe 2002 288030 31163. 15 Ireland Europe 2002 3879155 34077. 16 Italy Europe 2002 57926999 27968. 17 Montenegro Europe 2002 720230 6557. 18 Netherlands Europe 2002 16122830 33725. 19 Norway Europe 2002 4535591 44684. 20 Poland Europe 2002 38625976 12002. 21 Portugal Europe 2002 10433867 19971. 22 Romania Europe 2002 22404337 7885. 23 Serbia Europe 2002 10111559 7236. 24 Slovak Republic Europe 2002 5410052 13639. 25 Slovenia Europe 2002 2011497 20660. 26 Spain Europe 2002 40152517 24835. 27 Sweden Europe 2002 8954175 29342. 28 Switzerland Europe 2002 7361757 34481. 29 Turkey Europe 2002 67308928 6508. 30 United Kingdom Europe 2002 59912431 29479. ``` --- count: false ``` # A tibble: 30 × 5 country continent year population gdpPercap <fct> <fct> <int> <int> <dbl> 1 Albania Europe 2002 3508512 4604. 2 Austria Europe 2002 8148312 32418. 3 Belgium Europe 2002 10311970 30486. 4 Bosnia and Herzegovina Europe 2002 4165416 6019. 5 Bulgaria Europe 2002 7661799 7697. 6 Croatia Europe 2002 4481020 11628. 7 Czech Republic Europe 2002 10256295 17596. 8 Denmark Europe 2002 5374693 32167. 9 Finland Europe 2002 5193039 28205. 10 France Europe 2002 59925035 28926. 11 Germany Europe 2002 82350671 30036. 12 Greece Europe 2002 10603863 22514. 13 Hungary Europe 2002 10083313 14844. 14 Iceland Europe 2002 288030 31163. 15 Ireland Europe 2002 3879155 34077. 16 Italy Europe 2002 57926999 27968. 17 Montenegro Europe 2002 720230 6557. 18 Netherlands Europe 2002 16122830 33725. 19 Norway Europe 2002 4535591 44684. 20 Poland Europe 2002 38625976 12002. 21 Portugal Europe 2002 10433867 19971. 22 Romania Europe 2002 22404337 7885. 23 Serbia Europe 2002 10111559 7236. 24 Slovak Republic Europe 2002 5410052 13639. 25 Slovenia Europe 2002 2011497 20660. 26 Spain Europe 2002 40152517 24835. 27 Sweden Europe 2002 8954175 29342. 28 Switzerland Europe 2002 7361757 34481. 29 Turkey Europe 2002 67308928 6508. 30 United Kingdom Europe 2002 59912431 29479. ``` --- count: false ``` # A tibble: 30 × 6 country continent year population gdpPercap gdp_billions <fct> <fct> <int> <int> <dbl> <dbl> 1 Albania Europe 2002 3508512 4604. 16.2 2 Austria Europe 2002 8148312 32418. 264. 3 Belgium Europe 2002 10311970 30486. 314. 4 Bosnia and Herzegovina Europe 2002 4165416 6019. 25.1 5 Bulgaria Europe 2002 7661799 7697. 59.0 6 Croatia Europe 2002 4481020 11628. 52.1 7 Czech Republic Europe 2002 10256295 17596. 180. 8 Denmark Europe 2002 5374693 32167. 173. 9 Finland Europe 2002 5193039 28205. 146. 10 France Europe 2002 59925035 28926. 1733. 11 Germany Europe 2002 82350671 30036. 2473. 12 Greece Europe 2002 10603863 22514. 239. 13 Hungary Europe 2002 10083313 14844. 150. 14 Iceland Europe 2002 288030 31163. 8.98 15 Ireland Europe 2002 3879155 34077. 132. 16 Italy Europe 2002 57926999 27968. 1620. 17 Montenegro Europe 2002 720230 6557. 4.72 18 Netherlands Europe 2002 16122830 33725. 544. 19 Norway Europe 2002 4535591 44684. 203. 20 Poland Europe 2002 38625976 12002. 464. 21 Portugal Europe 2002 10433867 19971. 208. 22 Romania Europe 2002 22404337 7885. 177. 23 Serbia Europe 2002 10111559 7236. 73.2 24 Slovak Republic Europe 2002 5410052 13639. 73.8 25 Slovenia Europe 2002 2011497 20660. 41.6 26 Spain Europe 2002 40152517 24835. 997. 27 Sweden Europe 2002 8954175 29342. 263. 28 Switzerland Europe 2002 7361757 34481. 254. 29 Turkey Europe 2002 67308928 6508. 438. 30 United Kingdom Europe 2002 59912431 29479. 1766. ``` --- count: false ``` # A tibble: 30 × 6 country continent year population gdpPercap gdp_billions <fct> <fct> <int> <int> <dbl> <dbl> 1 Montenegro Europe 2002 720230 6557. 4.72 2 Iceland Europe 2002 288030 31163. 8.98 3 Albania Europe 2002 3508512 4604. 16.2 4 Bosnia and Herzegovina Europe 2002 4165416 6019. 25.1 5 Slovenia Europe 2002 2011497 20660. 41.6 6 Croatia Europe 2002 4481020 11628. 52.1 7 Bulgaria Europe 2002 7661799 7697. 59.0 8 Serbia Europe 2002 10111559 7236. 73.2 9 Slovak Republic Europe 2002 5410052 13639. 73.8 10 Ireland Europe 2002 3879155 34077. 132. 11 Finland Europe 2002 5193039 28205. 146. 12 Hungary Europe 2002 10083313 14844. 150. 13 Denmark Europe 2002 5374693 32167. 173. 14 Romania Europe 2002 22404337 7885. 177. 15 Czech Republic Europe 2002 10256295 17596. 180. 16 Norway Europe 2002 4535591 44684. 203. 17 Portugal Europe 2002 10433867 19971. 208. 18 Greece Europe 2002 10603863 22514. 239. 19 Switzerland Europe 2002 7361757 34481. 254. 20 Sweden Europe 2002 8954175 29342. 263. 21 Austria Europe 2002 8148312 32418. 264. 22 Belgium Europe 2002 10311970 30486. 314. 23 Turkey Europe 2002 67308928 6508. 438. 24 Poland Europe 2002 38625976 12002. 464. 25 Netherlands Europe 2002 16122830 33725. 544. 26 Spain Europe 2002 40152517 24835. 997. 27 Italy Europe 2002 57926999 27968. 1620. 28 France Europe 2002 59925035 28926. 1733. 29 United Kingdom Europe 2002 59912431 29479. 1766. 30 Germany Europe 2002 82350671 30036. 2473. ``` --- count: false ``` # A tibble: 30 × 6 country continent year population gdpPercap gdp_billions <fct> <fct> <int> <int> <dbl> <dbl> 1 Montenegro Europe 2002 720230 6557. 4.72 2 Iceland Europe 2002 288030 31163. 8.98 3 Albania Europe 2002 3508512 4604. 16.2 4 Bosnia and Herzegovina Europe 2002 4165416 6019. 25.1 5 Slovenia Europe 2002 2011497 20660. 41.6 6 Croatia Europe 2002 4481020 11628. 52.1 7 Bulgaria Europe 2002 7661799 7697. 59.0 8 Serbia Europe 2002 10111559 7236. 73.2 9 Slovak Republic Europe 2002 5410052 13639. 73.8 10 Ireland Europe 2002 3879155 34077. 132. 11 Finland Europe 2002 5193039 28205. 146. 12 Hungary Europe 2002 10083313 14844. 150. 13 Denmark Europe 2002 5374693 32167. 173. 14 Romania Europe 2002 22404337 7885. 177. 15 Czech Republic Europe 2002 10256295 17596. 180. 16 Norway Europe 2002 4535591 44684. 203. 17 Portugal Europe 2002 10433867 19971. 208. 18 Greece Europe 2002 10603863 22514. 239. 19 Switzerland Europe 2002 7361757 34481. 254. 20 Sweden Europe 2002 8954175 29342. 263. 21 Austria Europe 2002 8148312 32418. 264. 22 Belgium Europe 2002 10311970 30486. 314. 23 Turkey Europe 2002 67308928 6508. 438. 24 Poland Europe 2002 38625976 12002. 464. 25 Netherlands Europe 2002 16122830 33725. 544. 26 Spain Europe 2002 40152517 24835. 997. 27 Italy Europe 2002 57926999 27968. 1620. 28 France Europe 2002 59925035 28926. 1733. 29 United Kingdom Europe 2002 59912431 29479. 1766. 30 Germany Europe 2002 82350671 30036. 2473. ``` --- count: false --- count: false ![](lesson_03_data_wrangling_simulation_files/figure-html/wrangle_auto_12_output-1.png)<!-- --> --- count: false ![](lesson_03_data_wrangling_simulation_files/figure-html/wrangle_auto_13_output-1.png)<!-- --> --- count: false ![](lesson_03_data_wrangling_simulation_files/figure-html/wrangle_auto_14_output-1.png)<!-- --> --- count: false ![](lesson_03_data_wrangling_simulation_files/figure-html/wrangle_auto_15_output-1.png)<!-- --> --- count: false ![](lesson_03_data_wrangling_simulation_files/figure-html/wrangle_auto_16_output-1.png)<!-- --> --- count: false ![](lesson_03_data_wrangling_simulation_files/figure-html/wrangle_auto_17_output-1.png)<!-- --> --- count: false ![](lesson_03_data_wrangling_simulation_files/figure-html/wrangle_auto_18_output-1.png)<!-- --> --- count: false ![](lesson_03_data_wrangling_simulation_files/figure-html/wrangle_auto_19_output-1.png)<!-- --> --- count: false ![](lesson_03_data_wrangling_simulation_files/figure-html/wrangle_auto_20_output-1.png)<!-- --> --- count: false ![](lesson_03_data_wrangling_simulation_files/figure-html/wrangle_auto_21_output-1.png)<!-- --> <style> .panel1-wrangle-auto { color: black; width: 99%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-wrangle-auto { color: black; width: NA%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-wrangle-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false .panel1-wrangle-auto[ ```r *library(gapminder) ``` ] .panel2-wrangle-auto[ ] --- count: false .panel1-wrangle-auto[ ```r library(gapminder) *library(tidyverse) ``` ] .panel2-wrangle-auto[ ] --- count: false .panel1-wrangle-auto[ ```r library(gapminder) library(tidyverse) *gapminder ``` ] .panel2-wrangle-auto[ ``` # A tibble: 1,704 × 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. 11 Afghanistan Asia 2002 42.1 25268405 727. 12 Afghanistan Asia 2007 43.8 31889923 975. 13 Albania Europe 1952 55.2 1282697 1601. 14 Albania Europe 1957 59.3 1476505 1942. 15 Albania Europe 1962 64.8 1728137 2313. 16 Albania Europe 1967 66.2 1984060 2760. 17 Albania Europe 1972 67.7 2263554 3313. 18 Albania Europe 1977 68.9 2509048 3533. 19 Albania Europe 1982 70.4 2780097 3631. 20 Albania Europe 1987 72 3075321 3739. 21 Albania Europe 1992 71.6 3326498 2497. 22 Albania Europe 1997 73.0 3428038 3193. 23 Albania Europe 2002 75.7 3508512 4604. 24 Albania Europe 2007 76.4 3600523 5937. 25 Algeria Africa 1952 43.1 9279525 2449. 26 Algeria Africa 1957 45.7 10270856 3014. 27 Algeria Africa 1962 48.3 11000948 2551. 28 Algeria Africa 1967 51.4 12760499 3247. 29 Algeria Africa 1972 54.5 14760787 4183. 30 Algeria Africa 1977 58.0 17152804 4910. 31 Algeria Africa 1982 61.4 20033753 5745. 32 Algeria Africa 1987 65.8 23254956 5681. 33 Algeria Africa 1992 67.7 26298373 5023. 34 Algeria Africa 1997 69.2 29072015 4797. 35 Algeria Africa 2002 71.0 31287142 5288. 36 Algeria Africa 2007 72.3 33333216 6223. 37 Angola Africa 1952 30.0 4232095 3521. 38 Angola Africa 1957 32.0 4561361 3828. 39 Angola Africa 1962 34 4826015 4269. 40 Angola Africa 1967 36.0 5247469 5523. 41 Angola Africa 1972 37.9 5894858 5473. 42 Angola Africa 1977 39.5 6162675 3009. 43 Angola Africa 1982 39.9 7016384 2757. 44 Angola Africa 1987 39.9 7874230 2430. 45 Angola Africa 1992 40.6 8735988 2628. 46 Angola Africa 1997 41.0 9875024 2277. 47 Angola Africa 2002 41.0 10866106 2773. 48 Angola Africa 2007 42.7 12420476 4797. 49 Argentina Americas 1952 62.5 17876956 5911. 50 Argentina Americas 1957 64.4 19610538 6857. 51 Argentina Americas 1962 65.1 21283783 7133. 52 Argentina Americas 1967 65.6 22934225 8053. 53 Argentina Americas 1972 67.1 24779799 9443. 54 Argentina Americas 1977 68.5 26983828 10079. 55 Argentina Americas 1982 69.9 29341374 8998. # … with 1,649 more rows ``` ] --- count: false .panel1-wrangle-auto[ ```r library(gapminder) library(tidyverse) gapminder %>% * filter(year == 2002) ``` ] .panel2-wrangle-auto[ ``` # A tibble: 142 × 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Afghanistan Asia 2002 42.1 25268405 727. 2 Albania Europe 2002 75.7 3508512 4604. 3 Algeria Africa 2002 71.0 31287142 5288. 4 Angola Africa 2002 41.0 10866106 2773. 5 Argentina Americas 2002 74.3 38331121 8798. 6 Australia Oceania 2002 80.4 19546792 30688. 7 Austria Europe 2002 79.0 8148312 32418. 8 Bahrain Asia 2002 74.8 656397 23404. 9 Bangladesh Asia 2002 62.0 135656790 1136. 10 Belgium Europe 2002 78.3 10311970 30486. 11 Benin Africa 2002 54.4 7026113 1373. 12 Bolivia Americas 2002 63.9 8445134 3413. 13 Bosnia and Herzegovina Europe 2002 74.1 4165416 6019. 14 Botswana Africa 2002 46.6 1630347 11004. 15 Brazil Americas 2002 71.0 179914212 8131. 16 Bulgaria Europe 2002 72.1 7661799 7697. 17 Burkina Faso Africa 2002 50.6 12251209 1038. 18 Burundi Africa 2002 47.4 7021078 446. 19 Cambodia Asia 2002 56.8 12926707 896. 20 Cameroon Africa 2002 49.9 15929988 1934. 21 Canada Americas 2002 79.8 31902268 33329. 22 Central African Republic Africa 2002 43.3 4048013 739. 23 Chad Africa 2002 50.5 8835739 1156. 24 Chile Americas 2002 77.9 15497046 10779. 25 China Asia 2002 72.0 1280400000 3119. 26 Colombia Americas 2002 71.7 41008227 5755. 27 Comoros Africa 2002 63.0 614382 1076. 28 Congo, Dem. Rep. Africa 2002 45.0 55379852 241. 29 Congo, Rep. Africa 2002 53.0 3328795 3484. 30 Costa Rica Americas 2002 78.1 3834934 7723. 31 Cote d'Ivoire Africa 2002 46.8 16252726 1649. 32 Croatia Europe 2002 74.9 4481020 11628. 33 Cuba Americas 2002 77.2 11226999 6341. 34 Czech Republic Europe 2002 75.5 10256295 17596. 35 Denmark Europe 2002 77.2 5374693 32167. 36 Djibouti Africa 2002 53.4 447416 1908. 37 Dominican Republic Americas 2002 70.8 8650322 4564. 38 Ecuador Americas 2002 74.2 12921234 5773. 39 Egypt Africa 2002 69.8 73312559 4755. 40 El Salvador Americas 2002 70.7 6353681 5352. 41 Equatorial Guinea Africa 2002 49.3 495627 7703. 42 Eritrea Africa 2002 55.2 4414865 765. 43 Ethiopia Africa 2002 50.7 67946797 530. 44 Finland Europe 2002 78.4 5193039 28205. 45 France Europe 2002 79.6 59925035 28926. 46 Gabon Africa 2002 56.8 1299304 12522. 47 Gambia Africa 2002 58.0 1457766 661. 48 Germany Europe 2002 78.7 82350671 30036. 49 Ghana Africa 2002 58.5 20550751 1112. 50 Greece Europe 2002 78.3 10603863 22514. 51 Guatemala Americas 2002 69.0 11178650 4858. 52 Guinea Africa 2002 53.7 8807818 946. 53 Guinea-Bissau Africa 2002 45.5 1332459 576. 54 Haiti Americas 2002 58.1 7607651 1270. 55 Honduras Americas 2002 68.6 6677328 3100. # … with 87 more rows ``` ] --- count: false .panel1-wrangle-auto[ ```r library(gapminder) library(tidyverse) gapminder %>% filter(year == 2002) %>% * filter(continent == "Europe") ``` ] .panel2-wrangle-auto[ ``` # A tibble: 30 × 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Albania Europe 2002 75.7 3508512 4604. 2 Austria Europe 2002 79.0 8148312 32418. 3 Belgium Europe 2002 78.3 10311970 30486. 4 Bosnia and Herzegovina Europe 2002 74.1 4165416 6019. 5 Bulgaria Europe 2002 72.1 7661799 7697. 6 Croatia Europe 2002 74.9 4481020 11628. 7 Czech Republic Europe 2002 75.5 10256295 17596. 8 Denmark Europe 2002 77.2 5374693 32167. 9 Finland Europe 2002 78.4 5193039 28205. 10 France Europe 2002 79.6 59925035 28926. 11 Germany Europe 2002 78.7 82350671 30036. 12 Greece Europe 2002 78.3 10603863 22514. 13 Hungary Europe 2002 72.6 10083313 14844. 14 Iceland Europe 2002 80.5 288030 31163. 15 Ireland Europe 2002 77.8 3879155 34077. 16 Italy Europe 2002 80.2 57926999 27968. 17 Montenegro Europe 2002 74.0 720230 6557. 18 Netherlands Europe 2002 78.5 16122830 33725. 19 Norway Europe 2002 79.0 4535591 44684. 20 Poland Europe 2002 74.7 38625976 12002. 21 Portugal Europe 2002 77.3 10433867 19971. 22 Romania Europe 2002 71.3 22404337 7885. 23 Serbia Europe 2002 73.2 10111559 7236. 24 Slovak Republic Europe 2002 73.8 5410052 13639. 25 Slovenia Europe 2002 76.7 2011497 20660. 26 Spain Europe 2002 79.8 40152517 24835. 27 Sweden Europe 2002 80.0 8954175 29342. 28 Switzerland Europe 2002 80.6 7361757 34481. 29 Turkey Europe 2002 70.8 67308928 6508. 30 United Kingdom Europe 2002 78.5 59912431 29479. ``` ] --- count: false .panel1-wrangle-auto[ ```r library(gapminder) library(tidyverse) gapminder %>% filter(year == 2002) %>% filter(continent == "Europe") %>% * select(-lifeExp) ``` ] .panel2-wrangle-auto[ ``` # A tibble: 30 × 5 country continent year pop gdpPercap <fct> <fct> <int> <int> <dbl> 1 Albania Europe 2002 3508512 4604. 2 Austria Europe 2002 8148312 32418. 3 Belgium Europe 2002 10311970 30486. 4 Bosnia and Herzegovina Europe 2002 4165416 6019. 5 Bulgaria Europe 2002 7661799 7697. 6 Croatia Europe 2002 4481020 11628. 7 Czech Republic Europe 2002 10256295 17596. 8 Denmark Europe 2002 5374693 32167. 9 Finland Europe 2002 5193039 28205. 10 France Europe 2002 59925035 28926. 11 Germany Europe 2002 82350671 30036. 12 Greece Europe 2002 10603863 22514. 13 Hungary Europe 2002 10083313 14844. 14 Iceland Europe 2002 288030 31163. 15 Ireland Europe 2002 3879155 34077. 16 Italy Europe 2002 57926999 27968. 17 Montenegro Europe 2002 720230 6557. 18 Netherlands Europe 2002 16122830 33725. 19 Norway Europe 2002 4535591 44684. 20 Poland Europe 2002 38625976 12002. 21 Portugal Europe 2002 10433867 19971. 22 Romania Europe 2002 22404337 7885. 23 Serbia Europe 2002 10111559 7236. 24 Slovak Republic Europe 2002 5410052 13639. 25 Slovenia Europe 2002 2011497 20660. 26 Spain Europe 2002 40152517 24835. 27 Sweden Europe 2002 8954175 29342. 28 Switzerland Europe 2002 7361757 34481. 29 Turkey Europe 2002 67308928 6508. 30 United Kingdom Europe 2002 59912431 29479. ``` ] --- count: false .panel1-wrangle-auto[ ```r library(gapminder) library(tidyverse) gapminder %>% filter(year == 2002) %>% filter(continent == "Europe") %>% select(-lifeExp) %>% * rename(population = pop) ``` ] .panel2-wrangle-auto[ ``` # A tibble: 30 × 5 country continent year population gdpPercap <fct> <fct> <int> <int> <dbl> 1 Albania Europe 2002 3508512 4604. 2 Austria Europe 2002 8148312 32418. 3 Belgium Europe 2002 10311970 30486. 4 Bosnia and Herzegovina Europe 2002 4165416 6019. 5 Bulgaria Europe 2002 7661799 7697. 6 Croatia Europe 2002 4481020 11628. 7 Czech Republic Europe 2002 10256295 17596. 8 Denmark Europe 2002 5374693 32167. 9 Finland Europe 2002 5193039 28205. 10 France Europe 2002 59925035 28926. 11 Germany Europe 2002 82350671 30036. 12 Greece Europe 2002 10603863 22514. 13 Hungary Europe 2002 10083313 14844. 14 Iceland Europe 2002 288030 31163. 15 Ireland Europe 2002 3879155 34077. 16 Italy Europe 2002 57926999 27968. 17 Montenegro Europe 2002 720230 6557. 18 Netherlands Europe 2002 16122830 33725. 19 Norway Europe 2002 4535591 44684. 20 Poland Europe 2002 38625976 12002. 21 Portugal Europe 2002 10433867 19971. 22 Romania Europe 2002 22404337 7885. 23 Serbia Europe 2002 10111559 7236. 24 Slovak Republic Europe 2002 5410052 13639. 25 Slovenia Europe 2002 2011497 20660. 26 Spain Europe 2002 40152517 24835. 27 Sweden Europe 2002 8954175 29342. 28 Switzerland Europe 2002 7361757 34481. 29 Turkey Europe 2002 67308928 6508. 30 United Kingdom Europe 2002 59912431 29479. ``` ] --- count: false .panel1-wrangle-auto[ ```r library(gapminder) library(tidyverse) gapminder %>% filter(year == 2002) %>% filter(continent == "Europe") %>% select(-lifeExp) %>% rename(population = pop) %>% * mutate(gdp_billions = * gdpPercap * population / * 1000000000) ``` ] .panel2-wrangle-auto[ ``` # A tibble: 30 × 6 country continent year population gdpPercap gdp_billions <fct> <fct> <int> <int> <dbl> <dbl> 1 Albania Europe 2002 3508512 4604. 16.2 2 Austria Europe 2002 8148312 32418. 264. 3 Belgium Europe 2002 10311970 30486. 314. 4 Bosnia and Herzegovina Europe 2002 4165416 6019. 25.1 5 Bulgaria Europe 2002 7661799 7697. 59.0 6 Croatia Europe 2002 4481020 11628. 52.1 7 Czech Republic Europe 2002 10256295 17596. 180. 8 Denmark Europe 2002 5374693 32167. 173. 9 Finland Europe 2002 5193039 28205. 146. 10 France Europe 2002 59925035 28926. 1733. 11 Germany Europe 2002 82350671 30036. 2473. 12 Greece Europe 2002 10603863 22514. 239. 13 Hungary Europe 2002 10083313 14844. 150. 14 Iceland Europe 2002 288030 31163. 8.98 15 Ireland Europe 2002 3879155 34077. 132. 16 Italy Europe 2002 57926999 27968. 1620. 17 Montenegro Europe 2002 720230 6557. 4.72 18 Netherlands Europe 2002 16122830 33725. 544. 19 Norway Europe 2002 4535591 44684. 203. 20 Poland Europe 2002 38625976 12002. 464. 21 Portugal Europe 2002 10433867 19971. 208. 22 Romania Europe 2002 22404337 7885. 177. 23 Serbia Europe 2002 10111559 7236. 73.2 24 Slovak Republic Europe 2002 5410052 13639. 73.8 25 Slovenia Europe 2002 2011497 20660. 41.6 26 Spain Europe 2002 40152517 24835. 997. 27 Sweden Europe 2002 8954175 29342. 263. 28 Switzerland Europe 2002 7361757 34481. 254. 29 Turkey Europe 2002 67308928 6508. 438. 30 United Kingdom Europe 2002 59912431 29479. 1766. ``` ] --- count: false .panel1-wrangle-auto[ ```r library(gapminder) library(tidyverse) gapminder %>% filter(year == 2002) %>% filter(continent == "Europe") %>% select(-lifeExp) %>% rename(population = pop) %>% mutate(gdp_billions = gdpPercap * population / 1000000000) %>% * arrange(gdp_billions) ``` ] .panel2-wrangle-auto[ ``` # A tibble: 30 × 6 country continent year population gdpPercap gdp_billions <fct> <fct> <int> <int> <dbl> <dbl> 1 Montenegro Europe 2002 720230 6557. 4.72 2 Iceland Europe 2002 288030 31163. 8.98 3 Albania Europe 2002 3508512 4604. 16.2 4 Bosnia and Herzegovina Europe 2002 4165416 6019. 25.1 5 Slovenia Europe 2002 2011497 20660. 41.6 6 Croatia Europe 2002 4481020 11628. 52.1 7 Bulgaria Europe 2002 7661799 7697. 59.0 8 Serbia Europe 2002 10111559 7236. 73.2 9 Slovak Republic Europe 2002 5410052 13639. 73.8 10 Ireland Europe 2002 3879155 34077. 132. 11 Finland Europe 2002 5193039 28205. 146. 12 Hungary Europe 2002 10083313 14844. 150. 13 Denmark Europe 2002 5374693 32167. 173. 14 Romania Europe 2002 22404337 7885. 177. 15 Czech Republic Europe 2002 10256295 17596. 180. 16 Norway Europe 2002 4535591 44684. 203. 17 Portugal Europe 2002 10433867 19971. 208. 18 Greece Europe 2002 10603863 22514. 239. 19 Switzerland Europe 2002 7361757 34481. 254. 20 Sweden Europe 2002 8954175 29342. 263. 21 Austria Europe 2002 8148312 32418. 264. 22 Belgium Europe 2002 10311970 30486. 314. 23 Turkey Europe 2002 67308928 6508. 438. 24 Poland Europe 2002 38625976 12002. 464. 25 Netherlands Europe 2002 16122830 33725. 544. 26 Spain Europe 2002 40152517 24835. 997. 27 Italy Europe 2002 57926999 27968. 1620. 28 France Europe 2002 59925035 28926. 1733. 29 United Kingdom Europe 2002 59912431 29479. 1766. 30 Germany Europe 2002 82350671 30036. 2473. ``` ] --- count: false .panel1-wrangle-auto[ ```r library(gapminder) library(tidyverse) gapminder %>% filter(year == 2002) %>% filter(continent == "Europe") %>% select(-lifeExp) %>% rename(population = pop) %>% mutate(gdp_billions = gdpPercap * population / 1000000000) %>% arrange(gdp_billions) %>% * mutate(country = * fct_reorder(country, * gdp_billions)) ``` ] .panel2-wrangle-auto[ ``` # A tibble: 30 × 6 country continent year population gdpPercap gdp_billions <fct> <fct> <int> <int> <dbl> <dbl> 1 Montenegro Europe 2002 720230 6557. 4.72 2 Iceland Europe 2002 288030 31163. 8.98 3 Albania Europe 2002 3508512 4604. 16.2 4 Bosnia and Herzegovina Europe 2002 4165416 6019. 25.1 5 Slovenia Europe 2002 2011497 20660. 41.6 6 Croatia Europe 2002 4481020 11628. 52.1 7 Bulgaria Europe 2002 7661799 7697. 59.0 8 Serbia Europe 2002 10111559 7236. 73.2 9 Slovak Republic Europe 2002 5410052 13639. 73.8 10 Ireland Europe 2002 3879155 34077. 132. 11 Finland Europe 2002 5193039 28205. 146. 12 Hungary Europe 2002 10083313 14844. 150. 13 Denmark Europe 2002 5374693 32167. 173. 14 Romania Europe 2002 22404337 7885. 177. 15 Czech Republic Europe 2002 10256295 17596. 180. 16 Norway Europe 2002 4535591 44684. 203. 17 Portugal Europe 2002 10433867 19971. 208. 18 Greece Europe 2002 10603863 22514. 239. 19 Switzerland Europe 2002 7361757 34481. 254. 20 Sweden Europe 2002 8954175 29342. 263. 21 Austria Europe 2002 8148312 32418. 264. 22 Belgium Europe 2002 10311970 30486. 314. 23 Turkey Europe 2002 67308928 6508. 438. 24 Poland Europe 2002 38625976 12002. 464. 25 Netherlands Europe 2002 16122830 33725. 544. 26 Spain Europe 2002 40152517 24835. 997. 27 Italy Europe 2002 57926999 27968. 1620. 28 France Europe 2002 59925035 28926. 1733. 29 United Kingdom Europe 2002 59912431 29479. 1766. 30 Germany Europe 2002 82350671 30036. 2473. ``` ] --- count: false .panel1-wrangle-auto[ ```r library(gapminder) library(tidyverse) gapminder %>% filter(year == 2002) %>% filter(continent == "Europe") %>% select(-lifeExp) %>% rename(population = pop) %>% mutate(gdp_billions = gdpPercap * population / 1000000000) %>% arrange(gdp_billions) %>% mutate(country = fct_reorder(country, gdp_billions)) -> *europe_2002 ``` ] .panel2-wrangle-auto[ ] --- count: false .panel1-wrangle-auto[ ```r library(gapminder) library(tidyverse) gapminder %>% filter(year == 2002) %>% filter(continent == "Europe") %>% select(-lifeExp) %>% rename(population = pop) %>% mutate(gdp_billions = gdpPercap * population / 1000000000) %>% arrange(gdp_billions) %>% mutate(country = fct_reorder(country, gdp_billions)) -> europe_2002 *ggplot(data = europe_2002) ``` ] .panel2-wrangle-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/wrangle_auto_12_output-1.png)<!-- --> ] --- count: false .panel1-wrangle-auto[ ```r library(gapminder) library(tidyverse) gapminder %>% filter(year == 2002) %>% filter(continent == "Europe") %>% select(-lifeExp) %>% rename(population = pop) %>% mutate(gdp_billions = gdpPercap * population / 1000000000) %>% arrange(gdp_billions) %>% mutate(country = fct_reorder(country, gdp_billions)) -> europe_2002 ggplot(data = europe_2002) + * aes(x = gdp_billions) ``` ] .panel2-wrangle-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/wrangle_auto_13_output-1.png)<!-- --> ] --- count: false .panel1-wrangle-auto[ ```r library(gapminder) library(tidyverse) gapminder %>% filter(year == 2002) %>% filter(continent == "Europe") %>% select(-lifeExp) %>% rename(population = pop) %>% mutate(gdp_billions = gdpPercap * population / 1000000000) %>% arrange(gdp_billions) %>% mutate(country = fct_reorder(country, gdp_billions)) -> europe_2002 ggplot(data = europe_2002) + aes(x = gdp_billions) + * aes(y = country) ``` ] .panel2-wrangle-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/wrangle_auto_14_output-1.png)<!-- --> ] --- count: false .panel1-wrangle-auto[ ```r library(gapminder) library(tidyverse) gapminder %>% filter(year == 2002) %>% filter(continent == "Europe") %>% select(-lifeExp) %>% rename(population = pop) %>% mutate(gdp_billions = gdpPercap * population / 1000000000) %>% arrange(gdp_billions) %>% mutate(country = fct_reorder(country, gdp_billions)) -> europe_2002 ggplot(data = europe_2002) + aes(x = gdp_billions) + aes(y = country) + * geom_col() ``` ] .panel2-wrangle-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/wrangle_auto_15_output-1.png)<!-- --> ] --- count: false .panel1-wrangle-auto[ ```r library(gapminder) library(tidyverse) gapminder %>% filter(year == 2002) %>% filter(continent == "Europe") %>% select(-lifeExp) %>% rename(population = pop) %>% mutate(gdp_billions = gdpPercap * population / 1000000000) %>% arrange(gdp_billions) %>% mutate(country = fct_reorder(country, gdp_billions)) -> europe_2002 ggplot(data = europe_2002) + aes(x = gdp_billions) + aes(y = country) + geom_col() + * labs(y = NULL) ``` ] .panel2-wrangle-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/wrangle_auto_16_output-1.png)<!-- --> ] --- count: false .panel1-wrangle-auto[ ```r library(gapminder) library(tidyverse) gapminder %>% filter(year == 2002) %>% filter(continent == "Europe") %>% select(-lifeExp) %>% rename(population = pop) %>% mutate(gdp_billions = gdpPercap * population / 1000000000) %>% arrange(gdp_billions) %>% mutate(country = fct_reorder(country, gdp_billions)) -> europe_2002 ggplot(data = europe_2002) + aes(x = gdp_billions) + aes(y = country) + geom_col() + labs(y = NULL) + * labs(x = "US$ Billions") ``` ] .panel2-wrangle-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/wrangle_auto_17_output-1.png)<!-- --> ] --- count: false .panel1-wrangle-auto[ ```r library(gapminder) library(tidyverse) gapminder %>% filter(year == 2002) %>% filter(continent == "Europe") %>% select(-lifeExp) %>% rename(population = pop) %>% mutate(gdp_billions = gdpPercap * population / 1000000000) %>% arrange(gdp_billions) %>% mutate(country = fct_reorder(country, gdp_billions)) -> europe_2002 ggplot(data = europe_2002) + aes(x = gdp_billions) + aes(y = country) + geom_col() + labs(y = NULL) + labs(x = "US$ Billions") + * labs(title = "Country GDP in Europe, 2002") ``` ] .panel2-wrangle-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/wrangle_auto_18_output-1.png)<!-- --> ] --- count: false .panel1-wrangle-auto[ ```r library(gapminder) library(tidyverse) gapminder %>% filter(year == 2002) %>% filter(continent == "Europe") %>% select(-lifeExp) %>% rename(population = pop) %>% mutate(gdp_billions = gdpPercap * population / 1000000000) %>% arrange(gdp_billions) %>% mutate(country = fct_reorder(country, gdp_billions)) -> europe_2002 ggplot(data = europe_2002) + aes(x = gdp_billions) + aes(y = country) + geom_col() + labs(y = NULL) + labs(x = "US$ Billions") + labs(title = "Country GDP in Europe, 2002") + * labs(subtitle = "Source: gapminder package") ``` ] .panel2-wrangle-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/wrangle_auto_19_output-1.png)<!-- --> ] --- count: false .panel1-wrangle-auto[ ```r library(gapminder) library(tidyverse) gapminder %>% filter(year == 2002) %>% filter(continent == "Europe") %>% select(-lifeExp) %>% rename(population = pop) %>% mutate(gdp_billions = gdpPercap * population / 1000000000) %>% arrange(gdp_billions) %>% mutate(country = fct_reorder(country, gdp_billions)) -> europe_2002 ggplot(data = europe_2002) + aes(x = gdp_billions) + aes(y = country) + geom_col() + labs(y = NULL) + labs(x = "US$ Billions") + labs(title = "Country GDP in Europe, 2002") + labs(subtitle = "Source: gapminder package") + * labs(caption = "Dr. Reynolds for MA206") ``` ] .panel2-wrangle-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/wrangle_auto_20_output-1.png)<!-- --> ] --- count: false .panel1-wrangle-auto[ ```r library(gapminder) library(tidyverse) gapminder %>% filter(year == 2002) %>% filter(continent == "Europe") %>% select(-lifeExp) %>% rename(population = pop) %>% mutate(gdp_billions = gdpPercap * population / 1000000000) %>% arrange(gdp_billions) %>% mutate(country = fct_reorder(country, gdp_billions)) -> europe_2002 ggplot(data = europe_2002) + aes(x = gdp_billions) + aes(y = country) + geom_col() + labs(y = NULL) + labs(x = "US$ Billions") + labs(title = "Country GDP in Europe, 2002") + labs(subtitle = "Source: gapminder package") + labs(caption = "Dr. Reynolds for MA206") + * theme_minimal(base_size = 10) ``` ] .panel2-wrangle-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/wrangle_auto_21_output-1.png)<!-- --> ] <style> .panel1-wrangle-auto { color: black; width: 38.6060606060606%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-wrangle-auto { color: black; width: 59.3939393939394%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-wrangle-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- # pressure and cars only -- # Getting other data - # gapminder - # wages - # ma206 data --- # 1. install 'gapminder' -- # 2. install 'remotes' -- # 3. install 'Lahman' (baseball statistics back to 1800's!) -- # 4. in console `remotes::install_github("EvaMaeRey/ma206data")` --- class: inverse, center, middle # Facets, Small multiples --- count: false .panel1-hans-auto[ ```r *library(tidyverse) ``` ] .panel2-hans-auto[ ] --- count: false .panel1-hans-auto[ ```r library(tidyverse) *gapminder::gapminder ``` ] .panel2-hans-auto[ ``` # A tibble: 1,704 × 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. 11 Afghanistan Asia 2002 42.1 25268405 727. 12 Afghanistan Asia 2007 43.8 31889923 975. 13 Albania Europe 1952 55.2 1282697 1601. 14 Albania Europe 1957 59.3 1476505 1942. 15 Albania Europe 1962 64.8 1728137 2313. 16 Albania Europe 1967 66.2 1984060 2760. 17 Albania Europe 1972 67.7 2263554 3313. 18 Albania Europe 1977 68.9 2509048 3533. 19 Albania Europe 1982 70.4 2780097 3631. 20 Albania Europe 1987 72 3075321 3739. 21 Albania Europe 1992 71.6 3326498 2497. 22 Albania Europe 1997 73.0 3428038 3193. 23 Albania Europe 2002 75.7 3508512 4604. 24 Albania Europe 2007 76.4 3600523 5937. 25 Algeria Africa 1952 43.1 9279525 2449. 26 Algeria Africa 1957 45.7 10270856 3014. 27 Algeria Africa 1962 48.3 11000948 2551. 28 Algeria Africa 1967 51.4 12760499 3247. 29 Algeria Africa 1972 54.5 14760787 4183. 30 Algeria Africa 1977 58.0 17152804 4910. 31 Algeria Africa 1982 61.4 20033753 5745. 32 Algeria Africa 1987 65.8 23254956 5681. 33 Algeria Africa 1992 67.7 26298373 5023. 34 Algeria Africa 1997 69.2 29072015 4797. 35 Algeria Africa 2002 71.0 31287142 5288. 36 Algeria Africa 2007 72.3 33333216 6223. 37 Angola Africa 1952 30.0 4232095 3521. 38 Angola Africa 1957 32.0 4561361 3828. 39 Angola Africa 1962 34 4826015 4269. 40 Angola Africa 1967 36.0 5247469 5523. 41 Angola Africa 1972 37.9 5894858 5473. 42 Angola Africa 1977 39.5 6162675 3009. 43 Angola Africa 1982 39.9 7016384 2757. 44 Angola Africa 1987 39.9 7874230 2430. 45 Angola Africa 1992 40.6 8735988 2628. 46 Angola Africa 1997 41.0 9875024 2277. 47 Angola Africa 2002 41.0 10866106 2773. 48 Angola Africa 2007 42.7 12420476 4797. 49 Argentina Americas 1952 62.5 17876956 5911. 50 Argentina Americas 1957 64.4 19610538 6857. 51 Argentina Americas 1962 65.1 21283783 7133. 52 Argentina Americas 1967 65.6 22934225 8053. 53 Argentina Americas 1972 67.1 24779799 9443. 54 Argentina Americas 1977 68.5 26983828 10079. 55 Argentina Americas 1982 69.9 29341374 8998. # … with 1,649 more rows ``` ] --- count: false .panel1-hans-auto[ ```r library(tidyverse) gapminder::gapminder %>% * filter(year == 2002) ``` ] .panel2-hans-auto[ ``` # A tibble: 142 × 6 country continent year lifeExp pop gdpPercap <fct> <fct> <int> <dbl> <int> <dbl> 1 Afghanistan Asia 2002 42.1 25268405 727. 2 Albania Europe 2002 75.7 3508512 4604. 3 Algeria Africa 2002 71.0 31287142 5288. 4 Angola Africa 2002 41.0 10866106 2773. 5 Argentina Americas 2002 74.3 38331121 8798. 6 Australia Oceania 2002 80.4 19546792 30688. 7 Austria Europe 2002 79.0 8148312 32418. 8 Bahrain Asia 2002 74.8 656397 23404. 9 Bangladesh Asia 2002 62.0 135656790 1136. 10 Belgium Europe 2002 78.3 10311970 30486. 11 Benin Africa 2002 54.4 7026113 1373. 12 Bolivia Americas 2002 63.9 8445134 3413. 13 Bosnia and Herzegovina Europe 2002 74.1 4165416 6019. 14 Botswana Africa 2002 46.6 1630347 11004. 15 Brazil Americas 2002 71.0 179914212 8131. 16 Bulgaria Europe 2002 72.1 7661799 7697. 17 Burkina Faso Africa 2002 50.6 12251209 1038. 18 Burundi Africa 2002 47.4 7021078 446. 19 Cambodia Asia 2002 56.8 12926707 896. 20 Cameroon Africa 2002 49.9 15929988 1934. 21 Canada Americas 2002 79.8 31902268 33329. 22 Central African Republic Africa 2002 43.3 4048013 739. 23 Chad Africa 2002 50.5 8835739 1156. 24 Chile Americas 2002 77.9 15497046 10779. 25 China Asia 2002 72.0 1280400000 3119. 26 Colombia Americas 2002 71.7 41008227 5755. 27 Comoros Africa 2002 63.0 614382 1076. 28 Congo, Dem. Rep. Africa 2002 45.0 55379852 241. 29 Congo, Rep. Africa 2002 53.0 3328795 3484. 30 Costa Rica Americas 2002 78.1 3834934 7723. 31 Cote d'Ivoire Africa 2002 46.8 16252726 1649. 32 Croatia Europe 2002 74.9 4481020 11628. 33 Cuba Americas 2002 77.2 11226999 6341. 34 Czech Republic Europe 2002 75.5 10256295 17596. 35 Denmark Europe 2002 77.2 5374693 32167. 36 Djibouti Africa 2002 53.4 447416 1908. 37 Dominican Republic Americas 2002 70.8 8650322 4564. 38 Ecuador Americas 2002 74.2 12921234 5773. 39 Egypt Africa 2002 69.8 73312559 4755. 40 El Salvador Americas 2002 70.7 6353681 5352. 41 Equatorial Guinea Africa 2002 49.3 495627 7703. 42 Eritrea Africa 2002 55.2 4414865 765. 43 Ethiopia Africa 2002 50.7 67946797 530. 44 Finland Europe 2002 78.4 5193039 28205. 45 France Europe 2002 79.6 59925035 28926. 46 Gabon Africa 2002 56.8 1299304 12522. 47 Gambia Africa 2002 58.0 1457766 661. 48 Germany Europe 2002 78.7 82350671 30036. 49 Ghana Africa 2002 58.5 20550751 1112. 50 Greece Europe 2002 78.3 10603863 22514. 51 Guatemala Americas 2002 69.0 11178650 4858. 52 Guinea Africa 2002 53.7 8807818 946. 53 Guinea-Bissau Africa 2002 45.5 1332459 576. 54 Haiti Americas 2002 58.1 7607651 1270. 55 Honduras Americas 2002 68.6 6677328 3100. # … with 87 more rows ``` ] --- count: false .panel1-hans-auto[ ```r library(tidyverse) gapminder::gapminder %>% filter(year == 2002) %>% * ggplot() ``` ] .panel2-hans-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/hans_auto_04_output-1.png)<!-- --> ] --- count: false .panel1-hans-auto[ ```r library(tidyverse) gapminder::gapminder %>% filter(year == 2002) %>% ggplot() + * aes(x = gdpPercap) ``` ] .panel2-hans-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/hans_auto_05_output-1.png)<!-- --> ] --- count: false .panel1-hans-auto[ ```r library(tidyverse) gapminder::gapminder %>% filter(year == 2002) %>% ggplot() + aes(x = gdpPercap) + * aes(y = lifeExp) ``` ] .panel2-hans-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/hans_auto_06_output-1.png)<!-- --> ] --- count: false .panel1-hans-auto[ ```r library(tidyverse) gapminder::gapminder %>% filter(year == 2002) %>% ggplot() + aes(x = gdpPercap) + aes(y = lifeExp) + * geom_point() ``` ] .panel2-hans-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/hans_auto_07_output-1.png)<!-- --> ] --- count: false .panel1-hans-auto[ ```r library(tidyverse) gapminder::gapminder %>% filter(year == 2002) %>% ggplot() + aes(x = gdpPercap) + aes(y = lifeExp) + geom_point() + * aes(color = continent) ``` ] .panel2-hans-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/hans_auto_08_output-1.png)<!-- --> ] --- count: false .panel1-hans-auto[ ```r library(tidyverse) gapminder::gapminder %>% filter(year == 2002) %>% ggplot() + aes(x = gdpPercap) + aes(y = lifeExp) + geom_point() + aes(color = continent) + * aes(size = pop/1000000) ``` ] .panel2-hans-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/hans_auto_09_output-1.png)<!-- --> ] --- count: false .panel1-hans-auto[ ```r library(tidyverse) gapminder::gapminder %>% filter(year == 2002) %>% ggplot() + aes(x = gdpPercap) + aes(y = lifeExp) + geom_point() + aes(color = continent) + aes(size = pop/1000000) + * labs(size = "Population\n(millions)") ``` ] .panel2-hans-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/hans_auto_10_output-1.png)<!-- --> ] --- count: false .panel1-hans-auto[ ```r library(tidyverse) gapminder::gapminder %>% filter(year == 2002) %>% ggplot() + aes(x = gdpPercap) + aes(y = lifeExp) + geom_point() + aes(color = continent) + aes(size = pop/1000000) + labs(size = "Population\n(millions)") + * labs(color = NULL) ``` ] .panel2-hans-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/hans_auto_11_output-1.png)<!-- --> ] --- count: false .panel1-hans-auto[ ```r library(tidyverse) gapminder::gapminder %>% filter(year == 2002) %>% ggplot() + aes(x = gdpPercap) + aes(y = lifeExp) + geom_point() + aes(color = continent) + aes(size = pop/1000000) + labs(size = "Population\n(millions)") + labs(color = NULL) + * labs(x = "Per Capita GDP ($US)") ``` ] .panel2-hans-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/hans_auto_12_output-1.png)<!-- --> ] --- count: false .panel1-hans-auto[ ```r library(tidyverse) gapminder::gapminder %>% filter(year == 2002) %>% ggplot() + aes(x = gdpPercap) + aes(y = lifeExp) + geom_point() + aes(color = continent) + aes(size = pop/1000000) + labs(size = "Population\n(millions)") + labs(color = NULL) + labs(x = "Per Capita GDP ($US)") + * labs(y = "Life expecancy (years)") ``` ] .panel2-hans-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/hans_auto_13_output-1.png)<!-- --> ] --- count: false .panel1-hans-auto[ ```r library(tidyverse) gapminder::gapminder %>% filter(year == 2002) %>% ggplot() + aes(x = gdpPercap) + aes(y = lifeExp) + geom_point() + aes(color = continent) + aes(size = pop/1000000) + labs(size = "Population\n(millions)") + labs(color = NULL) + labs(x = "Per Capita GDP ($US)") + labs(y = "Life expecancy (years)") + * labs(title = "Life expectancy vs Per Capita GDP, 2002") ``` ] .panel2-hans-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/hans_auto_14_output-1.png)<!-- --> ] --- count: false .panel1-hans-auto[ ```r library(tidyverse) gapminder::gapminder %>% filter(year == 2002) %>% ggplot() + aes(x = gdpPercap) + aes(y = lifeExp) + geom_point() + aes(color = continent) + aes(size = pop/1000000) + labs(size = "Population\n(millions)") + labs(color = NULL) + labs(x = "Per Capita GDP ($US)") + labs(y = "Life expecancy (years)") + labs(title = "Life expectancy vs Per Capita GDP, 2002") + * labs(subtitle = "Data Source: gapminder package") ``` ] .panel2-hans-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/hans_auto_15_output-1.png)<!-- --> ] --- count: false .panel1-hans-auto[ ```r library(tidyverse) gapminder::gapminder %>% filter(year == 2002) %>% ggplot() + aes(x = gdpPercap) + aes(y = lifeExp) + geom_point() + aes(color = continent) + aes(size = pop/1000000) + labs(size = "Population\n(millions)") + labs(color = NULL) + labs(x = "Per Capita GDP ($US)") + labs(y = "Life expecancy (years)") + labs(title = "Life expectancy vs Per Capita GDP, 2002") + labs(subtitle = "Data Source: gapminder package") + * labs(caption = "Produced for MA206 in Fall AY2023") ``` ] .panel2-hans-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/hans_auto_16_output-1.png)<!-- --> ] --- count: false .panel1-hans-auto[ ```r library(tidyverse) gapminder::gapminder %>% filter(year == 2002) %>% ggplot() + aes(x = gdpPercap) + aes(y = lifeExp) + geom_point() + aes(color = continent) + aes(size = pop/1000000) + labs(size = "Population\n(millions)") + labs(color = NULL) + labs(x = "Per Capita GDP ($US)") + labs(y = "Life expecancy (years)") + labs(title = "Life expectancy vs Per Capita GDP, 2002") + labs(subtitle = "Data Source: gapminder package") + labs(caption = "Produced for MA206 in Fall AY2023") + * facet_wrap(~ continent) ``` ] .panel2-hans-auto[ ![](lesson_03_data_wrangling_simulation_files/figure-html/hans_auto_17_output-1.png)<!-- --> ] <style> .panel1-hans-auto { color: black; width: 38.6060606060606%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-hans-auto { color: black; width: 59.3939393939394%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-hans-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> <style type="text/css"> .remark-code{line-height: 1.5; font-size: 100%} @media print { .has-continuation { display: block; } } code.r.hljs.remark-code{ position: relative; overflow-x: hidden; } code.r.hljs.remark-code:hover{ overflow-x:visible; width: 500px; border-style: solid; } </style>