-
Notifications
You must be signed in to change notification settings - Fork 5
/
00_start_examples.Rmd
106 lines (80 loc) · 3.36 KB
/
00_start_examples.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
---
title: "What we will be working towards"
output:
html_document:
number_sections: no
toc: yes
toc_float: yes
---
Illustrating through exampes common steps for common thematic maps:
1. Get an appropriate blank map.
2. Load and add "regular" data.
3. Manipulate (spatial) data.
4. Plot map.
```{r, echo=FALSE, message=FALSE, warning=FALSE}
library(sf)
library(BelgiumMaps.StatBel)
library(tmap)
library(dplyr)
library(readxl)
library(eurostat)
library(leaflet)
library(haven)
```
# Socio-economic clusters
```{r}
# [1] Get blank map (of Belgian muncipalities)
data("BE_ADMIN_MUNTY")
munip_map <- st_as_sf(BE_ADMIN_MUNTY)
# [2] Load and add data-of-interest (Excel-file of socio-economic cluster-type of muncipality)
munip_data <- read_excel('data/muni_typology.xlsx', col_types = 'text')
munip <- left_join(munip_map, munip_data, by = c('CD_MUNTY_REFNIS' = 'gemeente_nis_code'))
# [3] Manipulate data (not needed)
# [4] Plot map
qtm(munip, fill = 'hoofdcluster_lbl', fill.title = 'Socio-economic cluster')
```
# Part-time work in the EU
```{r, message=FALSE, warning=FALSE}
# [1] Get blank map (of EU countries directly from Eurostat)
map_data <- get_eurostat_geospatial(resolution = "60", nuts_level = "0")
map_data <- st_crop(map_data, c(xmin=-10, xmax=45, ymin=36, ymax=71))
# [2] Load and add data-of-interest (Excel-file with % part-time workers, from Eurostat)
worktime_data <- read_excel('data/eurostat_workingtime_2017.xlsx')
worktime <- left_join(map_data, worktime_data, by = c('CNTR_CODE' = 'geo'))
# [3] Manipulate data (not needed)
# [4] Plot map
qtm(worktime, fill = 'values', fill.title = 'Percentage part-time')
```
# Mean income in Limburg (PPP)
```{r, message=FALSE, warning=FALSE}
# [1] Get blank map (of Belgian muncipalities)
data("BE_ADMIN_MUNTY")
munip_map <- st_as_sf(BE_ADMIN_MUNTY)
# [2] Load and add data-of-interest (Stata file with fiscal income data on municipal level).
munip_data <- read_dta('data/fiscal_incomes_2016.dta')
munip <- left_join(munip_map, munip_data, by = c('CD_MUNTY_REFNIS' = 'munip_nis'))
# [3] Manipulate (spatial) data (select muncipalities in Limburg, and convert to PPP).
limburg <- munip %>%
filter(TX_PROV_DESCR_NL == 'Provincie Limburg') %>%
mutate(income_mean_ppp = income_mean * 0.794)
# [4] Plot map.
qtm(limburg, fill = 'income_mean_ppp', fill.title = 'Mean income (2016, PPP)')
```
# Interactive map of income in Brussels
```{r, message=FALSE, warning=FALSE}
# [1] Get blank map (of Belgian muncipalities)
data("BE_ADMIN_MUNTY")
munip_map <- st_as_sf(BE_ADMIN_MUNTY)
# [2] Load and add data-of-interest (Stata file with fiscal income data on municipal level).
munip_data <- read_dta('data/fiscal_incomes_2016.dta')
munip <- left_join(munip_map, munip_data, by = c('CD_MUNTY_REFNIS' = 'munip_nis'))
# [3] Manipulate (spatial) data (select muncipalities in Limburg, and convert to PPP).
income_vl <- munip %>% filter(TX_RGN_DESCR_NL == 'Brussels Hoofdstedelijk Gewest')
# [4] Plot (interactive) map.
bins <- c(0, 5000, 10000, 15000, 20000, 25000, 30000) # intervals scale & color range
color_range <- colorBin("YlOrRd", domain = income_vl$income_mean, bins = bins)
leaflet(income_vl) %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addPolygons(fillColor = ~color_range(income_mean), color = "black", weight = 1, opacity = 1) %>%
addLegend(values = ~income_mean, title = 'Mean income (2016)', pal = color_range)
```