class: center, middle, inverse, title-slide .title[ # A Very Incomplete Survey of Descriptive Statistics Commands in R ] .author[ ### EDP 613 ] --- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script type="text/x-mathjax-config"> MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () { MathJax.Hub.Insert(MathJax.InputJax.TeX.Definitions.macros,{ cancel: ["Extension","cancel"], bcancel: ["Extension","cancel"], xcancel: ["Extension","cancel"], cancelto: ["Extension","cancel"] }); }); </script> <style> section { display: flex; display: -webkit-flex; } section p { margin: auto; } .hljs-github .hljs { background: transparent; color: #b2dfdb; } .hljs-github .hljs-keyword { color: #64b5f6; } .hljs-github .hljs-literal { color: #64b5f6; } .hljs-github .hljs-number { color: #64b5f6; } .hljs-github .hljs-string { color: #b7b3ef; } section { height: 600px; width: 60%; margin: auto; border-radius: 20px; background-color: #212121; } section p { text-align: center; font-size: 30px; background-color: #212121; border-radius: 20px; font-family: Roboto Condensed; font-style: bold; padding: 15px; color: #bff4ee; } #center { text-align: center; } #right { text-align: right; } .center p { margin: 0; position: absolute; top: 50%; left: 50%; -ms-transform: translate(-50%, -50%); transform: translate(-50%, -50%); } </style>
# Packages needed and a Note about Icons Please load up the `tidyverse` package ``` r library(tidyverse) ``` <br> You may come across the following icons. The table below lists what each means. <table class="table" style="width: auto !important; margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:center;"> Icon </th> <th style="text-align:left;"> Description </th> </tr> </thead> <tbody> <tr> <td style="text-align:center;width: 10em; "> <svg aria-hidden="true" role="img" viewBox="0 0 512 512" style="height:1em;width:1em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#4682b4;overflow:visible;position:relative;"><path d="M52.5 440.6c-9.5 7.9-22.8 9.7-34.1 4.4S0 428.4 0 416V96C0 83.6 7.2 72.3 18.4 67s24.5-3.6 34.1 4.4L224 214.3V256v41.7L52.5 440.6zM256 352V256 128 96c0-12.4 7.2-23.7 18.4-29s24.5-3.6 34.1 4.4l192 160c7.3 6.1 11.5 15.1 11.5 24.6s-4.2 18.5-11.5 24.6l-192 160c-9.5 7.9-22.8 9.7-34.1 4.4s-18.4-16.6-18.4-29V352z"/></svg> </td> <td style="text-align:left;width: 40em; "> Indicates that an example continues on the following slide. </td> </tr> <tr> <td style="text-align:center;width: 10em; "> <svg aria-hidden="true" role="img" viewBox="0 0 384 512" style="height:1em;width:0.75em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#ff6347;overflow:visible;position:relative;"><path d="M0 128C0 92.7 28.7 64 64 64H320c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V128z"/></svg> </td> <td style="text-align:left;width: 40em; "> Indicates that a section using common syntax has ended. </td> </tr> <tr> <td style="text-align:center;width: 10em; "> <svg aria-hidden="true" role="img" viewBox="0 0 640 512" style="height:1em;width:1.25em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#5cb85c;overflow:visible;position:relative;"><path d="M579.8 267.7c56.5-56.5 56.5-148 0-204.5c-50-50-128.8-56.5-186.3-15.4l-1.6 1.1c-14.4 10.3-17.7 30.3-7.4 44.6s30.3 17.7 44.6 7.4l1.6-1.1c32.1-22.9 76-19.3 103.8 8.6c31.5 31.5 31.5 82.5 0 114L422.3 334.8c-31.5 31.5-82.5 31.5-114 0c-27.9-27.9-31.5-71.8-8.6-103.8l1.1-1.6c10.3-14.4 6.9-34.4-7.4-44.6s-34.4-6.9-44.6 7.4l-1.1 1.6C206.5 251.2 213 330 263 380c56.5 56.5 148 56.5 204.5 0L579.8 267.7zM60.2 244.3c-56.5 56.5-56.5 148 0 204.5c50 50 128.8 56.5 186.3 15.4l1.6-1.1c14.4-10.3 17.7-30.3 7.4-44.6s-30.3-17.7-44.6-7.4l-1.6 1.1c-32.1 22.9-76 19.3-103.8-8.6C74 372 74 321 105.5 289.5L217.7 177.2c31.5-31.5 82.5-31.5 114 0c27.9 27.9 31.5 71.8 8.6 103.9l-1.1 1.6c-10.3 14.4-6.9 34.4 7.4 44.6s34.4 6.9 44.6-7.4l1.1-1.6C433.5 260.8 427 182 377 132c-56.5-56.5-148-56.5-204.5 0L60.2 244.3z"/></svg> </td> <td style="text-align:left;width: 40em; "> Indicates that there is an active hyperlink on the slide. </td> </tr> <tr> <td style="text-align:center;width: 10em; "> <svg aria-hidden="true" role="img" viewBox="0 0 384 512" style="height:1em;width:0.75em;vertical-align:-0.125em;margin-left:auto;margin-right:auto;font-size:inherit;fill:#faffbd;overflow:visible;position:relative;"><path d="M0 48C0 21.5 21.5 0 48 0l0 48V441.4l130.1-92.9c8.3-6 19.6-6 27.9 0L336 441.4V48H48V0H336c26.5 0 48 21.5 48 48V488c0 9-5 17.2-13 21.3s-17.6 3.4-24.9-1.8L192 397.5 37.9 507.5c-7.3 5.2-16.9 5.9-24.9 1.8S0 497 0 488V48z"/></svg> </td> <td style="text-align:left;width: 40em; "> Indicates that a section covering a concept has ended. </td> </tr> </tbody> </table> --- # Descriptives We're going to use the Star Wars data set that's included in `dplyr` ``` r data(starwars) ``` ``` r starwars ``` ``` ## # A tibble: 87 × 14 ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` --- ## View a Portion of the Data Set ``` r head(starwars) ``` ``` ## # A tibble: 6 × 14 ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sky… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth Va… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Org… 150 49 brown light brown 19 fema… femin… ## 6 Owen Lars 178 120 brown, gr… light blue 52 male mascu… ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` --- ## Counts **Total number of names** tidy approach <br> ``` r starwars %>% dplyr::select(name) %>% nrow() ``` ``` ## [1] 87 ``` Base R approach <br> ``` r length(starwars$name) ``` ``` ## [1] 87 ``` .right[.footnote[
]] --- ## Column Types Using `str` ``` r str(starwars) ``` ``` ## tibble [87 × 14] (S3: tbl_df/tbl/data.frame) ## $ name : chr [1:87] "Luke Skywalker" "C-3PO" "R2-D2" "Darth Vader" ... ## $ height : int [1:87] 172 167 96 202 150 178 165 97 183 182 ... ## $ mass : num [1:87] 77 75 32 136 49 120 75 32 84 77 ... ## $ hair_color: chr [1:87] "blond" NA NA "none" ... ## $ skin_color: chr [1:87] "fair" "gold" "white, blue" "white" ... ## $ eye_color : chr [1:87] "blue" "yellow" "red" "yellow" ... ## $ birth_year: num [1:87] 19 112 33 41.9 19 52 47 NA 24 57 ... ## $ sex : chr [1:87] "male" "none" "none" "male" ... ## $ gender : chr [1:87] "masculine" "masculine" "masculine" "masculine" ... ## $ homeworld : chr [1:87] "Tatooine" "Tatooine" "Naboo" "Tatooine" ... ## $ species : chr [1:87] "Human" "Droid" "Droid" "Human" ... ## $ films :List of 87 ## ..$ : chr [1:5] "A New Hope" "The Empire Strikes Back" "Return of the Jedi" "Revenge of the Sith" ... ## ..$ : chr [1:6] "A New Hope" "The Empire Strikes Back" "Return of the Jedi" "The Phantom Menace" ... ## ..$ : chr [1:7] "A New Hope" "The Empire Strikes Back" "Return of the Jedi" "The Phantom Menace" ... ## ..$ : chr [1:4] "A New Hope" "The Empire Strikes Back" "Return of the Jedi" "Revenge of the Sith" ## ..$ : chr [1:5] "A New Hope" "The Empire Strikes Back" "Return of the Jedi" "Revenge of the Sith" ... ## ..$ : chr [1:3] "A New Hope" "Attack of the Clones" "Revenge of the Sith" ## ..$ : chr [1:3] "A New Hope" "Attack of the Clones" "Revenge of the Sith" ## ..$ : chr "A New Hope" ## ..$ : chr "A New Hope" ## ..$ : chr [1:6] "A New Hope" "The Empire Strikes Back" "Return of the Jedi" "The Phantom Menace" ... ## ..$ : chr [1:3] "The Phantom Menace" "Attack of the Clones" "Revenge of the Sith" ## ..$ : chr [1:2] "A New Hope" "Revenge of the Sith" ## ..$ : chr [1:5] "A New Hope" "The Empire Strikes Back" "Return of the Jedi" "Revenge of the Sith" ... ## ..$ : chr [1:4] "A New Hope" "The Empire Strikes Back" "Return of the Jedi" "The Force Awakens" ## ..$ : chr "A New Hope" ## ..$ : chr [1:3] "A New Hope" "Return of the Jedi" "The Phantom Menace" ## ..$ : chr [1:3] "A New Hope" "The Empire Strikes Back" "Return of the Jedi" ## ..$ : chr "A New Hope" ## ..$ : chr [1:5] "The Empire Strikes Back" "Return of the Jedi" "The Phantom Menace" "Attack of the Clones" ... ## ..$ : chr [1:5] "The Empire Strikes Back" "Return of the Jedi" "The Phantom Menace" "Attack of the Clones" ... ## ..$ : chr [1:3] "The Empire Strikes Back" "Return of the Jedi" "Attack of the Clones" ## ..$ : chr "The Empire Strikes Back" ## ..$ : chr "The Empire Strikes Back" ## ..$ : chr [1:2] "The Empire Strikes Back" "Return of the Jedi" ## ..$ : chr "The Empire Strikes Back" ## ..$ : chr [1:2] "Return of the Jedi" "The Force Awakens" ## ..$ : chr "Return of the Jedi" ## ..$ : chr "Return of the Jedi" ## ..$ : chr "Return of the Jedi" ## ..$ : chr "Return of the Jedi" ## ..$ : chr "The Phantom Menace" ## ..$ : chr [1:3] "The Phantom Menace" "Attack of the Clones" "Revenge of the Sith" ## ..$ : chr "The Phantom Menace" ## ..$ : chr [1:3] "The Phantom Menace" "Attack of the Clones" "Revenge of the Sith" ## ..$ : chr [1:2] "The Phantom Menace" "Attack of the Clones" ## ..$ : chr "The Phantom Menace" ## ..$ : chr "The Phantom Menace" ## ..$ : chr "The Phantom Menace" ## ..$ : chr [1:2] "The Phantom Menace" "Attack of the Clones" ## ..$ : chr "The Phantom Menace" ## ..$ : chr "The Phantom Menace" ## ..$ : chr [1:2] "The Phantom Menace" "Attack of the Clones" ## ..$ : chr "The Phantom Menace" ## ..$ : chr "Return of the Jedi" ## ..$ : chr [1:3] "The Phantom Menace" "Attack of the Clones" "Revenge of the Sith" ## ..$ : chr "The Phantom Menace" ## ..$ : chr "The Phantom Menace" ## ..$ : chr "The Phantom Menace" ## ..$ : chr "The Phantom Menace" ## ..$ : chr [1:3] "The Phantom Menace" "Attack of the Clones" "Revenge of the Sith" ## ..$ : chr [1:3] "The Phantom Menace" "Attack of the Clones" "Revenge of the Sith" ## ..$ : chr [1:3] "The Phantom Menace" "Attack of the Clones" "Revenge of the Sith" ## ..$ : chr [1:2] "The Phantom Menace" "Revenge of the Sith" ## ..$ : chr [1:2] "The Phantom Menace" "Revenge of the Sith" ## ..$ : chr [1:2] "The Phantom Menace" "Revenge of the Sith" ## ..$ : chr "The Phantom Menace" ## ..$ : chr [1:3] "The Phantom Menace" "Attack of the Clones" "Revenge of the Sith" ## ..$ : chr [1:2] "The Phantom Menace" "Attack of the Clones" ## ..$ : chr "Attack of the Clones" ## ..$ : chr "Attack of the Clones" ## ..$ : chr "Attack of the Clones" ## ..$ : chr [1:2] "Attack of the Clones" "Revenge of the Sith" ## ..$ : chr [1:2] "Attack of the Clones" "Revenge of the Sith" ## ..$ : chr "Attack of the Clones" ## ..$ : chr "Attack of the Clones" ## ..$ : chr [1:2] "Attack of the Clones" "Revenge of the Sith" ## ..$ : chr [1:2] "Attack of the Clones" "Revenge of the Sith" ## ..$ : chr "Attack of the Clones" ## ..$ : chr "Attack of the Clones" ## ..$ : chr "Attack of the Clones" ## ..$ : chr "Attack of the Clones" ## ..$ : chr "Attack of the Clones" ## ..$ : chr "Attack of the Clones" ## ..$ : chr [1:2] "Attack of the Clones" "Revenge of the Sith" ## ..$ : chr "Attack of the Clones" ## ..$ : chr "Attack of the Clones" ## ..$ : chr [1:2] "Attack of the Clones" "Revenge of the Sith" ## ..$ : chr "Revenge of the Sith" ## ..$ : chr "Revenge of the Sith" ## ..$ : chr [1:2] "A New Hope" "Revenge of the Sith" ## ..$ : chr [1:2] "Attack of the Clones" "Revenge of the Sith" ## ..$ : chr "Revenge of the Sith" ## ..$ : chr "The Force Awakens" ## ..$ : chr "The Force Awakens" ## ..$ : chr "The Force Awakens" ## ..$ : chr "The Force Awakens" ## ..$ : chr "The Force Awakens" ## $ vehicles :List of 87 ## ..$ : chr [1:2] "Snowspeeder" "Imperial Speeder Bike" ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr "Imperial Speeder Bike" ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr "Tribubble bongo" ## ..$ : chr [1:2] "Zephyr-G swoop bike" "XJ-6 airspeeder" ## ..$ : chr(0) ## ..$ : chr "AT-ST" ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr "Snowspeeder" ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr "Tribubble bongo" ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr "Sith speeder" ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr "Flitknot speeder" ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr "Koro-2 Exodrive airspeeder" ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr "Tsmeu-6 personal wheel bike" ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## $ starships :List of 87 ## ..$ : chr [1:2] "X-wing" "Imperial shuttle" ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr "TIE Advanced x1" ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr "X-wing" ## ..$ : chr [1:5] "Jedi starfighter" "Trade Federation cruiser" "Naboo star skiff" "Jedi Interceptor" ... ## ..$ : chr [1:3] "Naboo fighter" "Trade Federation cruiser" "Jedi Interceptor" ## ..$ : chr(0) ## ..$ : chr [1:2] "Millennium Falcon" "Imperial shuttle" ## ..$ : chr [1:2] "Millennium Falcon" "Imperial shuttle" ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr "X-wing" ## ..$ : chr "X-wing" ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr "Slave 1" ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr "Millennium Falcon" ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr "A-wing" ## ..$ : chr(0) ## ..$ : chr "Millennium Falcon" ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr [1:3] "Naboo fighter" "H-type Nubian yacht" "Naboo star skiff" ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr "Naboo Royal Starship" ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr "Scimitar" ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr "Jedi starfighter" ## ..$ : chr(0) ## ..$ : chr "Naboo fighter" ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr "Belbullab-22 starfighter" ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr(0) ## ..$ : chr "X-wing" ## ..$ : chr(0) ## ..$ : chr(0) ``` or.... --- Using `glimpse` ``` r glimpse(starwars) ``` ``` ## Rows: 87 ## Columns: 14 ## $ name <chr> "Luke Skywalker", "C-3PO", "R2-D2", "Darth Vader", "Leia Or… ## $ height <int> 172, 167, 96, 202, 150, 178, 165, 97, 183, 182, 188, 180, 2… ## $ mass <dbl> 77.0, 75.0, 32.0, 136.0, 49.0, 120.0, 75.0, 32.0, 84.0, 77.… ## $ hair_color <chr> "blond", NA, NA, "none", "brown", "brown, grey", "brown", N… ## $ skin_color <chr> "fair", "gold", "white, blue", "white", "light", "light", "… ## $ eye_color <chr> "blue", "yellow", "red", "yellow", "brown", "blue", "blue",… ## $ birth_year <dbl> 19.0, 112.0, 33.0, 41.9, 19.0, 52.0, 47.0, NA, 24.0, 57.0, … ## $ sex <chr> "male", "none", "none", "male", "female", "male", "female",… ## $ gender <chr> "masculine", "masculine", "masculine", "masculine", "femini… ## $ homeworld <chr> "Tatooine", "Tatooine", "Naboo", "Tatooine", "Alderaan", "T… ## $ species <chr> "Human", "Droid", "Droid", "Human", "Human", "Human", "Huma… ## $ films <list> <"A New Hope", "The Empire Strikes Back", "Return of the J… ## $ vehicles <list> <"Snowspeeder", "Imperial Speeder Bike">, <>, <>, <>, "Imp… ## $ starships <list> <"X-wing", "Imperial shuttle">, <>, <>, "TIE Advanced x1",… ``` .right[.footnote[
]] --- ## Frequencies count: false .panel1-sw1-auto[ ``` r *starwars ``` ] .panel2-sw1-auto[ ``` ## # A tibble: 87 × 14 ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw1-auto[ ``` r starwars %>% * count(sex) ``` ] .panel2-sw1-auto[ ``` ## # A tibble: 5 × 2 ## sex n ## <chr> <int> ## 1 female 16 ## 2 hermaphroditic 1 ## 3 male 60 ## 4 none 6 ## 5 <NA> 4 ``` ] <style> .panel1-sw1-auto { color: white; width: 49%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw1-auto { color: white; width: 49%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw1-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> .right[.footnote[
]] --- ## Measures of Central Tendency **Mean** count: false .panel1-sw2-auto[ ``` r *starwars ``` ] .panel2-sw2-auto[ ``` ## # A tibble: 87 × 14 ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw2-auto[ ``` r starwars %>% * group_by(species) ``` ] .panel2-sw2-auto[ ``` ## # A tibble: 87 × 14 ## # Groups: species [38] ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw2-auto[ ``` r starwars %>% group_by(species) %>% * na.omit() ``` ] .panel2-sw2-auto[ ``` ## # A tibble: 29 × 14 ## # Groups: species [11] ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 Darth V… 202 136 none white yellow 41.9 male mascu… ## 3 Leia Or… 150 49 brown light brown 19 fema… femin… ## 4 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 5 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 6 Biggs D… 183 84 black light brown 24 male mascu… ## 7 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## 8 Anakin … 188 84 blond fair blue 41.9 male mascu… ## 9 Chewbac… 228 112 brown unknown blue 200 male mascu… ## 10 Han Solo 180 80 brown fair brown 29 male mascu… ## # ℹ 19 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw2-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% * summarise(mean(birth_year)) ``` ] .panel2-sw2-auto[ ``` ## # A tibble: 11 × 2 ## species `mean(birth_year)` ## <chr> <dbl> ## 1 Cerean 92 ## 2 Ewok 8 ## 3 Gungan 52 ## 4 Human 45.5 ## 5 Kel Dor 22 ## 6 Mirialan 49 ## 7 Mon Calamari 41 ## 8 Trandoshan 53 ## 9 Twi'lek 48 ## 10 Wookiee 200 ## 11 Zabrak 54 ``` ] --- count: false .panel1-sw2-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(mean(birth_year)) %>% * rename(`mean age by species` = * `mean(birth_year)`) ``` ] .panel2-sw2-auto[ ``` ## # A tibble: 11 × 2 ## species `mean age by species` ## <chr> <dbl> ## 1 Cerean 92 ## 2 Ewok 8 ## 3 Gungan 52 ## 4 Human 45.5 ## 5 Kel Dor 22 ## 6 Mirialan 49 ## 7 Mon Calamari 41 ## 8 Trandoshan 53 ## 9 Twi'lek 48 ## 10 Wookiee 200 ## 11 Zabrak 54 ``` ] --- count: false .panel1-sw2-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(mean(birth_year)) %>% rename(`mean age by species` = `mean(birth_year)`) %>% * ungroup() ``` ] .panel2-sw2-auto[ ``` ## # A tibble: 11 × 2 ## species `mean age by species` ## <chr> <dbl> ## 1 Cerean 92 ## 2 Ewok 8 ## 3 Gungan 52 ## 4 Human 45.5 ## 5 Kel Dor 22 ## 6 Mirialan 49 ## 7 Mon Calamari 41 ## 8 Trandoshan 53 ## 9 Twi'lek 48 ## 10 Wookiee 200 ## 11 Zabrak 54 ``` ] <style> .panel1-sw2-auto { color: white; width: 44.1%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw2-auto { color: white; width: 53.9%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw2-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- --- ### Side Note: Using Base R vs. tidy Either is fine but think about the outcome and what you're going to do with it. Let's take the `mean` again with a fake data set from taste test ratings using two varieties of bananas: cavendish and ice cream. ``` r banana_data <- tibble( id = c(1,2,3,4,5), cav_cat = c("Excellent", "Above Average", "Very Poor", "Average", "Excellent"), cav_code = c(5,4,1,3,5), ic_cat = c("Excellent", "Excellent", "Above Average", "Excellent", "Excellent"), ic_code = c(5,5,4,5,5) ) ``` .right[.footnote[
]] .pull-right[.footnote[If you are wondering, the blue java - aka the [ice cream banana](https://www.abc15.com/news/state/planet-arizona-blue-bananas-exist-and-they-taste-like-vanilla-ice-cream) is real!]] --- ``` r banana_data ``` ``` ## # A tibble: 5 × 5 ## id cav_cat cav_code ic_cat ic_code ## <dbl> <chr> <dbl> <chr> <dbl> ## 1 1 Excellent 5 Excellent 5 ## 2 2 Above Average 4 Excellent 5 ## 3 3 Very Poor 1 Above Average 4 ## 4 4 Average 3 Excellent 5 ## 5 5 Excellent 5 Excellent 5 ``` .right[.footnote[
]] --- If we just wanted to find the means, then the Base R method is likely simpler ``` r mean(banana_data$cav_code) ``` ``` ## [1] 3.6 ``` ``` r mean(banana_data$ic_code) ``` ``` ## [1] 4.8 ``` --- but if we wanted to pass that output along say to find the range of the means, the tidy way is a simpler and more efficient approach count: false .panel1-sw3-auto[ ``` r *banana_data ``` ] .panel2-sw3-auto[ ``` ## # A tibble: 5 × 5 ## id cav_cat cav_code ic_cat ic_code ## <dbl> <chr> <dbl> <chr> <dbl> ## 1 1 Excellent 5 Excellent 5 ## 2 2 Above Average 4 Excellent 5 ## 3 3 Very Poor 1 Above Average 4 ## 4 4 Average 3 Excellent 5 ## 5 5 Excellent 5 Excellent 5 ``` ] --- count: false .panel1-sw3-auto[ ``` r banana_data %>% * summarise(mean_cav = mean(cav_code), * mean_ic = mean(ic_code)) ``` ] .panel2-sw3-auto[ ``` ## # A tibble: 1 × 2 ## mean_cav mean_ic ## <dbl> <dbl> ## 1 3.6 4.8 ``` ] --- count: false .panel1-sw3-auto[ ``` r banana_data %>% summarise(mean_cav = mean(cav_code), mean_ic = mean(ic_code)) %>% * mutate(range_means = mean_ic - mean_cav) ``` ] .panel2-sw3-auto[ ``` ## # A tibble: 1 × 3 ## mean_cav mean_ic range_means ## <dbl> <dbl> <dbl> ## 1 3.6 4.8 1.2 ``` ] <style> .panel1-sw3-auto { color: white; width: 49%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw3-auto { color: white; width: 49%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw3-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- **Median** count: false .panel1-sw4-auto[ ``` r *starwars ``` ] .panel2-sw4-auto[ ``` ## # A tibble: 87 × 14 ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw4-auto[ ``` r starwars %>% * group_by(species) ``` ] .panel2-sw4-auto[ ``` ## # A tibble: 87 × 14 ## # Groups: species [38] ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw4-auto[ ``` r starwars %>% group_by(species) %>% * na.omit() ``` ] .panel2-sw4-auto[ ``` ## # A tibble: 29 × 14 ## # Groups: species [11] ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 Darth V… 202 136 none white yellow 41.9 male mascu… ## 3 Leia Or… 150 49 brown light brown 19 fema… femin… ## 4 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 5 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 6 Biggs D… 183 84 black light brown 24 male mascu… ## 7 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## 8 Anakin … 188 84 blond fair blue 41.9 male mascu… ## 9 Chewbac… 228 112 brown unknown blue 200 male mascu… ## 10 Han Solo 180 80 brown fair brown 29 male mascu… ## # ℹ 19 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw4-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% * summarise(median(birth_year)) ``` ] .panel2-sw4-auto[ ``` ## # A tibble: 11 × 2 ## species `median(birth_year)` ## <chr> <dbl> ## 1 Cerean 92 ## 2 Ewok 8 ## 3 Gungan 52 ## 4 Human 41.9 ## 5 Kel Dor 22 ## 6 Mirialan 49 ## 7 Mon Calamari 41 ## 8 Trandoshan 53 ## 9 Twi'lek 48 ## 10 Wookiee 200 ## 11 Zabrak 54 ``` ] --- count: false .panel1-sw4-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(median(birth_year)) %>% * rename(`median age by species` = * `median(birth_year)`) ``` ] .panel2-sw4-auto[ ``` ## # A tibble: 11 × 2 ## species `median age by species` ## <chr> <dbl> ## 1 Cerean 92 ## 2 Ewok 8 ## 3 Gungan 52 ## 4 Human 41.9 ## 5 Kel Dor 22 ## 6 Mirialan 49 ## 7 Mon Calamari 41 ## 8 Trandoshan 53 ## 9 Twi'lek 48 ## 10 Wookiee 200 ## 11 Zabrak 54 ``` ] --- count: false .panel1-sw4-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(median(birth_year)) %>% rename(`median age by species` = `median(birth_year)`) %>% * ungroup() ``` ] .panel2-sw4-auto[ ``` ## # A tibble: 11 × 2 ## species `median age by species` ## <chr> <dbl> ## 1 Cerean 92 ## 2 Ewok 8 ## 3 Gungan 52 ## 4 Human 41.9 ## 5 Kel Dor 22 ## 6 Mirialan 49 ## 7 Mon Calamari 41 ## 8 Trandoshan 53 ## 9 Twi'lek 48 ## 10 Wookiee 200 ## 11 Zabrak 54 ``` ] <style> .panel1-sw4-auto { color: white; width: 44.1%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw4-auto { color: white; width: 53.9%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw4-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- **Mode** <br><br> Remember that `mode` means something else in R. Instead first run the chunk below ``` r Mode <- function(x) { ux <- unique(x) ux[which.max(tabulate(match(x, ux)))] } ``` .right[.footnote[
]] --- Then you can find the `Mode` count: false .panel1-sw5-auto[ ``` r *starwars ``` ] .panel2-sw5-auto[ ``` ## # A tibble: 87 × 14 ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw5-auto[ ``` r starwars %>% * group_by(species) ``` ] .panel2-sw5-auto[ ``` ## # A tibble: 87 × 14 ## # Groups: species [38] ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw5-auto[ ``` r starwars %>% group_by(species) %>% * na.omit() ``` ] .panel2-sw5-auto[ ``` ## # A tibble: 29 × 14 ## # Groups: species [11] ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 Darth V… 202 136 none white yellow 41.9 male mascu… ## 3 Leia Or… 150 49 brown light brown 19 fema… femin… ## 4 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 5 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 6 Biggs D… 183 84 black light brown 24 male mascu… ## 7 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## 8 Anakin … 188 84 blond fair blue 41.9 male mascu… ## 9 Chewbac… 228 112 brown unknown blue 200 male mascu… ## 10 Han Solo 180 80 brown fair brown 29 male mascu… ## # ℹ 19 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw5-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% * summarise(Mode(birth_year)) ``` ] .panel2-sw5-auto[ ``` ## # A tibble: 11 × 2 ## species `Mode(birth_year)` ## <chr> <dbl> ## 1 Cerean 92 ## 2 Ewok 8 ## 3 Gungan 52 ## 4 Human 19 ## 5 Kel Dor 22 ## 6 Mirialan 58 ## 7 Mon Calamari 41 ## 8 Trandoshan 53 ## 9 Twi'lek 48 ## 10 Wookiee 200 ## 11 Zabrak 54 ``` ] --- count: false .panel1-sw5-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(Mode(birth_year)) %>% * rename(`mode age by species` = * `Mode(birth_year)`) ``` ] .panel2-sw5-auto[ ``` ## # A tibble: 11 × 2 ## species `mode age by species` ## <chr> <dbl> ## 1 Cerean 92 ## 2 Ewok 8 ## 3 Gungan 52 ## 4 Human 19 ## 5 Kel Dor 22 ## 6 Mirialan 58 ## 7 Mon Calamari 41 ## 8 Trandoshan 53 ## 9 Twi'lek 48 ## 10 Wookiee 200 ## 11 Zabrak 54 ``` ] --- count: false .panel1-sw5-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(Mode(birth_year)) %>% rename(`mode age by species` = `Mode(birth_year)`) %>% * ungroup() ``` ] .panel2-sw5-auto[ ``` ## # A tibble: 11 × 2 ## species `mode age by species` ## <chr> <dbl> ## 1 Cerean 92 ## 2 Ewok 8 ## 3 Gungan 52 ## 4 Human 19 ## 5 Kel Dor 22 ## 6 Mirialan 58 ## 7 Mon Calamari 41 ## 8 Trandoshan 53 ## 9 Twi'lek 48 ## 10 Wookiee 200 ## 11 Zabrak 54 ``` ] <style> .panel1-sw5-auto { color: white; width: 44.1%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw5-auto { color: white; width: 53.9%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw5-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- **Mean by Value** Sometimes you need to find a measure for a particular subgroup. In this example, we only want to find the birth year for the female classification of each species. One way to accomplish this is to use the `filter` command to get what we want. count: false .panel1-sw6-auto[ ``` r *starwars ``` ] .panel2-sw6-auto[ ``` ## # A tibble: 87 × 14 ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw6-auto[ ``` r starwars %>% * filter(gender == "feminine") ``` ] .panel2-sw6-auto[ ``` ## # A tibble: 17 × 14 ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Leia Or… 150 49 brown light brown 19 fema… femin… ## 2 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 3 Mon Mot… 150 NA auburn fair blue 48 fema… femin… ## 4 Padmé A… 185 45 brown light brown 46 fema… femin… ## 5 Shmi Sk… 163 NA black fair brown 72 fema… femin… ## 6 Ayla Se… 178 55 none blue hazel 48 fema… femin… ## 7 Adi Gal… 184 50 none dark blue NA fema… femin… ## 8 Luminar… 170 56.2 black yellow blue 58 fema… femin… ## 9 Barriss… 166 50 black yellow blue 40 fema… femin… ## 10 Dormé 165 NA brown light brown NA fema… femin… ## 11 Zam Wes… 168 55 blonde fair, gre… yellow NA fema… femin… ## 12 Taun We 213 NA none grey black NA fema… femin… ## 13 Jocasta… 167 NA white fair blue NA fema… femin… ## 14 R4-P17 96 NA none silver, r… red, blue NA none femin… ## 15 Shaak Ti 178 57 none red, blue… black NA fema… femin… ## 16 Rey NA NA brown light hazel NA fema… femin… ## 17 Captain… NA NA none none unknown NA fema… femin… ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw6-auto[ ``` r starwars %>% filter(gender == "feminine") %>% * group_by(species) ``` ] .panel2-sw6-auto[ ``` ## # A tibble: 17 × 14 ## # Groups: species [8] ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Leia Or… 150 49 brown light brown 19 fema… femin… ## 2 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 3 Mon Mot… 150 NA auburn fair blue 48 fema… femin… ## 4 Padmé A… 185 45 brown light brown 46 fema… femin… ## 5 Shmi Sk… 163 NA black fair brown 72 fema… femin… ## 6 Ayla Se… 178 55 none blue hazel 48 fema… femin… ## 7 Adi Gal… 184 50 none dark blue NA fema… femin… ## 8 Luminar… 170 56.2 black yellow blue 58 fema… femin… ## 9 Barriss… 166 50 black yellow blue 40 fema… femin… ## 10 Dormé 165 NA brown light brown NA fema… femin… ## 11 Zam Wes… 168 55 blonde fair, gre… yellow NA fema… femin… ## 12 Taun We 213 NA none grey black NA fema… femin… ## 13 Jocasta… 167 NA white fair blue NA fema… femin… ## 14 R4-P17 96 NA none silver, r… red, blue NA none femin… ## 15 Shaak Ti 178 57 none red, blue… black NA fema… femin… ## 16 Rey NA NA brown light hazel NA fema… femin… ## 17 Captain… NA NA none none unknown NA fema… femin… ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw6-auto[ ``` r starwars %>% filter(gender == "feminine") %>% group_by(species) %>% * na.omit() ``` ] .panel2-sw6-auto[ ``` ## # A tibble: 6 × 14 ## # Groups: species [3] ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Leia Org… 150 49 brown light brown 19 fema… femin… ## 2 Beru Whi… 165 75 brown light blue 47 fema… femin… ## 3 Padmé Am… 185 45 brown light brown 46 fema… femin… ## 4 Ayla Sec… 178 55 none blue hazel 48 fema… femin… ## 5 Luminara… 170 56.2 black yellow blue 58 fema… femin… ## 6 Barriss … 166 50 black yellow blue 40 fema… femin… ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw6-auto[ ``` r starwars %>% filter(gender == "feminine") %>% group_by(species) %>% na.omit() %>% * summarise(mean(birth_year)) ``` ] .panel2-sw6-auto[ ``` ## # A tibble: 3 × 2 ## species `mean(birth_year)` ## <chr> <dbl> ## 1 Human 37.3 ## 2 Mirialan 49 ## 3 Twi'lek 48 ``` ] --- count: false .panel1-sw6-auto[ ``` r starwars %>% filter(gender == "feminine") %>% group_by(species) %>% na.omit() %>% summarise(mean(birth_year)) %>% * rename(`female mean age by species` = * `mean(birth_year)`) ``` ] .panel2-sw6-auto[ ``` ## # A tibble: 3 × 2 ## species `female mean age by species` ## <chr> <dbl> ## 1 Human 37.3 ## 2 Mirialan 49 ## 3 Twi'lek 48 ``` ] --- count: false .panel1-sw6-auto[ ``` r starwars %>% filter(gender == "feminine") %>% group_by(species) %>% na.omit() %>% summarise(mean(birth_year)) %>% rename(`female mean age by species` = `mean(birth_year)`) %>% * ungroup() ``` ] .panel2-sw6-auto[ ``` ## # A tibble: 3 × 2 ## species `female mean age by species` ## <chr> <dbl> ## 1 Human 37.3 ## 2 Mirialan 49 ## 3 Twi'lek 48 ``` ] --- count: false .panel1-sw6-auto[ ``` r starwars %>% filter(gender == "feminine") %>% group_by(species) %>% na.omit() %>% summarise(mean(birth_year)) %>% rename(`female mean age by species` = `mean(birth_year)`) %>% ungroup() %>% * na.omit() ``` ] .panel2-sw6-auto[ ``` ## # A tibble: 3 × 2 ## species `female mean age by species` ## <chr> <dbl> ## 1 Human 37.3 ## 2 Mirialan 49 ## 3 Twi'lek 48 ``` ] <style> .panel1-sw6-auto { color: white; width: 44.1%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw6-auto { color: white; width: 53.9%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw6-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- ## Measures of Spread **Sample Standard Deviation** count: false .panel1-sw7-auto[ ``` r *starwars ``` ] .panel2-sw7-auto[ ``` ## # A tibble: 87 × 14 ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw7-auto[ ``` r starwars %>% * group_by(species) ``` ] .panel2-sw7-auto[ ``` ## # A tibble: 87 × 14 ## # Groups: species [38] ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw7-auto[ ``` r starwars %>% group_by(species) %>% * na.omit() ``` ] .panel2-sw7-auto[ ``` ## # A tibble: 29 × 14 ## # Groups: species [11] ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 Darth V… 202 136 none white yellow 41.9 male mascu… ## 3 Leia Or… 150 49 brown light brown 19 fema… femin… ## 4 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 5 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 6 Biggs D… 183 84 black light brown 24 male mascu… ## 7 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## 8 Anakin … 188 84 blond fair blue 41.9 male mascu… ## 9 Chewbac… 228 112 brown unknown blue 200 male mascu… ## 10 Han Solo 180 80 brown fair brown 29 male mascu… ## # ℹ 19 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw7-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% * summarise(sd(birth_year)) ``` ] .panel2-sw7-auto[ ``` ## # A tibble: 11 × 2 ## species `sd(birth_year)` ## <chr> <dbl> ## 1 Cerean NA ## 2 Ewok NA ## 3 Gungan NA ## 4 Human 23.1 ## 5 Kel Dor NA ## 6 Mirialan 12.7 ## 7 Mon Calamari NA ## 8 Trandoshan NA ## 9 Twi'lek NA ## 10 Wookiee NA ## 11 Zabrak NA ``` ] --- count: false .panel1-sw7-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(sd(birth_year)) %>% * rename(`age standard deviation by species` = * `sd(birth_year)`) ``` ] .panel2-sw7-auto[ ``` ## # A tibble: 11 × 2 ## species `age standard deviation by species` ## <chr> <dbl> ## 1 Cerean NA ## 2 Ewok NA ## 3 Gungan NA ## 4 Human 23.1 ## 5 Kel Dor NA ## 6 Mirialan 12.7 ## 7 Mon Calamari NA ## 8 Trandoshan NA ## 9 Twi'lek NA ## 10 Wookiee NA ## 11 Zabrak NA ``` ] --- count: false .panel1-sw7-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(sd(birth_year)) %>% rename(`age standard deviation by species` = `sd(birth_year)`) %>% * ungroup() ``` ] .panel2-sw7-auto[ ``` ## # A tibble: 11 × 2 ## species `age standard deviation by species` ## <chr> <dbl> ## 1 Cerean NA ## 2 Ewok NA ## 3 Gungan NA ## 4 Human 23.1 ## 5 Kel Dor NA ## 6 Mirialan 12.7 ## 7 Mon Calamari NA ## 8 Trandoshan NA ## 9 Twi'lek NA ## 10 Wookiee NA ## 11 Zabrak NA ``` ] --- count: false .panel1-sw7-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(sd(birth_year)) %>% rename(`age standard deviation by species` = `sd(birth_year)`) %>% ungroup() %>% * na.omit() ``` ] .panel2-sw7-auto[ ``` ## # A tibble: 2 × 2 ## species `age standard deviation by species` ## <chr> <dbl> ## 1 Human 23.1 ## 2 Mirialan 12.7 ``` ] <style> .panel1-sw7-auto { color: white; width: 49%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw7-auto { color: white; width: 49%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw7-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- **Population Standard Deviation**<br><br> Reflecting common assumptions and practice, most descriptive statistics in R do not assume that you have an entire population. So you should ***always assume that you have a sample unless the description explicitly says otherwise***. When you do come across with a population, run the following first ``` r pop_sd <- function(x) sd(x) * (length(x)-1) / length(x) ``` ... --- ... and then calculate the population standard deviation count: false .panel1-sw8-auto[ ``` r *starwars ``` ] .panel2-sw8-auto[ ``` ## # A tibble: 87 × 14 ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw8-auto[ ``` r starwars %>% * group_by(species) ``` ] .panel2-sw8-auto[ ``` ## # A tibble: 87 × 14 ## # Groups: species [38] ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw8-auto[ ``` r starwars %>% group_by(species) %>% * na.omit() ``` ] .panel2-sw8-auto[ ``` ## # A tibble: 29 × 14 ## # Groups: species [11] ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 Darth V… 202 136 none white yellow 41.9 male mascu… ## 3 Leia Or… 150 49 brown light brown 19 fema… femin… ## 4 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 5 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 6 Biggs D… 183 84 black light brown 24 male mascu… ## 7 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## 8 Anakin … 188 84 blond fair blue 41.9 male mascu… ## 9 Chewbac… 228 112 brown unknown blue 200 male mascu… ## 10 Han Solo 180 80 brown fair brown 29 male mascu… ## # ℹ 19 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw8-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% * summarise(pop_sd(birth_year)) ``` ] .panel2-sw8-auto[ ``` ## # A tibble: 11 × 2 ## species `pop_sd(birth_year)` ## <chr> <dbl> ## 1 Cerean NA ## 2 Ewok NA ## 3 Gungan NA ## 4 Human 21.8 ## 5 Kel Dor NA ## 6 Mirialan 6.36 ## 7 Mon Calamari NA ## 8 Trandoshan NA ## 9 Twi'lek NA ## 10 Wookiee NA ## 11 Zabrak NA ``` ] --- count: false .panel1-sw8-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(pop_sd(birth_year)) %>% * rename(`age standard deviation by species` = * `pop_sd(birth_year)`) ``` ] .panel2-sw8-auto[ ``` ## # A tibble: 11 × 2 ## species `age standard deviation by species` ## <chr> <dbl> ## 1 Cerean NA ## 2 Ewok NA ## 3 Gungan NA ## 4 Human 21.8 ## 5 Kel Dor NA ## 6 Mirialan 6.36 ## 7 Mon Calamari NA ## 8 Trandoshan NA ## 9 Twi'lek NA ## 10 Wookiee NA ## 11 Zabrak NA ``` ] --- count: false .panel1-sw8-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(pop_sd(birth_year)) %>% rename(`age standard deviation by species` = `pop_sd(birth_year)`) %>% * ungroup() ``` ] .panel2-sw8-auto[ ``` ## # A tibble: 11 × 2 ## species `age standard deviation by species` ## <chr> <dbl> ## 1 Cerean NA ## 2 Ewok NA ## 3 Gungan NA ## 4 Human 21.8 ## 5 Kel Dor NA ## 6 Mirialan 6.36 ## 7 Mon Calamari NA ## 8 Trandoshan NA ## 9 Twi'lek NA ## 10 Wookiee NA ## 11 Zabrak NA ``` ] --- count: false .panel1-sw8-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(pop_sd(birth_year)) %>% rename(`age standard deviation by species` = `pop_sd(birth_year)`) %>% ungroup() %>% * na.omit() ``` ] .panel2-sw8-auto[ ``` ## # A tibble: 2 × 2 ## species `age standard deviation by species` ## <chr> <dbl> ## 1 Human 21.8 ## 2 Mirialan 6.36 ``` ] <style> .panel1-sw8-auto { color: white; width: 49%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw8-auto { color: white; width: 49%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw8-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- **Sample Variance** count: false .panel1-sw9-auto[ ``` r *starwars ``` ] .panel2-sw9-auto[ ``` ## # A tibble: 87 × 14 ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw9-auto[ ``` r starwars %>% * group_by(species) ``` ] .panel2-sw9-auto[ ``` ## # A tibble: 87 × 14 ## # Groups: species [38] ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw9-auto[ ``` r starwars %>% group_by(species) %>% * na.omit() ``` ] .panel2-sw9-auto[ ``` ## # A tibble: 29 × 14 ## # Groups: species [11] ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 Darth V… 202 136 none white yellow 41.9 male mascu… ## 3 Leia Or… 150 49 brown light brown 19 fema… femin… ## 4 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 5 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 6 Biggs D… 183 84 black light brown 24 male mascu… ## 7 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## 8 Anakin … 188 84 blond fair blue 41.9 male mascu… ## 9 Chewbac… 228 112 brown unknown blue 200 male mascu… ## 10 Han Solo 180 80 brown fair brown 29 male mascu… ## # ℹ 19 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw9-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% * summarise(var(birth_year)) ``` ] .panel2-sw9-auto[ ``` ## # A tibble: 11 × 2 ## species `var(birth_year)` ## <chr> <dbl> ## 1 Cerean NA ## 2 Ewok NA ## 3 Gungan NA ## 4 Human 533. ## 5 Kel Dor NA ## 6 Mirialan 162 ## 7 Mon Calamari NA ## 8 Trandoshan NA ## 9 Twi'lek NA ## 10 Wookiee NA ## 11 Zabrak NA ``` ] --- count: false .panel1-sw9-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(var(birth_year)) %>% * rename(`age variance by species` = * `var(birth_year)`) ``` ] .panel2-sw9-auto[ ``` ## # A tibble: 11 × 2 ## species `age variance by species` ## <chr> <dbl> ## 1 Cerean NA ## 2 Ewok NA ## 3 Gungan NA ## 4 Human 533. ## 5 Kel Dor NA ## 6 Mirialan 162 ## 7 Mon Calamari NA ## 8 Trandoshan NA ## 9 Twi'lek NA ## 10 Wookiee NA ## 11 Zabrak NA ``` ] --- count: false .panel1-sw9-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(var(birth_year)) %>% rename(`age variance by species` = `var(birth_year)`) %>% * ungroup() ``` ] .panel2-sw9-auto[ ``` ## # A tibble: 11 × 2 ## species `age variance by species` ## <chr> <dbl> ## 1 Cerean NA ## 2 Ewok NA ## 3 Gungan NA ## 4 Human 533. ## 5 Kel Dor NA ## 6 Mirialan 162 ## 7 Mon Calamari NA ## 8 Trandoshan NA ## 9 Twi'lek NA ## 10 Wookiee NA ## 11 Zabrak NA ``` ] --- count: false .panel1-sw9-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(var(birth_year)) %>% rename(`age variance by species` = `var(birth_year)`) %>% ungroup() %>% * na.omit() ``` ] .panel2-sw9-auto[ ``` ## # A tibble: 2 × 2 ## species `age variance by species` ## <chr> <dbl> ## 1 Human 533. ## 2 Mirialan 162 ``` ] <style> .panel1-sw9-auto { color: white; width: 49%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw9-auto { color: white; width: 49%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw9-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> <br> .pull-right[.footnote[You can find a list of commands that may be used with `summarise` [here](https://www.guru99.com/r-aggregate-function.html)]] --- **Population Variance**<br><br> Paralleling the arguement given about the population standard deviation, when you have a known population and want to find the variance, first run ``` r pop_var <- function(x) var(x) * (length(x)-1) / length(x) ``` ... --- ... and then you can calculate the population variance count: false .panel1-sw10-auto[ ``` r *starwars ``` ] .panel2-sw10-auto[ ``` ## # A tibble: 87 × 14 ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw10-auto[ ``` r starwars %>% * group_by(species) ``` ] .panel2-sw10-auto[ ``` ## # A tibble: 87 × 14 ## # Groups: species [38] ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw10-auto[ ``` r starwars %>% group_by(species) %>% * na.omit() ``` ] .panel2-sw10-auto[ ``` ## # A tibble: 29 × 14 ## # Groups: species [11] ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 Darth V… 202 136 none white yellow 41.9 male mascu… ## 3 Leia Or… 150 49 brown light brown 19 fema… femin… ## 4 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 5 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 6 Biggs D… 183 84 black light brown 24 male mascu… ## 7 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## 8 Anakin … 188 84 blond fair blue 41.9 male mascu… ## 9 Chewbac… 228 112 brown unknown blue 200 male mascu… ## 10 Han Solo 180 80 brown fair brown 29 male mascu… ## # ℹ 19 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw10-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% * summarise(pop_var(birth_year)) ``` ] .panel2-sw10-auto[ ``` ## # A tibble: 11 × 2 ## species `pop_var(birth_year)` ## <chr> <dbl> ## 1 Cerean NA ## 2 Ewok NA ## 3 Gungan NA ## 4 Human 504. ## 5 Kel Dor NA ## 6 Mirialan 81 ## 7 Mon Calamari NA ## 8 Trandoshan NA ## 9 Twi'lek NA ## 10 Wookiee NA ## 11 Zabrak NA ``` ] --- count: false .panel1-sw10-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(pop_var(birth_year)) %>% * rename(`age variance by species` = * `pop_var(birth_year)`) ``` ] .panel2-sw10-auto[ ``` ## # A tibble: 11 × 2 ## species `age variance by species` ## <chr> <dbl> ## 1 Cerean NA ## 2 Ewok NA ## 3 Gungan NA ## 4 Human 504. ## 5 Kel Dor NA ## 6 Mirialan 81 ## 7 Mon Calamari NA ## 8 Trandoshan NA ## 9 Twi'lek NA ## 10 Wookiee NA ## 11 Zabrak NA ``` ] --- count: false .panel1-sw10-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(pop_var(birth_year)) %>% rename(`age variance by species` = `pop_var(birth_year)`) %>% * ungroup() ``` ] .panel2-sw10-auto[ ``` ## # A tibble: 11 × 2 ## species `age variance by species` ## <chr> <dbl> ## 1 Cerean NA ## 2 Ewok NA ## 3 Gungan NA ## 4 Human 504. ## 5 Kel Dor NA ## 6 Mirialan 81 ## 7 Mon Calamari NA ## 8 Trandoshan NA ## 9 Twi'lek NA ## 10 Wookiee NA ## 11 Zabrak NA ``` ] --- count: false .panel1-sw10-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(pop_var(birth_year)) %>% rename(`age variance by species` = `pop_var(birth_year)`) %>% ungroup() %>% * na.omit() ``` ] .panel2-sw10-auto[ ``` ## # A tibble: 2 × 2 ## species `age variance by species` ## <chr> <dbl> ## 1 Human 504. ## 2 Mirialan 81 ``` ] <style> .panel1-sw10-auto { color: white; width: 44.1%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw10-auto { color: white; width: 53.9%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw10-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> .right[.footnote[
]] --- ### Side Note: More about Summarise You can find a list of commands that may be used with `summarise` [here](https://www.guru99.com/r-aggregate-function.html) .right[.footnote[
]] --- # Range **Maximum** count: false .panel1-sw11-auto[ ``` r *starwars ``` ] .panel2-sw11-auto[ ``` ## # A tibble: 87 × 14 ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw11-auto[ ``` r starwars %>% * group_by(species) ``` ] .panel2-sw11-auto[ ``` ## # A tibble: 87 × 14 ## # Groups: species [38] ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw11-auto[ ``` r starwars %>% group_by(species) %>% * na.omit() ``` ] .panel2-sw11-auto[ ``` ## # A tibble: 29 × 14 ## # Groups: species [11] ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 Darth V… 202 136 none white yellow 41.9 male mascu… ## 3 Leia Or… 150 49 brown light brown 19 fema… femin… ## 4 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 5 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 6 Biggs D… 183 84 black light brown 24 male mascu… ## 7 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## 8 Anakin … 188 84 blond fair blue 41.9 male mascu… ## 9 Chewbac… 228 112 brown unknown blue 200 male mascu… ## 10 Han Solo 180 80 brown fair brown 29 male mascu… ## # ℹ 19 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw11-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% * summarise(max(birth_year)) ``` ] .panel2-sw11-auto[ ``` ## # A tibble: 11 × 2 ## species `max(birth_year)` ## <chr> <dbl> ## 1 Cerean 92 ## 2 Ewok 8 ## 3 Gungan 52 ## 4 Human 102 ## 5 Kel Dor 22 ## 6 Mirialan 58 ## 7 Mon Calamari 41 ## 8 Trandoshan 53 ## 9 Twi'lek 48 ## 10 Wookiee 200 ## 11 Zabrak 54 ``` ] --- count: false .panel1-sw11-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(max(birth_year)) %>% * rename(`maximum age by species` = * `max(birth_year)`) ``` ] .panel2-sw11-auto[ ``` ## # A tibble: 11 × 2 ## species `maximum age by species` ## <chr> <dbl> ## 1 Cerean 92 ## 2 Ewok 8 ## 3 Gungan 52 ## 4 Human 102 ## 5 Kel Dor 22 ## 6 Mirialan 58 ## 7 Mon Calamari 41 ## 8 Trandoshan 53 ## 9 Twi'lek 48 ## 10 Wookiee 200 ## 11 Zabrak 54 ``` ] --- count: false .panel1-sw11-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(max(birth_year)) %>% rename(`maximum age by species` = `max(birth_year)`) %>% * ungroup() ``` ] .panel2-sw11-auto[ ``` ## # A tibble: 11 × 2 ## species `maximum age by species` ## <chr> <dbl> ## 1 Cerean 92 ## 2 Ewok 8 ## 3 Gungan 52 ## 4 Human 102 ## 5 Kel Dor 22 ## 6 Mirialan 58 ## 7 Mon Calamari 41 ## 8 Trandoshan 53 ## 9 Twi'lek 48 ## 10 Wookiee 200 ## 11 Zabrak 54 ``` ] --- count: false .panel1-sw11-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(max(birth_year)) %>% rename(`maximum age by species` = `max(birth_year)`) %>% ungroup() %>% * na.omit() ``` ] .panel2-sw11-auto[ ``` ## # A tibble: 11 × 2 ## species `maximum age by species` ## <chr> <dbl> ## 1 Cerean 92 ## 2 Ewok 8 ## 3 Gungan 52 ## 4 Human 102 ## 5 Kel Dor 22 ## 6 Mirialan 58 ## 7 Mon Calamari 41 ## 8 Trandoshan 53 ## 9 Twi'lek 48 ## 10 Wookiee 200 ## 11 Zabrak 54 ``` ] <style> .panel1-sw11-auto { color: white; width: 44.1%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw11-auto { color: white; width: 53.9%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw11-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- **Minimum** count: false .panel1-sw12-auto[ ``` r *starwars ``` ] .panel2-sw12-auto[ ``` ## # A tibble: 87 × 14 ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw12-auto[ ``` r starwars %>% * group_by(species) ``` ] .panel2-sw12-auto[ ``` ## # A tibble: 87 × 14 ## # Groups: species [38] ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw12-auto[ ``` r starwars %>% group_by(species) %>% * na.omit() ``` ] .panel2-sw12-auto[ ``` ## # A tibble: 29 × 14 ## # Groups: species [11] ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 Darth V… 202 136 none white yellow 41.9 male mascu… ## 3 Leia Or… 150 49 brown light brown 19 fema… femin… ## 4 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 5 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 6 Biggs D… 183 84 black light brown 24 male mascu… ## 7 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## 8 Anakin … 188 84 blond fair blue 41.9 male mascu… ## 9 Chewbac… 228 112 brown unknown blue 200 male mascu… ## 10 Han Solo 180 80 brown fair brown 29 male mascu… ## # ℹ 19 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw12-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% * summarise(min(birth_year)) ``` ] .panel2-sw12-auto[ ``` ## # A tibble: 11 × 2 ## species `min(birth_year)` ## <chr> <dbl> ## 1 Cerean 92 ## 2 Ewok 8 ## 3 Gungan 52 ## 4 Human 19 ## 5 Kel Dor 22 ## 6 Mirialan 40 ## 7 Mon Calamari 41 ## 8 Trandoshan 53 ## 9 Twi'lek 48 ## 10 Wookiee 200 ## 11 Zabrak 54 ``` ] --- count: false .panel1-sw12-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(min(birth_year)) %>% * rename(`minimum age by species` = * `min(birth_year)`) ``` ] .panel2-sw12-auto[ ``` ## # A tibble: 11 × 2 ## species `minimum age by species` ## <chr> <dbl> ## 1 Cerean 92 ## 2 Ewok 8 ## 3 Gungan 52 ## 4 Human 19 ## 5 Kel Dor 22 ## 6 Mirialan 40 ## 7 Mon Calamari 41 ## 8 Trandoshan 53 ## 9 Twi'lek 48 ## 10 Wookiee 200 ## 11 Zabrak 54 ``` ] --- count: false .panel1-sw12-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(min(birth_year)) %>% rename(`minimum age by species` = `min(birth_year)`) %>% * ungroup() ``` ] .panel2-sw12-auto[ ``` ## # A tibble: 11 × 2 ## species `minimum age by species` ## <chr> <dbl> ## 1 Cerean 92 ## 2 Ewok 8 ## 3 Gungan 52 ## 4 Human 19 ## 5 Kel Dor 22 ## 6 Mirialan 40 ## 7 Mon Calamari 41 ## 8 Trandoshan 53 ## 9 Twi'lek 48 ## 10 Wookiee 200 ## 11 Zabrak 54 ``` ] --- count: false .panel1-sw12-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(min(birth_year)) %>% rename(`minimum age by species` = `min(birth_year)`) %>% ungroup() %>% * na.omit() ``` ] .panel2-sw12-auto[ ``` ## # A tibble: 11 × 2 ## species `minimum age by species` ## <chr> <dbl> ## 1 Cerean 92 ## 2 Ewok 8 ## 3 Gungan 52 ## 4 Human 19 ## 5 Kel Dor 22 ## 6 Mirialan 40 ## 7 Mon Calamari 41 ## 8 Trandoshan 53 ## 9 Twi'lek 48 ## 10 Wookiee 200 ## 11 Zabrak 54 ``` ] <style> .panel1-sw12-auto { color: white; width: 44.1%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw12-auto { color: white; width: 53.9%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw12-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- **Range** count: false .panel1-sw13-auto[ ``` r *starwars ``` ] .panel2-sw13-auto[ ``` ## # A tibble: 87 × 14 ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw13-auto[ ``` r starwars %>% * group_by(species) ``` ] .panel2-sw13-auto[ ``` ## # A tibble: 87 × 14 ## # Groups: species [38] ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu… ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu… ## 4 Darth V… 202 136 none white yellow 41.9 male mascu… ## 5 Leia Or… 150 49 brown light brown 19 fema… femin… ## 6 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 7 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 8 R5-D4 97 32 <NA> white, red red NA none mascu… ## 9 Biggs D… 183 84 black light brown 24 male mascu… ## 10 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## # ℹ 77 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw13-auto[ ``` r starwars %>% group_by(species) %>% * na.omit() ``` ] .panel2-sw13-auto[ ``` ## # A tibble: 29 × 14 ## # Groups: species [11] ## name height mass hair_color skin_color eye_color birth_year sex gender ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> ## 1 Luke Sk… 172 77 blond fair blue 19 male mascu… ## 2 Darth V… 202 136 none white yellow 41.9 male mascu… ## 3 Leia Or… 150 49 brown light brown 19 fema… femin… ## 4 Owen La… 178 120 brown, gr… light blue 52 male mascu… ## 5 Beru Wh… 165 75 brown light blue 47 fema… femin… ## 6 Biggs D… 183 84 black light brown 24 male mascu… ## 7 Obi-Wan… 182 77 auburn, w… fair blue-gray 57 male mascu… ## 8 Anakin … 188 84 blond fair blue 41.9 male mascu… ## 9 Chewbac… 228 112 brown unknown blue 200 male mascu… ## 10 Han Solo 180 80 brown fair brown 29 male mascu… ## # ℹ 19 more rows ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>, ## # vehicles <list>, starships <list> ``` ] --- count: false .panel1-sw13-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% * summarise(max(birth_year), * min(birth_year)) ``` ] .panel2-sw13-auto[ ``` ## # A tibble: 11 × 3 ## species `max(birth_year)` `min(birth_year)` ## <chr> <dbl> <dbl> ## 1 Cerean 92 92 ## 2 Ewok 8 8 ## 3 Gungan 52 52 ## 4 Human 102 19 ## 5 Kel Dor 22 22 ## 6 Mirialan 58 40 ## 7 Mon Calamari 41 41 ## 8 Trandoshan 53 53 ## 9 Twi'lek 48 48 ## 10 Wookiee 200 200 ## 11 Zabrak 54 54 ``` ] --- count: false .panel1-sw13-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(max(birth_year), min(birth_year)) %>% * rename(`max` = `max(birth_year)`) ``` ] .panel2-sw13-auto[ ``` ## # A tibble: 11 × 3 ## species max `min(birth_year)` ## <chr> <dbl> <dbl> ## 1 Cerean 92 92 ## 2 Ewok 8 8 ## 3 Gungan 52 52 ## 4 Human 102 19 ## 5 Kel Dor 22 22 ## 6 Mirialan 58 40 ## 7 Mon Calamari 41 41 ## 8 Trandoshan 53 53 ## 9 Twi'lek 48 48 ## 10 Wookiee 200 200 ## 11 Zabrak 54 54 ``` ] --- count: false .panel1-sw13-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(max(birth_year), min(birth_year)) %>% rename(`max` = `max(birth_year)`) %>% * rename(`min` = `min(birth_year)`) ``` ] .panel2-sw13-auto[ ``` ## # A tibble: 11 × 3 ## species max min ## <chr> <dbl> <dbl> ## 1 Cerean 92 92 ## 2 Ewok 8 8 ## 3 Gungan 52 52 ## 4 Human 102 19 ## 5 Kel Dor 22 22 ## 6 Mirialan 58 40 ## 7 Mon Calamari 41 41 ## 8 Trandoshan 53 53 ## 9 Twi'lek 48 48 ## 10 Wookiee 200 200 ## 11 Zabrak 54 54 ``` ] --- count: false .panel1-sw13-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(max(birth_year), min(birth_year)) %>% rename(`max` = `max(birth_year)`) %>% rename(`min` = `min(birth_year)`) %>% * ungroup() ``` ] .panel2-sw13-auto[ ``` ## # A tibble: 11 × 3 ## species max min ## <chr> <dbl> <dbl> ## 1 Cerean 92 92 ## 2 Ewok 8 8 ## 3 Gungan 52 52 ## 4 Human 102 19 ## 5 Kel Dor 22 22 ## 6 Mirialan 58 40 ## 7 Mon Calamari 41 41 ## 8 Trandoshan 53 53 ## 9 Twi'lek 48 48 ## 10 Wookiee 200 200 ## 11 Zabrak 54 54 ``` ] --- count: false .panel1-sw13-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(max(birth_year), min(birth_year)) %>% rename(`max` = `max(birth_year)`) %>% rename(`min` = `min(birth_year)`) %>% ungroup() %>% * na.omit() ``` ] .panel2-sw13-auto[ ``` ## # A tibble: 11 × 3 ## species max min ## <chr> <dbl> <dbl> ## 1 Cerean 92 92 ## 2 Ewok 8 8 ## 3 Gungan 52 52 ## 4 Human 102 19 ## 5 Kel Dor 22 22 ## 6 Mirialan 58 40 ## 7 Mon Calamari 41 41 ## 8 Trandoshan 53 53 ## 9 Twi'lek 48 48 ## 10 Wookiee 200 200 ## 11 Zabrak 54 54 ``` ] --- count: false .panel1-sw13-auto[ ``` r starwars %>% group_by(species) %>% na.omit() %>% summarise(max(birth_year), min(birth_year)) %>% rename(`max` = `max(birth_year)`) %>% rename(`min` = `min(birth_year)`) %>% ungroup() %>% na.omit() %>% * mutate(`age range by species` = max - min) ``` ] .panel2-sw13-auto[ ``` ## # A tibble: 11 × 4 ## species max min `age range by species` ## <chr> <dbl> <dbl> <dbl> ## 1 Cerean 92 92 0 ## 2 Ewok 8 8 0 ## 3 Gungan 52 52 0 ## 4 Human 102 19 83 ## 5 Kel Dor 22 22 0 ## 6 Mirialan 58 40 18 ## 7 Mon Calamari 41 41 0 ## 8 Trandoshan 53 53 0 ## 9 Twi'lek 48 48 0 ## 10 Wookiee 200 200 0 ## 11 Zabrak 54 54 0 ``` ] <style> .panel1-sw13-auto { color: white; width: 44.1%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw13-auto { color: white; width: 53.9%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw13-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> .left[
] --- # Plots To start, we'll use the sample mean age for all of the species ``` r starwars_by_species <- starwars %>% group_by(species) %>% na.omit() %>% summarise(mean(birth_year)) %>% rename(`mean age` = `mean(birth_year)`) %>% ungroup() %>% arrange(`mean age`) ``` --- ### Side Note: R Graph Gallery Want some inspiration or just want to copy code? Good! Head over to [The R Graph Gallery](https://www.r-graph-gallery.com/) to see some examples of basic visualizations and plots you can do in R right now. .right[.footnote[
]] --- ## Bar Plot count: false .panel1-sw15-auto[ ``` r *ggplot(starwars_by_species, * aes(x = species, * y = `mean age`, * fill = `mean age`)) ``` ] .panel2-sw15-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw15_auto_01_output-1.png)<!-- --> ] --- count: false .panel1-sw15-auto[ ``` r ggplot(starwars_by_species, aes(x = species, y = `mean age`, fill = `mean age`)) + * geom_bar(stat='identity') ``` ] .panel2-sw15-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw15_auto_02_output-1.png)<!-- --> ] --- count: false .panel1-sw15-auto[ ``` r ggplot(starwars_by_species, aes(x = species, y = `mean age`, fill = `mean age`)) + geom_bar(stat='identity') + * scale_fill_gradient(low = "#d9534f", * high = "#428bca") ``` ] .panel2-sw15-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw15_auto_03_output-1.png)<!-- --> ] --- count: false .panel1-sw15-auto[ ``` r ggplot(starwars_by_species, aes(x = species, y = `mean age`, fill = `mean age`)) + geom_bar(stat='identity') + scale_fill_gradient(low = "#d9534f", high = "#428bca") + * theme_minimal() ``` ] .panel2-sw15-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw15_auto_04_output-1.png)<!-- --> ] --- count: false .panel1-sw15-auto[ ``` r ggplot(starwars_by_species, aes(x = species, y = `mean age`, fill = `mean age`)) + geom_bar(stat='identity') + scale_fill_gradient(low = "#d9534f", high = "#428bca") + theme_minimal() + * theme(axis.text.x = element_text(angle = 45)) ``` ] .panel2-sw15-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw15_auto_05_output-1.png)<!-- --> ] <style> .panel1-sw15-auto { color: white; width: 49%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw15-auto { color: white; width: 49%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw15-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- ## Ordered Bar Plot Use `reorder` to order the bars from least to greatest. count: false .panel1-sw16-auto[ ``` r *ggplot(starwars_by_species, * aes(x = reorder(species, * `mean age`), * y = `mean age`, * fill = `mean age`)) ``` ] .panel2-sw16-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw16_auto_01_output-1.png)<!-- --> ] --- count: false .panel1-sw16-auto[ ``` r ggplot(starwars_by_species, aes(x = reorder(species, `mean age`), y = `mean age`, fill = `mean age`)) + * geom_bar(stat='identity') ``` ] .panel2-sw16-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw16_auto_02_output-1.png)<!-- --> ] --- count: false .panel1-sw16-auto[ ``` r ggplot(starwars_by_species, aes(x = reorder(species, `mean age`), y = `mean age`, fill = `mean age`)) + geom_bar(stat='identity') + * scale_fill_gradient(low = "#d9534f", * high = "#428bca") ``` ] .panel2-sw16-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw16_auto_03_output-1.png)<!-- --> ] --- count: false .panel1-sw16-auto[ ``` r ggplot(starwars_by_species, aes(x = reorder(species, `mean age`), y = `mean age`, fill = `mean age`)) + geom_bar(stat='identity') + scale_fill_gradient(low = "#d9534f", high = "#428bca") + * theme_minimal() ``` ] .panel2-sw16-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw16_auto_04_output-1.png)<!-- --> ] --- count: false .panel1-sw16-auto[ ``` r ggplot(starwars_by_species, aes(x = reorder(species, `mean age`), y = `mean age`, fill = `mean age`)) + geom_bar(stat='identity') + scale_fill_gradient(low = "#d9534f", high = "#428bca") + theme_minimal() + * theme(axis.text.x = element_text(angle = 45)) ``` ] .panel2-sw16-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw16_auto_05_output-1.png)<!-- --> ] <style> .panel1-sw16-auto { color: white; width: 49%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw16-auto { color: white; width: 49%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw16-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- ### Side Note: The Other Direction Want greatest to least? Stick a `-` in front of `mean age by species` within `reorder()`. count: false .panel1-sw17-auto[ ``` r *ggplot(starwars_by_species, * aes(x = reorder(species, * -`mean age`), * y = `mean age`, * fill = `mean age`)) ``` ] .panel2-sw17-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw17_auto_01_output-1.png)<!-- --> ] --- count: false .panel1-sw17-auto[ ``` r ggplot(starwars_by_species, aes(x = reorder(species, -`mean age`), y = `mean age`, fill = `mean age`)) + * geom_bar(stat='identity') ``` ] .panel2-sw17-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw17_auto_02_output-1.png)<!-- --> ] --- count: false .panel1-sw17-auto[ ``` r ggplot(starwars_by_species, aes(x = reorder(species, -`mean age`), y = `mean age`, fill = `mean age`)) + geom_bar(stat='identity') + * scale_fill_gradient(low = "#d9534f", * high = "#428bca") ``` ] .panel2-sw17-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw17_auto_03_output-1.png)<!-- --> ] --- count: false .panel1-sw17-auto[ ``` r ggplot(starwars_by_species, aes(x = reorder(species, -`mean age`), y = `mean age`, fill = `mean age`)) + geom_bar(stat='identity') + scale_fill_gradient(low = "#d9534f", high = "#428bca") + * theme_minimal() ``` ] .panel2-sw17-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw17_auto_04_output-1.png)<!-- --> ] --- count: false .panel1-sw17-auto[ ``` r ggplot(starwars_by_species, aes(x = reorder(species, -`mean age`), y = `mean age`, fill = `mean age`)) + geom_bar(stat='identity') + scale_fill_gradient(low = "#d9534f", high = "#428bca") + theme_minimal() + * theme(axis.text.x = element_text(angle = 45)) ``` ] .panel2-sw17-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw17_auto_05_output-1.png)<!-- --> ] <style> .panel1-sw17-auto { color: white; width: 49%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw17-auto { color: white; width: 49%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw17-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> .right[.footnote[
]] --- ## Line Plot count: false .panel1-sw18-auto[ ``` r *ggplot(starwars_by_species, * aes(x = reorder(species, * `mean age`), * y = `mean age`, * group = 1, * color = `mean age`)) ``` ] .panel2-sw18-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw18_auto_01_output-1.png)<!-- --> ] --- count: false .panel1-sw18-auto[ ``` r ggplot(starwars_by_species, aes(x = reorder(species, `mean age`), y = `mean age`, group = 1, color = `mean age`)) + * geom_line(size = 1.5, * color = "#cccccc") ``` ] .panel2-sw18-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw18_auto_02_output-1.png)<!-- --> ] --- count: false .panel1-sw18-auto[ ``` r ggplot(starwars_by_species, aes(x = reorder(species, `mean age`), y = `mean age`, group = 1, color = `mean age`)) + geom_line(size = 1.5, color = "#cccccc") + * geom_point(size = 4) ``` ] .panel2-sw18-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw18_auto_03_output-1.png)<!-- --> ] --- count: false .panel1-sw18-auto[ ``` r ggplot(starwars_by_species, aes(x = reorder(species, `mean age`), y = `mean age`, group = 1, color = `mean age`)) + geom_line(size = 1.5, color = "#cccccc") + geom_point(size = 4) + * scale_color_gradient(low = "#d9534f", * high = "#428bca") ``` ] .panel2-sw18-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw18_auto_04_output-1.png)<!-- --> ] --- count: false .panel1-sw18-auto[ ``` r ggplot(starwars_by_species, aes(x = reorder(species, `mean age`), y = `mean age`, group = 1, color = `mean age`)) + geom_line(size = 1.5, color = "#cccccc") + geom_point(size = 4) + scale_color_gradient(low = "#d9534f", high = "#428bca") + * theme_minimal() ``` ] .panel2-sw18-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw18_auto_05_output-1.png)<!-- --> ] --- count: false .panel1-sw18-auto[ ``` r ggplot(starwars_by_species, aes(x = reorder(species, `mean age`), y = `mean age`, group = 1, color = `mean age`)) + geom_line(size = 1.5, color = "#cccccc") + geom_point(size = 4) + scale_color_gradient(low = "#d9534f", high = "#428bca") + theme_minimal() + * theme(axis.text.x = element_text(angle = 45, * vjust = 0.6, * hjust = 0.5), * axis.title.y = element_blank()) ``` ] .panel2-sw18-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw18_auto_06_output-1.png)<!-- --> ] --- count: false .panel1-sw18-auto[ ``` r ggplot(starwars_by_species, aes(x = reorder(species, `mean age`), y = `mean age`, group = 1, color = `mean age`)) + geom_line(size = 1.5, color = "#cccccc") + geom_point(size = 4) + scale_color_gradient(low = "#d9534f", high = "#428bca") + theme_minimal() + theme(axis.text.x = element_text(angle = 45, vjust = 0.6, hjust = 0.5), axis.title.y = element_blank()) + * labs(x = "species") ``` ] .panel2-sw18-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw18_auto_07_output-1.png)<!-- --> ] <style> .panel1-sw18-auto { color: white; width: 51.45%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw18-auto { color: white; width: 46.55%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw18-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- ## Pie Chart (Useless) count: false .panel1-sw19-auto[ ``` r *starwars_by_species ``` ] .panel2-sw19-auto[ ``` ## # A tibble: 11 × 2 ## species `mean age` ## <chr> <dbl> ## 1 Ewok 8 ## 2 Kel Dor 22 ## 3 Mon Calamari 41 ## 4 Human 45.5 ## 5 Twi'lek 48 ## 6 Mirialan 49 ## 7 Gungan 52 ## 8 Trandoshan 53 ## 9 Zabrak 54 ## 10 Cerean 92 ## 11 Wookiee 200 ``` ] --- count: false .panel1-sw19-auto[ ``` r starwars_by_species %>% * arrange(desc(`mean age`)) ``` ] .panel2-sw19-auto[ ``` ## # A tibble: 11 × 2 ## species `mean age` ## <chr> <dbl> ## 1 Wookiee 200 ## 2 Cerean 92 ## 3 Zabrak 54 ## 4 Trandoshan 53 ## 5 Gungan 52 ## 6 Mirialan 49 ## 7 Twi'lek 48 ## 8 Human 45.5 ## 9 Mon Calamari 41 ## 10 Kel Dor 22 ## 11 Ewok 8 ``` ] --- count: false .panel1-sw19-auto[ ``` r starwars_by_species %>% arrange(desc(`mean age`)) %>% * mutate(prop = `mean age` / * sum(starwars_by_species$`mean age`) * 100) ``` ] .panel2-sw19-auto[ ``` ## # A tibble: 11 × 3 ## species `mean age` prop ## <chr> <dbl> <dbl> ## 1 Wookiee 200 30.1 ## 2 Cerean 92 13.8 ## 3 Zabrak 54 8.13 ## 4 Trandoshan 53 7.98 ## 5 Gungan 52 7.83 ## 6 Mirialan 49 7.37 ## 7 Twi'lek 48 7.22 ## 8 Human 45.5 6.85 ## 9 Mon Calamari 41 6.17 ## 10 Kel Dor 22 3.31 ## 11 Ewok 8 1.20 ``` ] --- count: false .panel1-sw19-auto[ ``` r starwars_by_species %>% arrange(desc(`mean age`)) %>% mutate(prop = `mean age` / sum(starwars_by_species$`mean age`) * 100) %>% * mutate(ypos = cumsum(prop) - 0.5*prop) ``` ] .panel2-sw19-auto[ ``` ## # A tibble: 11 × 4 ## species `mean age` prop ypos ## <chr> <dbl> <dbl> <dbl> ## 1 Wookiee 200 30.1 15.0 ## 2 Cerean 92 13.8 37.0 ## 3 Zabrak 54 8.13 48.0 ## 4 Trandoshan 53 7.98 56.1 ## 5 Gungan 52 7.83 64.0 ## 6 Mirialan 49 7.37 71.6 ## 7 Twi'lek 48 7.22 78.9 ## 8 Human 45.5 6.85 85.9 ## 9 Mon Calamari 41 6.17 92.4 ## 10 Kel Dor 22 3.31 97.1 ## 11 Ewok 8 1.20 99.4 ``` ] --- count: false .panel1-sw19-auto[ ``` r starwars_by_species %>% arrange(desc(`mean age`)) %>% mutate(prop = `mean age` / sum(starwars_by_species$`mean age`) * 100) %>% mutate(ypos = cumsum(prop) - 0.5*prop) %>% *ggplot(aes(x = "", * y = prop, * fill = `mean age`)) ``` ] .panel2-sw19-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw19_auto_05_output-1.png)<!-- --> ] --- count: false .panel1-sw19-auto[ ``` r starwars_by_species %>% arrange(desc(`mean age`)) %>% mutate(prop = `mean age` / sum(starwars_by_species$`mean age`) * 100) %>% mutate(ypos = cumsum(prop) - 0.5*prop) %>% ggplot(aes(x = "", y = prop, fill = `mean age`)) + * geom_bar(stat = "identity", * width = 1, * color = "white") ``` ] .panel2-sw19-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw19_auto_06_output-1.png)<!-- --> ] --- count: false .panel1-sw19-auto[ ``` r starwars_by_species %>% arrange(desc(`mean age`)) %>% mutate(prop = `mean age` / sum(starwars_by_species$`mean age`) * 100) %>% mutate(ypos = cumsum(prop) - 0.5*prop) %>% ggplot(aes(x = "", y = prop, fill = `mean age`)) + geom_bar(stat = "identity", width = 1, color = "white") + * coord_polar("y", start = 0) ``` ] .panel2-sw19-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw19_auto_07_output-1.png)<!-- --> ] --- count: false .panel1-sw19-auto[ ``` r starwars_by_species %>% arrange(desc(`mean age`)) %>% mutate(prop = `mean age` / sum(starwars_by_species$`mean age`) * 100) %>% mutate(ypos = cumsum(prop) - 0.5*prop) %>% ggplot(aes(x = "", y = prop, fill = `mean age`)) + geom_bar(stat = "identity", width = 1, color = "white") + coord_polar("y", start = 0) + * geom_label(aes(y = ypos, * label = `species`), * color = "white", * size = 6, * show.legend = FALSE) ``` ] .panel2-sw19-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw19_auto_08_output-1.png)<!-- --> ] --- count: false .panel1-sw19-auto[ ``` r starwars_by_species %>% arrange(desc(`mean age`)) %>% mutate(prop = `mean age` / sum(starwars_by_species$`mean age`) * 100) %>% mutate(ypos = cumsum(prop) - 0.5*prop) %>% ggplot(aes(x = "", y = prop, fill = `mean age`)) + geom_bar(stat = "identity", width = 1, color = "white") + coord_polar("y", start = 0) + geom_label(aes(y = ypos, label = `species`), color = "white", size = 6, show.legend = FALSE) + * scale_fill_gradient(low = "#d9534f", * high = "#428bca") ``` ] .panel2-sw19-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw19_auto_09_output-1.png)<!-- --> ] --- count: false .panel1-sw19-auto[ ``` r starwars_by_species %>% arrange(desc(`mean age`)) %>% mutate(prop = `mean age` / sum(starwars_by_species$`mean age`) * 100) %>% mutate(ypos = cumsum(prop) - 0.5*prop) %>% ggplot(aes(x = "", y = prop, fill = `mean age`)) + geom_bar(stat = "identity", width = 1, color = "white") + coord_polar("y", start = 0) + geom_label(aes(y = ypos, label = `species`), color = "white", size = 6, show.legend = FALSE) + scale_fill_gradient(low = "#d9534f", high = "#428bca") + * theme_void() ``` ] .panel2-sw19-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw19_auto_10_output-1.png)<!-- --> ] --- count: false .panel1-sw19-auto[ ``` r starwars_by_species %>% arrange(desc(`mean age`)) %>% mutate(prop = `mean age` / sum(starwars_by_species$`mean age`) * 100) %>% mutate(ypos = cumsum(prop) - 0.5*prop) %>% ggplot(aes(x = "", y = prop, fill = `mean age`)) + geom_bar(stat = "identity", width = 1, color = "white") + coord_polar("y", start = 0) + geom_label(aes(y = ypos, label = `species`), color = "white", size = 6, show.legend = FALSE) + scale_fill_gradient(low = "#d9534f", high = "#428bca") + theme_void() ``` ] .panel2-sw19-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw19_auto_11_output-1.png)<!-- --> ] <style> .panel1-sw19-auto { color: white; width: 49%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw19-auto { color: white; width: 49%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw19-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- ## Filtered Pie Chart (A Little Less Useless) count: false .panel1-sw20-auto[ ``` r *starwars_by_species ``` ] .panel2-sw20-auto[ ``` ## # A tibble: 11 × 2 ## species `mean age` ## <chr> <dbl> ## 1 Ewok 8 ## 2 Kel Dor 22 ## 3 Mon Calamari 41 ## 4 Human 45.5 ## 5 Twi'lek 48 ## 6 Mirialan 49 ## 7 Gungan 52 ## 8 Trandoshan 53 ## 9 Zabrak 54 ## 10 Cerean 92 ## 11 Wookiee 200 ``` ] --- count: false .panel1-sw20-auto[ ``` r starwars_by_species %>% * filter(species %in% c("Human", * "Twi'lek", * "Mon Calamari", * "Wookiee")) ``` ] .panel2-sw20-auto[ ``` ## # A tibble: 4 × 2 ## species `mean age` ## <chr> <dbl> ## 1 Mon Calamari 41 ## 2 Human 45.5 ## 3 Twi'lek 48 ## 4 Wookiee 200 ``` ] --- count: false .panel1-sw20-auto[ ``` r starwars_by_species %>% filter(species %in% c("Human", "Twi'lek", "Mon Calamari", "Wookiee")) %>% * arrange(desc(`mean age`)) ``` ] .panel2-sw20-auto[ ``` ## # A tibble: 4 × 2 ## species `mean age` ## <chr> <dbl> ## 1 Wookiee 200 ## 2 Twi'lek 48 ## 3 Human 45.5 ## 4 Mon Calamari 41 ``` ] --- count: false .panel1-sw20-auto[ ``` r starwars_by_species %>% filter(species %in% c("Human", "Twi'lek", "Mon Calamari", "Wookiee")) %>% arrange(desc(`mean age`)) %>% * mutate(prop = `mean age` / * sum(starwars_by_species$`mean age`) *100) ``` ] .panel2-sw20-auto[ ``` ## # A tibble: 4 × 3 ## species `mean age` prop ## <chr> <dbl> <dbl> ## 1 Wookiee 200 30.1 ## 2 Twi'lek 48 7.22 ## 3 Human 45.5 6.85 ## 4 Mon Calamari 41 6.17 ``` ] --- count: false .panel1-sw20-auto[ ``` r starwars_by_species %>% filter(species %in% c("Human", "Twi'lek", "Mon Calamari", "Wookiee")) %>% arrange(desc(`mean age`)) %>% mutate(prop = `mean age` / sum(starwars_by_species$`mean age`) *100) %>% * mutate(ypos = cumsum(prop)- 0.5*prop) ``` ] .panel2-sw20-auto[ ``` ## # A tibble: 4 × 4 ## species `mean age` prop ypos ## <chr> <dbl> <dbl> <dbl> ## 1 Wookiee 200 30.1 15.0 ## 2 Twi'lek 48 7.22 33.7 ## 3 Human 45.5 6.85 40.7 ## 4 Mon Calamari 41 6.17 47.3 ``` ] --- count: false .panel1-sw20-auto[ ``` r starwars_by_species %>% filter(species %in% c("Human", "Twi'lek", "Mon Calamari", "Wookiee")) %>% arrange(desc(`mean age`)) %>% mutate(prop = `mean age` / sum(starwars_by_species$`mean age`) *100) %>% mutate(ypos = cumsum(prop)- 0.5*prop) %>% *ggplot(aes(x = "", * y = prop)) ``` ] .panel2-sw20-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw20_auto_06_output-1.png)<!-- --> ] --- count: false .panel1-sw20-auto[ ``` r starwars_by_species %>% filter(species %in% c("Human", "Twi'lek", "Mon Calamari", "Wookiee")) %>% arrange(desc(`mean age`)) %>% mutate(prop = `mean age` / sum(starwars_by_species$`mean age`) *100) %>% mutate(ypos = cumsum(prop)- 0.5*prop) %>% ggplot(aes(x = "", y = prop)) + * geom_bar(aes(fill = `mean age`), * stat = "identity", * width = 1, * color = "white") ``` ] .panel2-sw20-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw20_auto_07_output-1.png)<!-- --> ] --- count: false .panel1-sw20-auto[ ``` r starwars_by_species %>% filter(species %in% c("Human", "Twi'lek", "Mon Calamari", "Wookiee")) %>% arrange(desc(`mean age`)) %>% mutate(prop = `mean age` / sum(starwars_by_species$`mean age`) *100) %>% mutate(ypos = cumsum(prop)- 0.5*prop) %>% ggplot(aes(x = "", y = prop)) + geom_bar(aes(fill = `mean age`), stat = "identity", width = 1, color = "white") + * coord_polar("y", start = 0) ``` ] .panel2-sw20-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw20_auto_08_output-1.png)<!-- --> ] --- count: false .panel1-sw20-auto[ ``` r starwars_by_species %>% filter(species %in% c("Human", "Twi'lek", "Mon Calamari", "Wookiee")) %>% arrange(desc(`mean age`)) %>% mutate(prop = `mean age` / sum(starwars_by_species$`mean age`) *100) %>% mutate(ypos = cumsum(prop)- 0.5*prop) %>% ggplot(aes(x = "", y = prop)) + geom_bar(aes(fill = `mean age`), stat = "identity", width = 1, color = "white") + coord_polar("y", start = 0) + * geom_label(aes(y = ypos, * label = paste0(`species`, * " (", round(prop, 0), "%)"), * color = "white", * size = 6), * show.legend = FALSE) ``` ] .panel2-sw20-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw20_auto_09_output-1.png)<!-- --> ] --- count: false .panel1-sw20-auto[ ``` r starwars_by_species %>% filter(species %in% c("Human", "Twi'lek", "Mon Calamari", "Wookiee")) %>% arrange(desc(`mean age`)) %>% mutate(prop = `mean age` / sum(starwars_by_species$`mean age`) *100) %>% mutate(ypos = cumsum(prop)- 0.5*prop) %>% ggplot(aes(x = "", y = prop)) + geom_bar(aes(fill = `mean age`), stat = "identity", width = 1, color = "white") + coord_polar("y", start = 0) + geom_label(aes(y = ypos, label = paste0(`species`, " (", round(prop, 0), "%)"), color = "white", size = 6), show.legend = FALSE) + * scale_fill_gradient(low = "#d9534f", * high = "#428bca") ``` ] .panel2-sw20-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw20_auto_10_output-1.png)<!-- --> ] --- count: false .panel1-sw20-auto[ ``` r starwars_by_species %>% filter(species %in% c("Human", "Twi'lek", "Mon Calamari", "Wookiee")) %>% arrange(desc(`mean age`)) %>% mutate(prop = `mean age` / sum(starwars_by_species$`mean age`) *100) %>% mutate(ypos = cumsum(prop)- 0.5*prop) %>% ggplot(aes(x = "", y = prop)) + geom_bar(aes(fill = `mean age`), stat = "identity", width = 1, color = "white") + coord_polar("y", start = 0) + geom_label(aes(y = ypos, label = paste0(`species`, " (", round(prop, 0), "%)"), color = "white", size = 6), show.legend = FALSE) + scale_fill_gradient(low = "#d9534f", high = "#428bca") + * theme_void() ``` ] .panel2-sw20-auto[ ![](Descriptive-statistics-in-R_files/figure-html/sw20_auto_11_output-1.png)<!-- --> ] <style> .panel1-sw20-auto { color: white; width: 53.9%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw20-auto { color: white; width: 44.1%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw20-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> .right[.footnote[
]] --- ## Thats it!