layout: true
knitr::opts_chunk$set(echo = TRUE, message = FALSE, error = FALSE, warning = FALSE) # These are the defaults xaringanExtra::use_extra_styles( hover_code_line = TRUE, #<< mute_unhighlighted_code = TRUE #<< ) library(knitr) library(tidyquintro) library(countdown)
class: dark, center background-image: url(img/ggplot2.png), url(img/dplyr.png), url(img/pipe.png) background-size: 15% background-position: 32% 65%, 50% 65%, 68% 65%
class: middle, inverse
|>
(~10 min)background-image: url(img/ggplot2.png) background-size: 8% background-position: 95% 5% name: ggplot
background-image: url(img/ggplot2.png) background-size: 8% background-position: 95% 5%
.pull-left[
ggplot(data = penguins, mapping = aes(x = bill_length_mm)) + geom_histogram( fill = "forestgreen" #<< )
]
.pull-right[
]
background-image: url(img/ggplot2.png) background-size: 8% background-position: 95% 5%
.pull-left[
ggplot(data = penguins, mapping = aes(x = bill_length_mm, fill = species)) + #<< geom_histogram( )
]
.pull-right[
]
class: inverse, middle, center
class: inverse, middle, center
learnr::run_tutorial("001-plotting", "tidyquintro")
countdown(minutes = 8, left = 0, right = 0, top = "50%", padding = "50px", margin = "10%", font_size = "4em", color_running_background = "transparent", color_finished_background = "#ffffff", play_sound = TRUE, warn_when = 30)
class: dark, middle, center background-image: url(img/dplyr.png) background-size: 15% background-position: 50% 95% name: dplyr-subset
background-image: url(img/dplyr.png) background-size: 8% background-position: 95% 5%
provides a consistent set of verbs that help you solve the most common data manipulation challenges:
mutate()
- adds or alters variables that are functions of existing variables
summarise()
reduces multiple values down to a single summary.
arrange()
changes the ordering of the rows.
background-image: url(img/dplyr.png) background-size: 8% background-position: 95% 5% name: filter
.pull-left[
filter()
- subsetting rowsReducing the number of rows in a data sat based on some logic.
filter()
evaluates a statement to be logical (TRUE
or FALSE
)--
.pull-right[
knitr::include_graphics("gifs/filtering.gif")
]
background-image: url(img/dplyr.png) background-size: 8% background-position: 95% 5%
filter(penguins, bill_length_mm > 40)
penguins[penguins$bill_length_mm > 40, ] # or subset(penguins, bill_length_mm > 40)
class: inverse, middle, center
background-image: url(img/dplyr.png) background-size: 8% background-position: 95% 5% name: select
.pull-left[
select()
- reduce columnsReducing the number of columns (or rearranging columns) Can be used with column names, index integer, or tidyselect-functions
tidy-select helpers
- ends_with("string")
- column names ending with "string"
- starts_with("string")
- column names starting with "string"
- contains("string")
- column names containing "string"
]
--
.pull-right[
knitr::include_graphics("gifs/selecting.gif")
]
background-image: url(img/dplyr.png) background-size: 8% background-position: 95% 5%
select(penguins, species, island, ends_with("mm"))
penguins[c(1, 2, grep("mm$", names(penguins)))] # or subset(penguins, select = c("species", "island", "bill_length_mm", "bill_depth_mm", "flipper_length_mm"))
class: inverse, middle, center
class: inverse, middle, center
learnr::run_tutorial("002-subsetting", "tidyquintro")
countdown(minutes = 8, left = 0, right = 0, top = "50%", play_sound = TRUE, warn_when = 30)
class: dark, center background-image: url(img/pipe.png) background-size: 15% background-position: 50% 65% name: pipe
background-image: url(img/pipe.png) background-size: 8% background-position: 95% 5%
sending the output from one function, straight into another, without saving the intermediary
Only really work when input is the first command to a function
This is not the case for most base-R functions, but is always the case with tidyverse functions
The common used pipe in R, |>
, originally comes from the magrittr package, but also comes with dplyr
??? arguably, in tidyverse the chaining of commands is one of the things that makes it most powerful. Chaining commands is a common programming concept, where you send the output of one command directly into another, without saving the intermediary. This saves you from overcrowding your workspace with lots of new objects you will never use. It is commonly referred to as a "pipe" and in R the common pipe is |>
background-image: url(img/pipe.png) background-size: 8% background-position: 95% 5%
.pull-left[
# standard select(penguins, species, island, ends_with("mm"))
# piped penguins |> select(species, island, ends_with("mm"))
]
.pull-right[
]
class: inverse, middle, center
class: inverse, middle, center
learnr::run_tutorial("003-chaining", "tidyquintro")
countdown(minutes = 8, left = 0, right = 0, top = "50%", play_sound = TRUE, warn_when = 30)
class: dark, center background-image: url(img/dplyr.png) background-size: 15% background-position: 50% 65% name: dplyr-mutate
background-image: url(img/dplyr.png) background-size: 8% background-position: 95% 5%
provides a consistent set of verbs that help you solve the most common data manipulation challenges:
select()
picks variables based on their names.
filter()
picks cases based on their values.
mutate()
- adds or alters variables that are functions of existing variablessummarise()
reduces multiple values down to a single summary.arrange()
changes the ordering of the rows.
background-image: url(img/dplyr.png) background-size: 8% background-position: 95% 5%
penguins |> mutate( new_column = 1, bill_ld_ratio = bill_length_mm/bill_depth_mm )
penguins$new_column <- 1 penguins$bill_ld_ratio <- penguins$bill_length_mm/penguins$bill_depth_mm
class: inverse, middle, center
class: inverse, middle, center
learnr::run_tutorial("004-mutating", "tidyquintro")
countdown(minutes = 8, left = 0, right = 0, top = "50%", play_sound = TRUE, warn_when = 30)
class: dark, middle, center
countdown(minutes = 30, left = 0, right = 0, top = "50%", play_sound = TRUE, color_running_text = "white", warn_when = 5*60)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.