-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwk_32_2020.Rmd
212 lines (197 loc) · 5.85 KB
/
wk_32_2020.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
---
title: "European energy"
author: "mnaR99"
date: "3/8/2020"
output: html_document
---
```{r}
library(tidyverse)
library(ggforce)
library(geofacet)
library(scales)
library(ggnewscale)
library(cowplot)
library(ggtext)
library(extrafont)
```
```{r load data}
tuesdata <- tidytuesdayR::tt_load(2020, week = 32)
energy_types <- tuesdata$energy_types
```
```{r clean data}
energy_clean <- energy_types %>%
filter(level == "Level 1") %>%
gather(year, n, 5:7, convert = TRUE) %>%
select(-level) %>%
mutate(
country_name = case_when(
country == "EL" ~ "Greece",
country == "UK" ~ "United Kingdom",
TRUE ~ country_name
),
gtype = case_when(
!type %in% c("Nuclear", "Conventional thermal") ~ "Renewable",
TRUE ~ type
)
) %>%
rename(code = country, name = country_name) %>%
rows_update(tibble(code = "MT", type = "Other", year = 2018, n = 172), by = c("code", "type", "year"))
```
```{r geofacet - grid}
eu_grid <- geofacet::europe_countries_grid1
eu_grid[42,] <- list(row = 6, col = 10, code = "GE", name = "Georgia")
eu_grid <- eu_grid %>%
filter(!code %in% c("IS", "CH", "BY", "RU", "MD")) %>%
mutate(name = ifelse(str_detect(name, "Macedonia"), "North Macedonia", name))
```
```{r summary}
prop_eu <- energy_clean %>%
filter(year == 2018) %>%
group_by(name) %>%
summarise(
total = sum(n),
p_clean = sum(n[gtype != "Conventional thermal"])/total,
)
```
```{r plot data}
data_plot <- energy_clean %>%
filter(year == 2018) %>%
mutate(
code = recode(code, "UK" = "GB", "EL" = "GR")
) %>%
count(code, name , year, gtype, wt = n) %>%
group_by(code) %>%
mutate(p = n/sum(n)) %>%
ungroup() %>%
left_join(prop_eu)
```
```{r pies plot}
pies <- data_plot %>%
ggplot() +
aes(x0 = 0, y0 = 0) +
stat_pie(
aes(r0 = 0.7, r = 1, amount = p, fill = gtype),
color = "white",
size = 1,
show.legend = FALSE
) +
scale_fill_manual(
values = c("#ECBA82", "#2E933C", "#81C14B")
) +
new_scale_fill() +
geom_circle(
aes(r = 0.675, fill = p_clean),
color = NA
) +
scale_fill_fermenter(
type = "div",
direction = 1,
labels = c("25%", "50%", "75%"),
guide = guide_colorsteps(
title = "Clean Energy Share",
title.position = "top"
)
) +
geom_text(
aes(x = 0, y = 0, label = str_glue("{comma(total, .01)}\nGWh")),
color = "white",
family = "Montserrat"
) +
coord_fixed() +
facet_geo(~code, grid = eu_grid, label = "name") +
theme_void(base_family = "Teko") +
theme(
strip.text = element_text(
size = 16,
margin = margin(t = 10, b = 10)
),
legend.position = "bottom",
legend.title = element_text(hjust = 0.5, size = 16),
legend.key.width = grid::unit(15, "mm"),
legend.key.height = grid::unit(3, "mm"),
legend.text = element_text(size = 14)
)
piesG <- ggplotGrob(pies + theme(legend.position = "none"))
legendG <- cowplot::get_legend(pies)
```
```{r notes}
notes <- tribble(
~x, ~y, ~label,
0, -4.5, "**Albania** is dependent on hydroelectricity, with a share in its production of 100%. Still, its topography has the potential to supply power from wind, sun, and soil.",
-3, 0.5, "**France** is the second largest producer of energy in the region, and has the largest share of nuclear electricity (71.3%) in the world.",
1, 1.75, "**Germany** is the country that produced the most energy in 2018, 12.6% was nuclear energy and 31.3% renewable energy.",
-0.5, 3.15, "Much of **Norway**'s electricity is generated from hydropower (95%) due to the natural advantage of its topography with abundant valleys and steep rivers.",
4, 0.5, "**Montenegro** leads the energy transition in the region. In 2018 the production of clean energy increased by more than 100%, compared to the previous year."
)
```
```{r plot}
plot <- qplot() +
geom_curve(
aes(x = 1.5, y = -3.25, xend = 4, yend = 0.16),
size = 2,
curvature = 0.3,
color = "white",
lineend = "round"
) +
annotation_custom(
piesG,
xmin = -5, xmax = 5,
ymin = -5, ymax = 5
) +
annotation_custom(
legendG,
xmin = -5, xmax = -2.2,
ymin = -3.5, ymax = -3
) +
geom_textbox(
data = notes,
aes(x, y, label = label),
family = "Montserrat",
lineheight = 1.5,
# halign = 0,
width = 0.14,
box.color = NA,
fill = NA,
) +
geom_textbox(
aes(
x = -5, y = 4.75,
label = "<span style='font-size:42pt;font-family:Teko'>Clean Energy Producers, 2018</span>
<br><br>
<span style='font-size:15pt'>Total net energy produced (GWh) by european countries in 2018, and its distribution by <b style='color:#ECBA82'>conventional thermal</b>, <b style='color:#2E933C'>nuclear</b> and <b style='color:#81C14B'>renewable</b> energy.</span>
<br><br>
<i style='font-size:10pt;color:#737373;'>**GWh**: Energy generated or consumed by 1 GW of power for one hour.<br>
**How Much Power is 1 GW?** 110 Million LEDs, on typical performance.</i>"
),
family = "Montserrat",
width = unit(27, "lines"),
lineheight = 2,
hjust = 0,
vjust = 1,
fill = NA,
box.color = NA,
) +
scale_x_continuous(limits = c(-5,5), breaks = -5:5) +
scale_y_continuous(limits = c(-5,5), breaks = -5:5) +
labs(caption = "@AtMissing · Eurostat. Supply of electricity") +
# theme_light() +
theme_void() +
theme(
plot.caption = element_text(
hjust = 0.5,
size = 10,
family = "Montserrat",
margin = margin(b = 30)
),
plot.background = element_rect(fill = "#f0f0f0", color = NA)
)
ggsave(here::here("plots","wk_32_2020.pdf"), plot, width = 20, height = 20, device = cairo_pdf)
```
```{r png save}
pdftools::pdf_convert(
pdf = here::here("plots","wk_32_2020.pdf"),
filenames = here::here("plots","wk_32_2020.png"),
format = "png",
dpi = 400
)
```