A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data...
Transcript of A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data...
![Page 2: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/2.jpg)
Aimee Gott – Senior Consultant
In This Workshop
• You will learn…
• What the tidyverse is & why bother using it
• What tools are available in the tidyverse
• A brief overview of core functionality
![Page 3: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/3.jpg)
Aimee Gott – Senior Consultant
Data for Today
• Funding of Olympic sports
• UK Sport World Class Performance Programme
• Data from Sydney (2000) to Rio de Janeiro (2016)
• Extracted from
http://www.uksport.gov.uk/our-work/investing-in-
sport/historical-funding-figures
![Page 4: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/4.jpg)
Aimee Gott – Senior Consultant
Where to Get the Data
Files in multiple formats available on GitHub:
https://github.com/MangoTheCat/Olympic-Funding-
Data
![Page 6: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/6.jpg)
Aimee Gott – Senior Consultant
Unified Packages
• Set of unified packages covering the data
analysis workflow
• Implementing a single philosophy
• Makes it easy to learn and use!
![Page 7: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/7.jpg)
Aimee Gott – Senior Consultant
Import Tidy
Model
CommunicateTransform
Visualise
Program
![Page 8: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/8.jpg)
Aimee Gott – Senior Consultant
Useful Resouces
RStudio Cheat Sheets
https://www.rstudio.com/resources/cheatsheets/
(My advice – print them all and keep them on your desk!)
![Page 9: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/9.jpg)
Aimee Gott – Senior Consultant
Further Reading
R for Data Science (2017), Hadley Wickham &
Garrett Grolemund, O'Reilly
Available online:
http://r4ds.had.co.nz/
![Page 11: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/11.jpg)
Aimee Gott – Senior Consultant
What are the Packages?
• 18 Core Packages
• Loads more dependencies
• 6 Packages loaded with Tidyverse
• All others installed and available
![Page 12: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/12.jpg)
Aimee Gott – Senior Consultant
Packages Loaded By Default
• ggplot2
• dplyr
• tidyr
• readr
• purrr
• tibble
![Page 13: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/13.jpg)
Aimee Gott – Senior Consultant
Other Installed Packages
• hms
• stringr
• lubridate
• forcats
• haven
• httr
• jsonlite
• readxl
• rvest
• xml2
• modelr
• broom
![Page 15: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/15.jpg)
Aimee Gott – Senior Consultant
Import Tidy
Model
CommunicateTransform
Visualise
Program
![Page 16: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/16.jpg)
Aimee Gott – Senior Consultant
Import
• readr
• haven
• httr
• jsonlite
• readxl
• rvest
• xml2
![Page 17: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/17.jpg)
Aimee Gott – Senior Consultant
Reading Web Data: rvest
read_html("www.myWebPage.co.uk")
• Includes lots of functions for extracting specific
elements of a web page
![Page 18: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/18.jpg)
Aimee Gott – Senior Consultant
Read Olympic Data
funding <-
read_html("http://www.uksport.gov.uk/our
-work/investing-in-sport/
historical-funding-figures")
funding <- html_table(funding, header = TRUE)
![Page 19: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/19.jpg)
Aimee Gott – Senior Consultant
Reading Tabular Data: readr
read_csv("myFile.csv", na = c(" ", "NA"))
Other variants include:
• read_tsv
• read_fwf
• read_delim
![Page 20: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/20.jpg)
Aimee Gott – Senior Consultant
Reading Summer Olympics Data
summer <-
read_csv("SummerOlympicsFunding.csv",
na = c("n/a", "n/a**"),
col_types = cols(
.default = col_number(),
Sport = col_character())
)
![Page 21: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/21.jpg)
Aimee Gott – Senior Consultant
Reading MS Excel Data: readxl
read_excel("myExcelFile.xlsx",
sheet = "Sheet 1")
![Page 22: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/22.jpg)
Aimee Gott – Senior Consultant
Reading Proprietary Data: haven
read_sas("mySASData.sas7bdat")
Other formats include:
• SPSS Data
• Stata Data
![Page 23: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/23.jpg)
Aimee Gott – Senior Consultant
Import Tidy
Model
CommunicateTransform
Visualise
Program
![Page 25: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/25.jpg)
Aimee Gott – Senior Consultant
What is tibble?
• A tibble is an update to the data frame
• Generally works as a data frame but with extra
features
• Doesn’t change column names
• Doesn't convert strings to factors
• Doesn't allow partial matching of names
• Doesn't create row names
![Page 26: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/26.jpg)
Aimee Gott – Senior Consultant
How Do You Create a tibble?
• Using the import functions in the tidyverse
• With the tibble or tribble functions
![Page 27: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/27.jpg)
Aimee Gott – Senior Consultant
What Does the tibble Package Do?
• Provides utility functions for working with tibble
structure
• Generally don't need to directly use the package
much
![Page 28: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/28.jpg)
Aimee Gott – Senior Consultant
Functions in tibble
• glimpse – useful overview of data
• tibble/tribble – creation of tibbles
• add_row/add_column – helpful functions for
adding elements to an existing tibble
• There are also a number of functions for
converting rownames if needed
![Page 29: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/29.jpg)
Aimee Gott – Senior Consultant
Creating A Reference Tibble
years <- tribble(
~Location, ~Year, ~Month, ~Day,
"Sydney", 2000, 9, 15,
"Athens", 2004, 8, 13,
"Beijing", 2008, 8, 8,
"London", 2012, 7, 27,
"Rio de Janeiro", 2016, 8, 5
)
![Page 30: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/30.jpg)
Aimee Gott – Senior Consultant
Tidy Data
• The tidyverse is designed to work with tidy data
• A single structure that is common to all of the
packages
• Makes it easy to move from manipulation to
visualisation to modelling without changing the data
![Page 31: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/31.jpg)
Aimee Gott – Senior Consultant
What is Tidy Data?
• Each variable has its own column
• Each observation has its own row
• Each value has its own cell
![Page 32: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/32.jpg)
Aimee Gott – Senior Consultant
Tidying the Olympic Data
summer <- gather(summer,
Location,
Funding,
-Sport)
![Page 33: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/33.jpg)
Aimee Gott – Senior Consultant
Working with Missing Values
summer <- replace_na(summer,
replace = list(Funding = 0))
![Page 34: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/34.jpg)
Aimee Gott – Senior Consultant
Import Tidy
Model
CommunicateTransform
Visualise
Program
![Page 35: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/35.jpg)
Aimee Gott – Senior Consultant
Transform
• dplyr
• forcats
• stringr
• hms
• lubridate
![Page 36: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/36.jpg)
Aimee Gott – Senior Consultant
Data Manipulation: dplyr
• Standard manipulations
• Filter
• Select
• Arrange
• Mutate
• Summarise
• Perform actions by group (group_by)
![Page 37: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/37.jpg)
Aimee Gott – Senior Consultant
Join Related Data Sets
• Merge/Join two data sets
• Full
• Left/Right
• Inner
• Anti
• Semi
![Page 38: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/38.jpg)
Aimee Gott – Senior Consultant
Joining Olympic Data
summer <- full_join(summer, years) %>%
filter(Sport != "Total")
![Page 39: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/39.jpg)
Aimee Gott – Senior Consultant
Manipulating Factors: forcats
• Factors are a representation of categorical data
• Forcats allows us to easily manipulate factors
• Change names
• Group levels
• Reorder levels
![Page 42: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/42.jpg)
Aimee Gott – Senior Consultant
Reordering Olympic Years
numberNoFund <- summer %>%
filter(Funding == 0)
count(Location) %>%
left_join(years) %>%
mutate(Location =
fct_reorder(Location, Year))
![Page 43: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/43.jpg)
Aimee Gott – Senior Consultant
Manipulating Characters: stringr
• The stringr package provides consistent functions
for manipulating character strings
• Manipulations include:
• Concatenation
• Pattern search and replace
• Subset with strings
![Page 44: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/44.jpg)
Aimee Gott – Senior Consultant
Combining Location and Year
str_c(
magrittr::use_series(years, Location),
"\n(",
magrittr::use_series(years, Year),
")"
)
![Page 46: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/46.jpg)
Aimee Gott – Senior Consultant
Exercise
• Import the winter Olympics data csv
• By performing the appropriate manipulations (using tidyr, dplyr and forcats) • Which sport has the most funding by Sochi?
• Extract the data for just this sport
• What is the difference between the maximum and minimum funding levels for this sport?
• Can you create a simple graphic of this data?
• Why is there some missing data for this sport?
![Page 47: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/47.jpg)
Aimee Gott – Senior Consultant
Manipulating Dates: lubridate
• Easy to use functions to convert characters to date
format
• ymd
• mdy
• dmy
• Manipulation functions to extract elements of dates
• Functions for accounting for addition of time periods
to dates e.g. accounting for 30/31 day months
![Page 48: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/48.jpg)
Aimee Gott – Senior Consultant
Creating Olympic Start Dates
summer <- mutate(summer,
Date = str_c(Year, Month, Day, sep = "-"),
Date = ymd(Date)
)
![Page 50: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/50.jpg)
Aimee Gott – Senior Consultant
Manipulating Times: HMS
• Allows working with just times
• Convert to just a time
• hms
![Page 51: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/51.jpg)
Aimee Gott – Senior Consultant
Import Tidy
Model
CommunicateTransform
Visualise
Program
![Page 53: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/53.jpg)
Aimee Gott – Senior Consultant
Creating Graphics: ggplot2
• A whole workshop on its own!
• Create quick plots with qplot
• Specify the type of plot using the geoms
• Add titles and labels with labs
![Page 55: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/55.jpg)
Aimee Gott – Senior Consultant
Graphic of Olympic Funding
qplot(data = fundingTime,
x = Date, y = Funding/1e6,
colour = Sport,
geom = c("line", "point")) +
labs(title = "Increasing Funding ",
x = "", y = "Funding (Millions)",
colour = "Sport",
caption = "Data taken from ...")
![Page 56: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/56.jpg)
Aimee Gott – Senior Consultant
Exercise
• Using the winter Olympics data create a graphic
showing the change in funding over time for all of
the winter Olympic sports
![Page 57: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/57.jpg)
Aimee Gott – Senior Consultant
Import Tidy
Model
CommunicateTransform
Visualise
Program
![Page 59: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/59.jpg)
Aimee Gott – Senior Consultant
Fitting Models: modelr
• Functionality for bootstrapping/cross validation
• Model metrics – rsquare, rmse
• Extracting predictions and residuals
![Page 60: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/60.jpg)
Aimee Gott – Senior Consultant
Predicting Olympic Funding
fundingModel <- lm(Funding ~ Sport*Year,
data = fundingTime)
modelGrid <- data_grid(fundingTime,
Year, Sport)
modelGrid <- modelGrid %>%
add_predictions(fundingModel)
![Page 62: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/62.jpg)
Aimee Gott – Senior Consultant
Investigating Model Residuals
fundingResid <- fundingTime %>%
add_residuals(fundingModel)
![Page 64: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/64.jpg)
Aimee Gott – Senior Consultant
Assessing Model Quality: broom
• Provides functions for extracting details on the
model fit
• Model coefficients – tidy
• Model diagnostics – glance
• Useful for working with multiple models to
compare fit
![Page 65: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/65.jpg)
Aimee Gott – Senior Consultant
Fit of Olympics Models
tidy(fundingModel)
glance(fundingModel)
![Page 66: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/66.jpg)
Aimee Gott – Senior Consultant
Import Tidy
Model
CommunicateTransform
Visualise
Program
![Page 68: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/68.jpg)
Aimee Gott – Senior Consultant
Iterating: purrr
• Iterate (over a vector of values) or apply to
multiple set/subsets of data
• Output can be one of many types based on the
function used:
• map
• map_df
• map_dbl
• …
![Page 69: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/69.jpg)
Aimee Gott – Senior Consultant
Model For Each Sport
sportData <- fundingTime %>%
group_by(Sport) %>%
nest()
sportsModels <- map(sportData$data,
~lm(Funding ~ Year, data = .))
sportResid <- map2_df(sportData$data,
sportsModels,
add_residuals, .id = "Sport")
![Page 71: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/71.jpg)
Aimee Gott – Senior Consultant
Import Tidy
Model
CommunicateTransform
Visualise
Program
![Page 72: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/72.jpg)
Aimee Gott – Senior Consultant
Communicate
• There are no tidyverse packages directly aimed at
communicating results (other than creating
graphics)
• There are lots of packages that can be used to
present results
![Page 73: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/73.jpg)
Aimee Gott – Senior Consultant
Options for Communicating Results
• Rmarkdown
• Shiny
• Flexdashboard
• bookdown/blogdown
![Page 75: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/75.jpg)
Aimee Gott – Senior Consultant
Using the Tidyverse
• Single unified approach to manipulating and
analysing data
• Provides packages for all stages of the analysis
lifecycle
![Page 76: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/76.jpg)
Aimee Gott – Senior Consultant
Learning More
• R for Data Science
• RStudio Cheat sheets
• Training
![Page 77: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/77.jpg)
Aimee Gott – Senior Consultant
Upcoming Mango Training Courses
• An Introduction to R for Analytics
• Data Manipulation
• Data Visualisation
![Page 78: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/78.jpg)
Aimee Gott – Senior Consultant
EARL London Workshops
• Spark and R with sparklyr
• Web Scraping and Text Analysis in R
• Writing R Functions for Fun and Profit
• Working with the MicrosoftML Package
• Working with GitHub
• Introduction to Shiny
![Page 79: A Two Hour Tour of the Tidyverse - London R · •The tidyverse is designed to work with tidy data •A single structure that is common to all of the packages •Makes it easy to](https://reader034.fdocuments.in/reader034/viewer/2022042219/5ec549141146c40e7c449436/html5/thumbnails/79.jpg)
Aimee Gott – Senior Consultant
Next LondonR Workshop
Matching Your Brand with ggplot2: Working with
Scales, Themes and Guides