This is an extension of the tidytuesday assignment you have already done. Complete the questions below, using the screencast you chose for the tidytuesday assigment.

Import data

library(tidyverse)
library(lubridate)

brewing_materials <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-03-31/brewing_materials.csv')
beer_taxed <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-03-31/beer_taxed.csv')
brewer_size <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-03-31/brewer_size.csv')
beer_states <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-03-31/beer_states.csv')

Description of the data and definition of variables

The data set used for these graphs is

Beer states: Each row represents a state and the recorded barrels and type per year. This set has 1,872 observations.

Variables and meanings: State - state where barrels were produced Year - calander year Barrels - number of barrels Type - bottles/cans, barrels/kegs, or on premises

Visualize data

Where is beer produced?

beer_states %>%
  count(type, sort = TRUE, wt = barrels)
## # A tibble: 3 x 2
##   type                       n
##   <chr>                  <dbl>
## 1 Bottles and Cans 3790640995.
## 2 Kegs and Barrels  413060363.
## 3 On Premises        32942944.
beer_states %>%
  group_by(year) %>%
  summarize(barrels = sum(barrels, na.rm = TRUE))
## # A tibble: 12 x 2
##     year    barrels
##    <dbl>      <dbl>
##  1  2008 369365660.
##  2  2009 366722996 
##  3  2010 362423267.
##  4  2011 356149025.
##  5  2012 360802673.
##  6  2013 356172814.
##  7  2014 354773849.
##  8  2015 352082099.
##  9  2016 348860505.
## 10  2017 341358612.
## 11  2018 333778335.
## 12  2019 334154466.
# Who consumes beer on premises
state_percents_2019 <- beer_states %>%
  filter(year == max(year), state != "total") %>%
  group_by(state, year) %>%
  mutate(percent = barrels / sum(barrels)) %>%
  ungroup()
state_percents_2019 %>%
  filter(type == "On Premises") %>%
  arrange(desc(percent))
## # A tibble: 51 x 5
##    state  year barrels type        percent
##    <chr> <dbl>   <dbl> <chr>         <dbl>
##  1 ND     2019  10219. On Premises   0.982
##  2 OK     2019  21129. On Premises   0.925
##  3 SD     2019   9386. On Premises   0.722
##  4 WV     2019   8302. On Premises   0.673
##  5 AL     2019  47160. On Premises   0.659
##  6 SC     2019  53161. On Premises   0.625
##  7 IA     2019  61429. On Premises   0.560
##  8 MS     2019  11912. On Premises   0.555
##  9 DC     2019  16348. On Premises   0.547
## 10 AR     2019  16569. On Premises   0.542
## # … with 41 more rows
library(maps)
library(sf)
states <- st_as_sf(map("state", plot = FALSE, fill = TRUE))
states_joined <- state_percents_2019 %>%
  mutate(ID = str_to_lower(state.name[match(state, state.abb)])) %>%
  inner_join(states, by = "ID")
states_joined %>%
  filter(type == "On Premises") %>%
  ggplot(aes(geometry = geom, fill = percent)) +
  geom_sf() +
  scale_fill_gradient2(low = "blue", high = "orange", midpoint = .5,
                       labels = scales::percent) +
  ggthemes::theme_map() +
  labs(title = "In which states is a lot of beer produced consumed on premises?",
       fill = "% consumed on prem.")

states_joined %>%
  ggplot(aes(geometry = geom, fill = percent)) +
  geom_sf() +
  facet_wrap(~ type, nrow = 2) +
  scale_fill_gradient2(low = "blue", high = "orange", midpoint = .5,
                       labels = scales::percent) +
  ggthemes::theme_map() +
  theme(legend.position = "right") +
  labs(title = "How is beer consumed within each state?",
       fill = "% consumed")

library(gganimate)
beer_states %>%
  filter(state != "total") %>%
  group_by(state, year) %>%
  mutate(percent = barrels / sum(barrels)) %>%
  ungroup() %>%
  filter(type == "On Premises") %>%
  mutate(ID = str_to_lower(state.name[match(state, state.abb)])) %>%
  inner_join(states, by = "ID") %>%
  ggplot(aes(geometry = geom, fill = percent)) +
  geom_sf() +
  transition_time(year) +
  facet_wrap(~ type, nrow = 2) +
  scale_fill_gradient2(low = "blue", high = "orange", midpoint = .5,
                       labels = scales::percent) +
  ggthemes::theme_map() +
  theme(legend.position = "right") +
  labs(title = "How is beer consumed within each state? ({ as.integer(frame_time) })",
       fill = "% consumed")
## NULL

What is the story behind the graph?

Dave wanted to figure out how beer is consumed by the states. The first graph shows the percentage consumed at breweries and the second shows by means of consumption either through bottles and cans, barrels, and kegs, or again just on the premises of the breweries.

Hide the messages, but display the code and its results on the webpage.

Write your name for the author at the top.

Use the correct slug.