diff --git a/slides/warm-up.Rmd b/slides/warm-up.Rmd index 1159d2f..6febe0d 100644 --- a/slides/warm-up.Rmd +++ b/slides/warm-up.Rmd @@ -229,33 +229,16 @@ What are the names of our three little pigs? (Pardon the reference) Display them as a character vector. ---- - -# Solution 3 - -```{r eval = FALSE} -seattle_pets |> - filter(species == "Pig") |> - pull(animal_name) -``` - - -```{r echo = FALSE, message = FALSE} -seattle_pets |> - filter(species == "Pig") |> - pull(animal_name) -``` - --- class: your-turn -# Your Turn 4 +# Your Turn 3 What is the most popular pet name in this data set? *Hint* Look up the help documentation for `slice_max()` from dplyr. --- -# Solution 4 +# Solution 3 ```{r eval = FALSE} seattle_pets |> @@ -275,13 +258,13 @@ seattle_pets |> --- class: your-turn -# Your Turn 5 +# Your Turn 4 How many different primary dog breeds are there? --- -# Solution 5 +# Solution 4 .pull-left[ @@ -317,13 +300,13 @@ seattle_pets |> --- class: your-turn -# Your Turn 6 +# Your Turn 5 Let's narrow this down -- what are the top 10 most popular dog breeds? --- -# Solution 6 +# Solution 5 ```{r eval=FALSE} seattle_pets |> @@ -342,7 +325,7 @@ seattle_pets |> --- class: your-turn -# Your Turn 7 -- last one! +# Your Turn 6 -- last one! Visualize the top 10 dog breeds in a bar chart. @@ -375,7 +358,7 @@ seattle_pets |> --- -# Solution 7 +# Solution 6 .pull-left[ @@ -405,9 +388,9 @@ seattle_pets |> ] --- -class: blue, middle, center +class: inverse, middle, center -# .big-text.white[Nice work! `r emo::ji("rocket")`] +# Nice work! --- @@ -448,11 +431,14 @@ We would need to handle **dates**. seattle_pets |> mutate( license_issue_date = mdy(license_issue_date), - month = month(license_issue_date, label = TRUE) + month = month(license_issue_date, label = TRUE), + year = year(license_issue_date) ) |> + group_by(month, year) |> + summarize(n = n()) |> group_by(month) |> - count() |> - ggplot(aes(month, n, group = 1)) + + summarize(mean_licenses = mean(n)) |> + ggplot(aes(month, mean_licenses, group = 1)) + geom_point() + geom_line() ``` diff --git a/slides/warm-up.html b/slides/warm-up.html index c57fd70..f8c415d 100644 --- a/slides/warm-up.html +++ b/slides/warm-up.html @@ -114,13 +114,13 @@ ``` ## Rows: 43,683 ## Columns: 7 -## $ license_issue_date <chr> "December 18 2015", "June 14 2016", "August 04 2016", "February 13 2019", "August 10 2019", "November … -## $ license_number <chr> "S107948", "S116503", "S119301", "962273", "S133113", "8002549", "S112835", "S131986", "S112996", "S14… -## $ animal_name <chr> "Zen", "Misty", "Lyra", "Veronica", "Spider", "Maxx", "Diamond", "Nacho", "Pixel", "C.C.", "Gemma", "O… -## $ species <chr> "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat… -## $ primary_breed <chr> "Domestic Longhair", "Siberian", "Mix", "Domestic Longhair", "LaPerm", "American Shorthair", "Domestic… -## $ secondary_breed <chr> "Mix", NA, NA, NA, NA, NA, "Mix", "Mix", "Mix", "Mix", "American Shorthair", "Mix", NA, NA, "Mix", NA,… -## $ zip_code <dbl> 98117, 98117, 98121, 98107, 98115, 98125, 98103, 98126, 98112, 98117, 98126, 98199, 98115, 98116, 9813… +## $ license_issue_date <chr> "December 18 2015", "June 14 2016", "August 04 2016", "February 13 2019", "August 10 2019", "November … +## $ license_number <chr> "S107948", "S116503", "S119301", "962273", "S133113", "8002549", "S112835", "S131986", "S112996", "S14… +## $ animal_name <chr> "Zen", "Misty", "Lyra", "Veronica", "Spider", "Maxx", "Diamond", "Nacho", "Pixel", "C.C.", "Gemma", "O… +## $ species <chr> "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat… +## $ primary_breed <chr> "Domestic Longhair", "Siberian", "Mix", "Domestic Longhair", "LaPerm", "American Shorthair", "Domestic… +## $ secondary_breed <chr> "Mix", NA, NA, NA, NA, NA, "Mix", "Mix", "Mix", "Mix", "American Shorthair", "Mix", NA, NA, "Mix", NA,… +## $ zip_code <dbl> 98117, 98117, 98121, 98107, 98115, 98125, 98103, 98126, 98112, 98117, 98126, 98199, 98115, 98116, 9813… ``` @@ -141,13 +141,13 @@ ``` ## Rows: 43,683 ## Columns: 7 -## $ license_issue_date <chr> "December 18 2015", "June 14 2016", "August 04 2016", "February 13 2019", "August 10 2019", "November … -## $ license_number <chr> "S107948", "S116503", "S119301", "962273", "S133113", "8002549", "S112835", "S131986", "S112996", "S14… -## $ animal_name <chr> "Zen", "Misty", "Lyra", "Veronica", "Spider", "Maxx", "Diamond", "Nacho", "Pixel", "C.C.", "Gemma", "O… -## $ species <chr> "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat… -## $ primary_breed <chr> "Domestic Longhair", "Siberian", "Mix", "Domestic Longhair", "LaPerm", "American Shorthair", "Domestic… -## $ secondary_breed <chr> "Mix", NA, NA, NA, NA, NA, "Mix", "Mix", "Mix", "Mix", "American Shorthair", "Mix", NA, NA, "Mix", NA,… -## $ zip_code <dbl> 98117, 98117, 98121, 98107, 98115, 98125, 98103, 98126, 98112, 98117, 98126, 98199, 98115, 98116, 9813… +## $ license_issue_date <chr> "December 18 2015", "June 14 2016", "August 04 2016", "February 13 2019", "August 10 2019", "November … +## $ license_number <chr> "S107948", "S116503", "S119301", "962273", "S133113", "8002549", "S112835", "S131986", "S112996", "S14… +## $ animal_name <chr> "Zen", "Misty", "Lyra", "Veronica", "Spider", "Maxx", "Diamond", "Nacho", "Pixel", "C.C.", "Gemma", "O… +## $ species <chr> "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat", "Cat… +## $ primary_breed <chr> "Domestic Longhair", "Siberian", "Mix", "Domestic Longhair", "LaPerm", "American Shorthair", "Domestic… +## $ secondary_breed <chr> "Mix", NA, NA, NA, NA, NA, "Mix", "Mix", "Mix", "Mix", "American Shorthair", "Mix", NA, NA, "Mix", NA,… +## $ zip_code <dbl> 98117, 98117, 98121, 98107, 98115, 98125, 98103, 98126, 98112, 98117, 98126, 98199, 98115, 98116, 9813… ``` --- @@ -201,33 +201,16 @@ Display them as a character vector. ---- - -# Solution 3 - - -```r -seattle_pets |> - filter(species == "Pig") |> - pull(animal_name) -``` - - - -``` -## [1] "Millie" "Calvin" "Waffles Olivia McHart" -``` - --- class: your-turn -# Your Turn 4 +# Your Turn 3 What is the most popular pet name in this data set? *Hint* Look up the help documentation for `slice_max()` from dplyr. --- -# Solution 4 +# Solution 3 ```r @@ -246,13 +229,13 @@ --- class: your-turn -# Your Turn 5 +# Your Turn 4 How many different primary dog breeds are there? --- -# Solution 5 +# Solution 4 .pull-left[ @@ -288,13 +271,13 @@ --- class: your-turn -# Your Turn 6 +# Your Turn 5 Let's narrow this down -- what are the top 10 most popular dog breeds? --- -# Solution 6 +# Solution 5 ```r @@ -324,7 +307,7 @@ --- class: your-turn -# Your Turn 7 -- last one! +# Your Turn 6 -- last one! Visualize the top 10 dog breeds in a bar chart. @@ -344,13 +327,13 @@ ] .pull-right[ -<img src="warm-up_files/figure-html/unnamed-chunk-18-1.png" width="80%" /> +<img src="warm-up_files/figure-html/unnamed-chunk-16-1.png" width="80%" /> ] --- -# Solution 7 +# Solution 6 .pull-left[ @@ -368,14 +351,14 @@ ] .pull-right[ -<img src="warm-up_files/figure-html/unnamed-chunk-20-1.png" width="80%" /> +<img src="warm-up_files/figure-html/unnamed-chunk-18-1.png" width="80%" /> ] --- -class: blue, middle, center +class: inverse, middle, center -# .big-text.white[Nice work! 🚀] +# Nice work! --- @@ -388,7 +371,7 @@ ] .pull-right[ -<img src="warm-up_files/figure-html/unnamed-chunk-21-1.png" width="90%" /> +<img src="warm-up_files/figure-html/unnamed-chunk-19-1.png" width="90%" /> ] @@ -403,7 +386,12 @@ .pull-right[ -<img src="warm-up_files/figure-html/unnamed-chunk-22-1.png" width="90%" /> + +``` +## `summarise()` has grouped output by 'month'. You can override using the `.groups` argument. +``` + +<img src="warm-up_files/figure-html/unnamed-chunk-20-1.png" width="90%" /> ] @@ -457,6 +445,7 @@ Fortunately, the tidyverse provides us with tools to work with these different types of data... <br> + .center[ <img src="https://github.com/rstudio/hex-stickers/blob/main/PNG/stringr.png?raw=true" width="25%" /><img src="https://github.com/rstudio/hex-stickers/blob/main/PNG/forcats.png?raw=true" width="25%" /><img src="https://github.com/rstudio/hex-stickers/blob/main/PNG/lubridate.png?raw=true" width="25%" />