Australian Animal Outcomes

Data manipulation, Web Scraping (rvest package) and SelectorGadget, Animated Choropleth Map

Published

July 20, 2020

Notable topics: Data manipulation, Web Scraping (rvest package) and SelectorGadget, Animated Choropleth Map

Recorded on: 2020-07-20

Timestamps by: Eric Fletcher

View code

Screencast

Timestamps

use_tidytemplate
tidytuesdayR

Using use_tidytemplate to open the project dataset with the package's tidytemplate Rmd

rename
dplyr

Using rename to rename Total column to total

fct_reorder
forcats

Using fct_reorder to reorder stacked barplot with weight = sum

fct_lump
forcats

Using fct_lump with w = n to lump together outcome factor levels displaying the most frequenct with rest lumped into other

fct_recode
forcats

Using fct_recode to combine the factor level In Stock with Currently In Care

fct_reorder
forcats

Using fct_reorder to reorder facet_wrap panels

scale_y_continuous
ggplot2scales

Using scale_y_continuous with labels = comma to separate digits with comma

complete
tidyr

Using complete to complete account for missing combinations of data where the value is 0 in the released column

max
base

Using max (year) within filter to subset the data displaying only the most recent year

pivot_longer
tidyr

Using pivot_longer to pivot location variables from wide to long

read_htmlhtml_nodesmap
rvestjanitor

Web Scaraping table from Wikipedia with SelectorGadget and Rvest

str_to_upper
stringr

Using str_to_upper to upper case the values in the shorthand column

parse_number
readr

Using parse_number to remove commas from population and area columns

bind_rows
dplyr

Using bind_rows to bind the two web scraped tables from Wikipedia together by row and column

inner_join
dplyr

Using inner_join to combine the Wikipedia table with the original data set

mutate
dplyr

Using mutate to create new per_capita_million column to show outcome on a per million people basis

summarize
dplyr

Using summarize to create new column pct_euthanized showing percent of cats and dogs euthanized over time. Formula accounts for 0 values thus avoiding a resulting empty vector.

scale_y_continuous
ggplot2scales

Using scale_y_continuous with labels = percent to add percentage sign to y-axis values

read_sfgeom_sfsf_simplify
sfggplot2

Create a choropleth map of Australia using an Australian States Shapefile using the sf and ggplot2 packages | Troubleshooting begins at 44:25 (downsizing / downsampling with sf_simplify)

transition_manual
gganimate

Add animation to the map of Australia showing the percent of cats euthanized by region using gganimate

Summary of screencast