-
Notifications
You must be signed in to change notification settings - Fork 0
/
maps.Rmd
60 lines (47 loc) · 2.13 KB
/
maps.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
---
date: "`r Sys.time()`"
output: html_document
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, fig.path = "assets/plots/")
source("init.R")
theme_set(tadaatoolbox::theme_tadaa(bg = "#ffffff"))
```
## Voter Turnout
### by State
```{r voter_tunrout_state_map}
# create labels and color palette
labels1 <- paste0(
laender$NAME_1, ": ", round(laender$Wahlbeteiligung * 100, 1), "%"
) %>% lapply(htmltools::HTML)
pal1 <- colorBin("plasma", domain = laender$Wahlbeteiligung, reverse = TRUE)
# create map
leaflet(laender) %>%
addProviderTiles(providers$Esri) %>% # oder $Stamen.TonerLite
addPolygons(weight = 2, color = "black", fillColor = ~pal1(Wahlbeteiligung),
dashArray = "4", fillOpacity = 0.5, label = labels1,
highlightOptions = highlightOptions(weight = 3, color = "#800000",
dashArray = "", fillOpacity = .8,
bringToFront = TRUE)) %>%
addLegend(pal = pal1, values = ~Wahlbeteiligung, opacity = 0.7, title = NULL, labels = "",
position = "topright", labFormat = labelFormat(suffix = "%", digits = 2))
```
### by Voting District
```{r voter_tunrout_districts_map}
kreise$Wahlbeteiligung <- turnout_dist$Wahlbeteiligung
pal2 <- colorBin("plasma", domain = kreise$Wahlbeteiligung, reverse = TRUE)
labels2 <- paste0(
kreise$WKR_NAME, ": ", round(kreise$Wahlbeteiligung * 100, 1), "%"
) %>% lapply(htmltools::HTML)
leaflet(kreise) %>%
addProviderTiles(providers$Stamen.TonerLite) %>% # oder $Esri
addPolygons(weight = 1, color = "black", fillColor = ~pal2(Wahlbeteiligung),
dashArray = "4", fillOpacity = 0.4, label = labels2,
highlightOptions = highlightOptions(weight = 3, color = "#800000",
dashArray = "", fillOpacity = .8,
bringToFront = TRUE)) %>%
addLegend(pal = pal2, values = ~Wahlbeteiligung, opacity = 0.7, title = NULL, labels = "",
position = "topright", labFormat = labelFormat(suffix = "%", digits = 2))
```