Beer Production

tidymetrics package demonstration, Animated map (gganimate package)

Published

March 31, 2020

Notable topics: tidymetrics package demonstration, Animated map (gganimate package)

Recorded on: 2020-03-31

Timestamps by: Alex Cookson

View code

Screencast

Timestamps

Asking, "What ingredients are used in beer?"

filtermax

Using filter and max functions to look at the most recent period of time

pasteymd

Using paste and ymd functions (ymd is from lubridate package) to convert year-month field into an date-formatted field

Spotting potential missing or mis-parsed data

Introducing the tidymetrics framework

install_github

Using install_github function to install tidymetrics from GitHub

cross_by_dimensions
tidymetrics

Using cross_by_dimensions function from tidymetrics package to get aggregations at different levels of multiple dimensions

cross_by_periods
tidymetrics

Using cross_by_periods function from tidymetrics package to also get aggregations for different intervals (e.g, month, quarter, year)

use_metrics_scaffold
tidymetrics

Using use_metrics_scaffold function from tidymetrics package to create framework for documenting dimensions in RMarkdown YAML header

create_metrics
tidymetrics

Using create_metrics function from tidymetrics package to save data as a tibble with useful metadata (good for visualizing interactively)

preview_metrics
shinymetrics

Using preview_metric function from shinymetrics package (still under development as of 2020-04-24) to demonstrate shinymetrics

shinymetrics

Succesfuly getting shinymetrics to work

shinymetrics

Explanation of the shinymetrics bug David ran into

parse_numberfct_lumpcoalesce

Changing order of ordinal variable (e.g., "1,000 to 10,000" and "10,000 to 20,000") using the parse_number, fct_lump, and coalesce functions

Asking, "Where is beer produced?"

sf

Looking up sf package documentation to refresh memory on how to draw state borders for a map

match

Using match function and state.abb vector (state abbreviations) from sf package to perform a lookup of state names

geom_sf
sf

Using geom_sf function (and working through some hiccoughs) to create a choropleth map

theme_map
ggthemes

Using theme_map function from ggthemes package to get more appropriate styling for maps

Experimenting with how to get the legend to display in the bottom right corner

gganimate

Starting to build an animation of consumption patterns over time using gganimate package

gganimate

Getting the year being animated to show up in the title of a gganimate map

Summary of screencast

Spotting a mistake in a group_by call causing the percentages not to add up properly

tidymetrics

Brief extra overview of tidymetrics code