-
Notifications
You must be signed in to change notification settings - Fork 32
/
03_brexit.Rmd
85 lines (69 loc) · 3.28 KB
/
03_brexit.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
name: brexit
# Brexit
This visualization challenge was a proposed makeover for a Financial Times visualization focusing on relative economic growth in G7 countries, with an emphasis on growth in the UK, focusing especially since Brexit. The visualization I present here is not what I created at the time of the challenge; instead it is inspired by Alan Smith a data journalist at the Financial Times, who created a really compelling visualization a couple of months after #MakeoverMonday's treatment. I try to recreate his plot - which uses a ribbon to contain all G7 countries, and plot the UK's stats thereover. This declutters the graph, and makes you focus on where the UK falls among other countries, without being needlessly specific about those countries; the data story isn't about them anyway, might be Smith's thinking. My graph actually lightly traces economic growth in other countries, but deemphasizes their importance, like Smith.
```{r, echo = F}
data <- readxl::read_xlsx("raw_data/G7 Quarterly GDP Growth.xlsx")
data <- data %>%
mutate(Quarter = as.numeric(stringr::str_extract(Quarter, "\\d"))) %>%
mutate(`Date (start o quarter)` = lubridate::date(`Date (start of quarter)`))
```
A random sample from the data set:
```{r, echo = F}
knitr::kable(sample_n(data, 5), format = "html")
```
---
```{r brexit_1, eval=F, echo=F}
ggplot(data = data) +
aes(x = `Date (start of quarter)`) +
aes(y = `Percentage change from previous period`) +
facet_wrap(~ Country) +
geom_line() +
geom_hline(yintercept = 0, col = "grey") +
geom_vline(xintercept = as.numeric(as.POSIXct("2016-06-23")), lty = "dashed") +
labs(title = "Quarterly GDP Growth in Relation to Brexit Vote") +
labs(subtitle = "Source: OECD")
```
```{r, echo = F, warning=F, message=F, eval = T, fig.show='hide'}
get_what_save_what <- "brexit_1"
eval(parse(text = paste(knitr:::knit_code$get(get_what_save_what), collapse = "")))
ggsave(paste0("figures/", get_what_save_what, ".png"), dpi = 300)
```
`r paste(knitr::knit(text = partial_knit_chunks("brexit_1")), collapse = "\n")`
---
```{r, echo = F}
data <- data %>%
group_by(`Date (start of quarter)`) %>%
mutate(
min_ = min(`Percentage change from previous period`),
max_ = max(`Percentage change from previous period`)
) %>%
ungroup()
```
A random sample from the data set:
```{r, echo = F}
knitr::kable(sample_n(data, 5), format = "html")
data_gbr <- data %>% filter(Country == "GBR")
```
---
```{r brexit, eval=F, echo=F}
ggplot(data = data) +
aes(x = `Date (start of quarter)`) +
aes(y = `Percentage change from previous period`) +
aes(ymin = min_) +
aes(ymax = max_) +
geom_hline(yintercept = 0, col = "grey") +
geom_ribbon(alpha = .2) +
geom_line(aes(col = Country), alpha = .2) +
geom_line(data = data_gbr, col = "black") +
geom_vline(xintercept =
as.numeric(as.POSIXct("2016-06-23")),
lty = 2) +
annotate(geom = "text",
x = as.POSIXct("2016-04-23"), y = 1.5,
label = "Brexit Vote", angle = 90) +
labs(title = "Quarterly GDP Growth of G7 in Relation to Brexit Vote",
subtitle = "Source: OECD", col = "") +
theme_bw()
```
`r paste(knitr::knit(text = partial_knit_chunks("brexit")), collapse = "\n")`
---