-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathus_beer_production.Rmd
220 lines (147 loc) · 5.35 KB
/
us_beer_production.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
---
title: "Beer Production"
author: "Dean Marchiori"
date: "4/3/2020"
output: html_document
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(tidyverse)
library(forcats)
library(brolgar)
library(tsibble)
library(fabletools)
library(patchwork)
options(scipen = 999)
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')
```
```{r}
size <- brewer_size %>%
select(year, brewer_size, n_of_brewers) %>%
filter(brewer_size != "Total",
brewer_size != "Zero Barrels",
brewer_size != "Under 1 Barrel") %>%
mutate(brewer_size = fct_recode(brewer_size,
`> 1,000,000 Barrels` = "1,000,001 to 6,000,000 Barrels",
`> 1,000,000 Barrels` = "1,000,001 to 1,999,999 Barrels",
`> 1,000,000 Barrels` = "1,000,000 to 6,000,000 Barrels",
`> 1,000,000 Barrels` = "6,000,001 Barrels and Over",
`> 1,000,000 Barrels` = "2,000,000 to 6,000,000 Barrels",
),
brewer_size = fct_relevel(brewer_size,
"1 to 1,000 Barrels",
"1,001 to 7,500 Barrels",
"7,501 to 15,000 Barrels",
"15,001 to 30,000 Barrels",
"30,001 to 60,000 Barrels",
"60,001 to 100,000 Barrels",
"100,001 to 500,000 Barrels",
"500,001 to 1,000,000 Barrels"
)) %>%
group_by(year, brewer_size) %>%
summarise(n_of_brewers = sum(n_of_brewers)) %>%
ungroup() %>%
as_tsibble(key = brewer_size, index = year)
a <- size %>%
features(n_of_brewers, feat_brolgar) %>%
left_join(size) %>%
ggplot() +
geom_line(aes(year,
n_of_brewers,
group = brewer_size,
alpha = sd),
show.legend = FALSE,
colour = "#BD5B0F") +
geom_text(data = size %>% filter(year == last(year)),
aes(label = brewer_size,
x = year + 0.5,
y = n_of_brewers),
check_overlap = TRUE,
size = 3,
colour = "#533505") +
scale_x_continuous(breaks = c(2009:2019)) +
scale_colour_viridis_c(direction = 1) +
theme_minimal() +
labs(title = "Number of brewers",
x = "",
y = "Number of Brewers")
```
```{r}
cans <- beer_states %>%
filter(!state == "total",
type == "Bottles and Cans",
!is.na(barrels)) %>%
as_tsibble(key = c(state), index = year)
cans_feat <- cans %>%
features(barrels, feat_brolgar) %>%
left_join(cans)
b <- ggplot(cans_feat) +
geom_line(aes(year,
barrels,
group = state,
alpha = sd),
colour = "#F17F0F",
show.legend = FALSE) +
geom_text(data = cans_feat %>% filter(year == last(year)) %>% top_n(5, sd),
aes(label = state,
x = year + 0.5,
y = barrels),
show.legend = F,
check_overlap = TRUE,
size = 3,
colour = "#533505") +
theme_minimal() +
scale_y_continuous(labels = scales::comma) +
scale_x_continuous(breaks = c(2009:2019)) +
labs(title = "Bottles and Cans",
x = "",
y = "Barrels Produced")
```
```{r}
onprem <- beer_states %>%
filter(!state == "total",
type == "On Premises",
!is.na(barrels)) %>%
as_tsibble(key = c(state), index = year)
onprem_feat <- onprem %>%
features(barrels, feat_brolgar) %>%
left_join(onprem)
c <- ggplot(onprem_feat) +
geom_line(aes(year,
barrels,
group = state,
alpha = sd),
colour = "#AE430B",
show.legend = FALSE) +
geom_text(data = onprem_feat %>% filter(year == last(year)) %>% top_n(5, sd),
aes(label = state,
x = year + 0.5,
y = barrels),
show.legend = F,
check_overlap = TRUE,
size = 3,
colour = "#533505") +
scale_y_continuous(labels = scales::comma) +
theme_minimal() +
scale_x_continuous(breaks = c(2009:2019)) +
labs(title = "On Premises",
x = "",
y = "")
```
```{r}
patchwork <- a / (b + c)
patchwork + plot_annotation(
title = 'The rise of craft beer in the US',
subtitle = 'Over the last 10 years there has been huge growth in small boutique brewers.
With bottle and can consumption decreasing, more beer is being consumed on premises, particularly in California.',
caption = '@deanmarchiori | Data: Alcohol and Tobacco Tax and Trade Bureau (TTB)',
theme = theme(plot.title = element_text(face = 'bold', size = 42))) &
theme(text = element_text(colour = '#533505', family = 'Noto Mono'),
plot.background = element_rect(fill = "#D9D1AF", colour = NA)
)
```