-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNUTS2Germany.R
45 lines (45 loc) · 1.2 KB
/
NUTS2Germany.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
## Maps and choropleths with {ggplot2}
#
library(dplyr)
library(eurostat)
library(sf)
library(ggplot2)
rm(list = ls())
#
#
#### Simple maps with {ggplot2}
#
# Get the spatial data for NUTS regions in {sf} format
options(readr.default_locale=readr::locale(tz="Europe/Berlin"))
df60 <- eurostat::get_eurostat_geospatial(resolution = 60)
#
#
# Example of map for Germany - NUTS 2
Germany60 <- df60 %>%
dplyr::filter(LEVL_CODE == 2 & CNTR_CODE %in% ("DE")) %>%
dplyr::select(NUTS_ID)
# ggplot2 map
ggplot() +
geom_sf(data = Germany60)
#
GE.sp <- as_Spatial(Germany60)
#
library(rgeos) # install.packages("rgeos")
library(rgdal) # install.packages("rgdal")
#
######################################################
#
#
# Centroids - representative points for areal regions
#
Centroids <- as.data.frame(as.character(GE.sp$NUTS_ID))
Centroids <- cbind(Centroids, coordinates(GE.sp))
colnames(Centroids) <- c("NUTS_ID","long","lat")
Centroids[Centroids$NUTS_ID=="DE40",2:3] <- c(13.397932, 53) # amend for name overlap
#
ggplot() +
geom_sf(data = Germany60)+
geom_text(data = Centroids, aes(label = NUTS_ID, x = long, y = lat, group=NUTS_ID), size = 2.5) +
# ggtitle("NUTS2 regions in Germany") +
theme_minimal()
#