-
Notifications
You must be signed in to change notification settings - Fork 0
/
3_test-plots.R
367 lines (311 loc) · 17 KB
/
3_test-plots.R
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
load("./data/processed_data.Rdata")
library(ggplot2)
library(viridis)
library(dplyr)
library(rgeos)
poly_ggplot <- gBuffer(poly, byid = TRUE, width = 0)
poly_ggplot$ovw <- substr(poly_ggplot$NUTS_ID, 1, 2)
poly_ggplot_ovw <- fortify(poly_ggplot, region = "ovw")
poly_ggplot <- fortify(poly_ggplot, region = "NUTS_ID")
poly_plot_ovw <- poly_ggplot
poly_plot_ovw$Country <- as.factor(substr(poly_ggplot$id, 1, 2))
p_ovw <- ggplot() +
geom_polygon(data = poly_plot_ovw,
aes(fill = Country, x = long, y = lat, group = group)) +
geom_path(data = poly_ggplot_ovw, aes(x = long, y = lat, group = group),
color = "black", size = 0.1) +
# geom_path(data = poly_ggplot_ovw, aes(x = long, y = lat, group = group),
# color = 'red', size = 0.25) +
coord_equal() +
labs(x = NULL, y = NULL) +
theme(axis.line = element_blank(),
axis.text.x = element_blank(), axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(),axis.title.y = element_blank(),
panel.background = element_rect(fill = "transparent", colour = NA),
plot.background = element_rect(fill = "transparent", colour = NA)) +
scale_fill_viridis(option = "plasma", discrete = TRUE) +
theme(plot.margin = unit(c(0,0.5,0,0.5), "cm")) +
theme(legend.position = "bottom", legend.justification = "center",
legend.direction = "horizontal",
legend.background = element_rect(fill="transparent"),
legend.title = element_blank()) +
guides(fill = guide_legend(nrow = 2,byrow = TRUE))
gdp_pc <- depvar_list$gdp_pc
quant_gdp_pc_00 <- quantile(gdp_pc$GDP_pc_2000, probs = seq(0, 1, by = 1/6))
quant_gdp_pc_07 <- quantile(gdp_pc$GDP_pc_2007, probs = seq(0, 1, by = 1/6))
quant_gdp_pc_08 <- quantile(gdp_pc$GDP_pc_2008, probs = seq(0, 1, by = 1/6))
quant_gdp_pc_15 <- quantile(gdp_pc$GDP_pc_2015, probs = seq(0, 1, by = 1/6))
equal_gdp_pc_00 <- seq(min(gdp_pc$GDP_pc_2000), max(gdp_pc$GDP_pc_2000),
by = (max(gdp_pc$GDP_pc_2000) - min(gdp_pc$GDP_pc_2000)))
equal_gdp_pc_07 <- seq(min(gdp_pc$GDP_pc_2007), max(gdp_pc$GDP_pc_2007),
by = (max(gdp_pc$GDP_pc_2007) - min(gdp_pc$GDP_pc_2007)))
equal_gdp_pc_08 <- seq(min(gdp_pc$GDP_pc_2008), max(gdp_pc$GDP_pc_2008),
by = (max(gdp_pc$GDP_pc_2008) - min(gdp_pc$GDP_pc_2008)))
equal_gdp_pc_15 <- seq(min(gdp_pc$GDP_pc_2015), max(gdp_pc$GDP_pc_2015),
by = (max(gdp_pc$GDP_pc_2015) - min(gdp_pc$GDP_pc_2015)))
gdp_pc$quant_gdp_pc_00 <- cut(gdp_pc$GDP_pc_2000, breaks = quant_gdp_pc_00, include_lowest = T)
gdp_pc$quant_gdp_pc_07 <- cut(gdp_pc$GDP_pc_2007, breaks = quant_gdp_pc_07, include_lowest = T)
gdp_pc$quant_gdp_pc_08 <- cut(gdp_pc$GDP_pc_2008, breaks = quant_gdp_pc_08, include_lowest = T)
gdp_pc$quant_gdp_pc_15 <- cut(gdp_pc$GDP_pc_2015, breaks = quant_gdp_pc_15, include_lowest = T)
gdp_pc$equal_gdp_pc_00 <- cut(gdp_pc$GDP_pc_2000, breaks = equal_gdp_pc_00, include_lowest = T)
gdp_pc$equal_gdp_pc_07 <- cut(gdp_pc$GDP_pc_2007, breaks = equal_gdp_pc_07, include_lowest = T)
gdp_pc$equal_gdp_pc_08 <- cut(gdp_pc$GDP_pc_2008, breaks = equal_gdp_pc_08, include_lowest = T)
gdp_pc$equal_gdp_pc_15 <- cut(gdp_pc$GDP_pc_2015, breaks = equal_gdp_pc_15, include_lowest = T)
poly_plot_gdp_pc <- na.omit(left_join(poly_ggplot, gdp_pc[ , c(1, 38:ncol(gdp_pc))], by = c("id" = "NUTS_ID")))
gdp_pc_plot_list <- list()
plot_names <- names(poly_plot_gdp_pc)[8:ncol(poly_plot_gdp_pc)]
for(i in 1:length(plot_names)){
gdp_pc_plot_list[[plot_names[i]]] <- ggplot() +
geom_polygon(data = poly_plot_gdp_pc,
aes_string(fill = plot_names[i],
x = "long", y = "lat", group = "group")) +
geom_path(data = poly_plot_gdp_pc, aes(x = long, y = lat, group = group),
color = "black", size = 0.05) +
labs(x = NULL, y = NULL) +
theme(axis.line = element_blank(),
axis.text.x=element_blank(), axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(), axis.title.y = element_blank(),
panel.background = element_rect(fill = "transparent", colour = NA),
plot.background = element_rect(fill = "transparent", colour = NA)) +
coord_equal() +
scale_fill_viridis(option = "plasma", direction = -1, discrete = TRUE) +
theme(legend.position = "none", legend.justification = c(0,1),
legend.background = element_rect(fill="transparent"),
legend.title = element_blank())
}
gdp_gr <- depvar_list$gdp_pc_gr
quant_gdp_gr_0015 <- quantile(gdp_gr$GDP_gr_0015, probs = seq(0, 1, by = 1/6))
quant_gdp_gr_0007 <- quantile(gdp_gr$GDP_gr_0007, probs = seq(0, 1, by = 1/6))
quant_gdp_gr_0815 <- quantile(gdp_gr$GDP_gr_0815, probs = seq(0, 1, by = 1/6))
equal_gdp_gr_0015 <- seq(min(gdp_gr$GDP_gr_0015), max(gdp_gr$GDP_gr_0015),
by = (max(gdp_gr$GDP_gr_0015) - min(gdp_gr$GDP_gr_0015)))
equal_gdp_gr_0007 <- seq(min(gdp_gr$GDP_gr_0007), max(gdp_gr$GDP_gr_0007),
by = (max(gdp_gr$GDP_gr_0007) - min(gdp_gr$GDP_gr_0007)))
equal_gdp_gr_0815 <- seq(min(gdp_gr$GDP_gr_0815), max(gdp_gr$GDP_gr_0815),
by = (max(gdp_gr$GDP_gr_0815) - min(gdp_gr$GDP_gr_0815)))
gdp_gr$quant_gdp_gr_0015 <- cut(gdp_gr$GDP_gr_0015, breaks = quant_gdp_gr_0015, include_lowest = T)
gdp_gr$quant_gdp_gr_0007 <- cut(gdp_gr$GDP_gr_0007, breaks = quant_gdp_gr_0007, include_lowest = T)
gdp_gr$quant_gdp_gr_0815 <- cut(gdp_gr$GDP_gr_0815, breaks = quant_gdp_gr_0815, include_lowest = T)
gdp_gr$equal_gdp_gr_0015 <- cut(gdp_gr$GDP_gr_0015, breaks = equal_gdp_gr_0015, include_lowest = T)
gdp_gr$equal_gdp_gr_0007 <- cut(gdp_gr$GDP_gr_0007, breaks = equal_gdp_gr_0007, include_lowest = T)
gdp_gr$equal_gdp_gr_0815 <- cut(gdp_gr$GDP_gr_0815, breaks = equal_gdp_gr_0815, include_lowest = T)
poly_plot_gdp_gr <- na.omit(left_join(poly_ggplot, gdp_gr[ , c(1, 10:ncol(gdp_gr))], by = c("id" = "NUTS_ID")))
gdp_gr_plot_list <- list()
plot_names <- names(poly_plot_gdp_gr)[8:ncol(poly_plot_gdp_gr)]
for(i in 1:length(plot_names)){
gdp_gr_plot_list[[plot_names[i]]] <- ggplot() +
geom_polygon(data = poly_plot_gdp_gr,
aes_string(fill = plot_names[i],
x = "long", y = "lat", group = "group")) +
geom_path(data = poly_plot_gdp_gr, aes(x = long, y = lat, group = group),
color = "black", size = 0.05) +
labs(x = NULL, y = NULL) +
theme(axis.line = element_blank(),
axis.text.x=element_blank(), axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(), axis.title.y = element_blank(),
panel.background = element_rect(fill = "transparent", colour = NA),
plot.background = element_rect(fill = "transparent", colour = NA)) +
coord_equal() +
scale_fill_viridis(option = "plasma", direction = -1, discrete = TRUE) +
theme(legend.position = "none", legend.justification = c(0,1),
legend.background = element_rect(fill="transparent"),
legend.title = element_blank())
}
#####
# GVA plots in case necessary
# gva_pc <- depvar_list$gva_pc
#
# quant_gva_pc_00 <- quantile(gva_pc$GVA_pc_2000, probs = seq(0, 1, by = 1/6))
# quant_gva_pc_07 <- quantile(gva_pc$GVA_pc_2007, probs = seq(0, 1, by = 1/6))
# quant_gva_pc_08 <- quantile(gva_pc$GVA_pc_2008, probs = seq(0, 1, by = 1/6))
# quant_gva_pc_15 <- quantile(gva_pc$GVA_pc_2015, probs = seq(0, 1, by = 1/6))
#
# equal_gva_pc_00 <- seq(min(gva_pc$GVA_pc_2000), max(gva_pc$GVA_pc_2000),
# by = (max(gva_pc$GVA_pc_2000) - min(gva_pc$GVA_pc_2000)))
# equal_gva_pc_07 <- seq(min(gva_pc$GVA_pc_2007), max(gva_pc$GVA_pc_2007),
# by = (max(gva_pc$GVA_pc_2007) - min(gva_pc$GVA_pc_2007)))
# equal_gva_pc_08 <- seq(min(gva_pc$GVA_pc_2008), max(gva_pc$GVA_pc_2008),
# by = (max(gva_pc$GVA_pc_2008) - min(gva_pc$GVA_pc_2008)))
# equal_gva_pc_15 <- seq(min(gva_pc$GVA_pc_2015), max(gva_pc$GVA_pc_2015),
# by = (max(gva_pc$GVA_pc_2015) - min(gva_pc$GVA_pc_2015)))
#
# gva_pc$quant_gva_pc_00 <- cut(gva_pc$GVA_pc_2000, breaks = quant_gva_pc_00, include_lowest = T)
# gva_pc$quant_gva_pc_07 <- cut(gva_pc$GVA_pc_2007, breaks = quant_gva_pc_07, include_lowest = T)
# gva_pc$quant_gva_pc_08 <- cut(gva_pc$GVA_pc_2008, breaks = quant_gva_pc_08, include_lowest = T)
# gva_pc$quant_gva_pc_15 <- cut(gva_pc$GVA_pc_2015, breaks = quant_gva_pc_15, include_lowest = T)
#
# gva_pc$equal_gva_pc_00 <- cut(gva_pc$GVA_pc_2000, breaks = equal_gva_pc_00, include_lowest = T)
# gva_pc$equal_gva_pc_07 <- cut(gva_pc$GVA_pc_2007, breaks = equal_gva_pc_07, include_lowest = T)
# gva_pc$equal_gva_pc_08 <- cut(gva_pc$GVA_pc_2008, breaks = equal_gva_pc_08, include_lowest = T)
# gva_pc$equal_gva_pc_15 <- cut(gva_pc$GVA_pc_2015, breaks = equal_gva_pc_15, include_lowest = T)
#
#
# poly_plot_gva_pc <- na.omit(left_join(poly_ggplot, gva_pc[ , c(1, 38:ncol(gva_pc))], by = c("id" = "NUTS_ID")))
#
#
# gva_pc_plot_list <- list()
# plot_names <- names(poly_plot_gva_pc)[8:ncol(poly_plot_gva_pc)]
#
# for(i in 1:length(plot_names)){
# gva_pc_plot_list[[plot_names[i]]] <- ggplot() +
# geom_polygon(data = poly_plot_gva_pc,
# aes_string(fill = plot_names[i],
# x = "long", y = "lat", group = "group")) +
# geom_path(data = poly_plot_gva_pc, aes(x = long, y = lat, group = group),
# color = "black", size = 0.05) +
# labs(x = NULL, y = NULL) +
# theme(axis.line = element_blank(),
# axis.text.x=element_blank(), axis.text.y = element_blank(),
# axis.ticks = element_blank(),
# axis.title.x = element_blank(), axis.title.y = element_blank()) +
# coord_equal() +
# scale_fill_viridis(option = "plasma", direction = -1, discrete = TRUE) +
# theme(legend.position = "none", legend.justification = c(0,1),
# legend.background = element_rect(fill="transparent"),
# legend.title = element_blank())
# }
#
#
#
#
# gva_gr <- depvar_list$gva_pc_gr
#
# quant_gva_gr_0015 <- quantile(gva_gr$GVA_gr_0015, probs = seq(0, 1, by = 1/6))
# quant_gva_gr_0007 <- quantile(gva_gr$GVA_gr_0007, probs = seq(0, 1, by = 1/6))
# quant_gva_gr_0815 <- quantile(gva_gr$GVA_gr_0815, probs = seq(0, 1, by = 1/6))
#
# equal_gva_gr_0015 <- seq(min(gva_gr$GVA_gr_0015), max(gva_gr$GVA_gr_0015),
# by = (max(gva_gr$GVA_gr_0015) - min(gva_gr$GVA_gr_0015)))
# equal_gva_gr_0007 <- seq(min(gva_gr$GVA_gr_0007), max(gva_gr$GVA_gr_0007),
# by = (max(gva_gr$GVA_gr_0007) - min(gva_gr$GVA_gr_0007)))
# equal_gva_gr_0815 <- seq(min(gva_gr$GVA_gr_0815), max(gva_gr$GVA_gr_0815),
# by = (max(gva_gr$GVA_gr_0815) - min(gva_gr$GVA_gr_0815)))
#
# gva_gr$quant_gva_gr_0015 <- cut(gva_gr$GVA_gr_0015, breaks = quant_gva_gr_0015, include_lowest = T)
# gva_gr$quant_gva_gr_0007 <- cut(gva_gr$GVA_gr_0007, breaks = quant_gva_gr_0007, include_lowest = T)
# gva_gr$quant_gva_gr_0815 <- cut(gva_gr$GVA_gr_0815, breaks = quant_gva_gr_0815, include_lowest = T)
#
# gva_gr$equal_gva_gr_0015 <- cut(gva_gr$GVA_gr_0015, breaks = equal_gva_gr_0015, include_lowest = T)
# gva_gr$equal_gva_gr_0007 <- cut(gva_gr$GVA_gr_0007, breaks = equal_gva_gr_0007, include_lowest = T)
# gva_gr$equal_gva_gr_0815 <- cut(gva_gr$GVA_gr_0815, breaks = equal_gva_gr_0815, include_lowest = T)
#
#
# poly_plot_gva_gr <- na.omit(left_join(poly_ggplot, gva_gr[ , c(1, 10:ncol(gva_gr))], by = c("id" = "NUTS_ID")))
#
#
# gva_gr_plot_list <- list()
# plot_names <- names(poly_plot_gva_gr)[8:ncol(poly_plot_gva_gr)]
#
# for(i in 1:length(plot_names)){
# gva_gr_plot_list[[plot_names[i]]] <- ggplot() +
# geom_polygon(data = poly_plot_gva_gr,
# aes_string(fill = plot_names[i],
# x = "long", y = "lat", group = "group")) +
# geom_path(data = poly_plot_gva_gr, aes(x = long, y = lat, group = group),
# color = "black", size = 0.05) +
# labs(x = NULL, y = NULL) +
# theme(axis.line = element_blank(),
# axis.text.x=element_blank(), axis.text.y = element_blank(),
# axis.ticks = element_blank(),
# axis.title.x = element_blank(), axis.title.y = element_blank()) +
# coord_equal() +
# scale_fill_viridis(option = "plasma", direction = -1, discrete = TRUE) +
# theme(legend.position = "none", legend.justification = c(0,1),
# legend.background = element_rect(fill="transparent"),
# legend.title = element_blank())
# }
#
# save(poly_plot_gdp_pc, gdp_pc_plot_list,
# poly_plot_gdp_gr, gdp_gr_plot_list,
# poly_plot_gva_pc, gva_pc_plot_list,
# poly_plot_gva_gr, gva_gr_plot_list,
# file = "./data/plots.Rda")
#####
load("./output/run.Rda")
poly_plot_clubs <- left_join(poly_ggplot,
cbind(rownames(data),
data[ , c("clubs_lm", "clubs_sar", "clubs_sem")]),
by = c("id" = "rownames(data)"))
p_clubs_lm <- ggplot() +
geom_polygon(data = poly_plot_clubs,
aes(fill = clubs_lm, x = long, y = lat, group = group)) +
geom_path(data = poly_plot_clubs, aes(x = long, y = lat, group = group),
color = "black", size = 0.1) +
coord_equal() +
labs(x = NULL, y = NULL,
title = "Convergence clubs NUTS 2",
subtitle = "Unfiltered data") +
theme(axis.line = element_blank(),
axis.text.x = element_blank(), axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(), axis.title.y = element_blank(),
panel.background = element_rect(fill = "transparent", colour = NA),
plot.background = element_rect(fill = "transparent", colour = NA)) +
scale_fill_viridis(option = "viridis", discrete = TRUE) +
theme(plot.margin = unit(c(0.5,0,0,0), "cm")) +
theme(legend.position = "bottom", legend.justification = "center",
legend.direction = "horizontal",
legend.background = element_rect(fill="transparent"),
legend.title = element_blank()) +
guides(fill = guide_legend(nrow = 2,byrow = TRUE))
p_clubs_sar <- ggplot() +
geom_polygon(data = poly_plot_clubs,
aes(fill = clubs_sar, x = long, y = lat, group = group)) +
geom_path(data = poly_plot_clubs, aes(x = long, y = lat, group = group),
color = "black", size = 0.1) +
coord_equal() +
labs(x = NULL, y = NULL,
title = "Convergence clubs NUTS 2",
subtitle = "SAR-filtered data") +
theme(axis.line = element_blank(),
axis.text.x = element_blank(), axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(),axis.title.y = element_blank(),
panel.background = element_rect(fill = "transparent", colour = NA),
plot.background = element_rect(fill = "transparent", colour = NA)) +
scale_fill_viridis(option = "viridis", discrete = TRUE) +
theme(plot.margin = unit(c(0.5,0,0,0), "cm")) +
theme(legend.position = "bottom", legend.justification = "center",
legend.direction = "horizontal",
legend.background = element_rect(fill="transparent"),
legend.title = element_blank()) +
guides(fill = guide_legend(nrow = 2,byrow = TRUE))
p_clubs_sem <- ggplot() +
geom_polygon(data = poly_plot_clubs,
aes(fill = clubs_sem, x = long, y = lat, group = group)) +
geom_path(data = poly_plot_clubs, aes(x = long, y = lat, group = group),
color = "black", size = 0.1) +
coord_equal() +
labs(x = NULL, y = NULL,
title = "Convergence clubs NUTS 2",
subtitle = "SEM-filtered data") +
theme(axis.line = element_blank(),
axis.text.x = element_blank(), axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(), axis.title.y = element_blank(),
panel.background = element_rect(fill = "transparent", colour = NA),
plot.background = element_rect(fill = "transparent", colour = NA)) +
scale_fill_viridis(option = "viridis", discrete = TRUE) +
theme(plot.margin = unit(c(0.5,0,0,0), "cm")) +
theme(legend.position = "bottom", legend.justification = "center",
legend.direction = "horizontal",
legend.background = element_rect(fill="transparent"),
legend.title = element_blank()) +
guides(fill = guide_legend(nrow = 2,byrow = TRUE))
# save(poly_plot_gdp_pc, gdp_pc_plot_list,
# poly_plot_gdp_gr, gdp_gr_plot_list,
# poly_ggplot_ovw, p_ovw,
# poly_plot_clubs, p_clubs_lm, p_clubs_sar, p_clubs_sem,
# file = "./data/plots.Rda")
plot_gdp_pc <- gdp_pc_plot_list$quant_gdp_pc_00 +
labs(title = "GDP p.c. in 2000", subtitle = "Quantile map")
plot_gdp_gr <- gdp_gr_plot_list$quant_gdp_gr_0015 +
labs(title = "GDP p.c. growth 2000-15", subtitle = "Quantile map")
save(poly_plot_gdp_pc, plot_gdp_pc,
poly_plot_gdp_gr, plot_gdp_gr,
poly_ggplot_ovw, p_ovw,
poly_plot_clubs, p_clubs_lm, p_clubs_sar, p_clubs_sem,
file = "./data/plots_pres.Rda")