-
Notifications
You must be signed in to change notification settings - Fork 3
/
3-maps.R
165 lines (133 loc) · 5.29 KB
/
3-maps.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
## Libraries
if (!require("pacman")) install.packages("pacman")
pacman::p_load(tidyverse,
sf,
here,
leaflet,
leaflet.extras,
leafpop,
cartography,
htmlwidgets)
## Folders for outputs
dir.create(here("visualizations"))
dir.create(here("visualizations", "maps"))
setwd(here("visualizations", "maps"))
## NUTS2 regions maps
region <- lau_matched %>%
pull(region) %>%
unique()
for (i in region) {
lau_i <- lau_matched %>% filter(region == i)
bins <- c(0,10,20,30,40,50,60,70,80,90,100,120,140,160,180,200,1200)
qpal <- colorBin(palette = cartography::carto.pal("turquoise.pal", 20),
domain = lau_i$avg_d,
bins = bins)
map <- leaflet() %>%
addProviderTiles(providers$CartoDB.PositronNoLabels) %>%
addPolygons(data = lau_i,
fillColor = ~qpal(lau_i$avg_d),
fillOpacity = 1,
smoothFactor = .2,
color = "#5d5d5d",
opacity = .2,
weight = .25,
label = ~City,
group = "City",
popup = popupTable(lau_i,
zcol = c(12:15),
row.numbers = F,
feature.id = F)) %>%
addLegend(pal = qpal,
values = lau_i$avg_d,
opacity = 1,
position = "bottomright",
title = "Download speed (Mbps)") %>%
addSearchFeatures(targetGroups = 'City',
options = searchFeaturesOptions(zoom = 11,
openPopup = T,
hideMarkerOnCollapse = T))
saveWidget(map, i %>% paste0(".html"), selfcontained = T)
}
## Countries map
country <- lau_matched %>%
pull(Country) %>%
unique()
for (i in country) {
lau_i <- lau_matched %>% filter(Country == i)
bins <- c(0,10,20,30,40,50,60,70,80,90,100,120,140,160,180,200,1200)
qpal <- colorBin(palette = cartography::carto.pal("turquoise.pal", 20),
domain = lau_i$avg_d,
bins = bins)
map <- leaflet() %>%
addProviderTiles(providers$CartoDB.PositronNoLabels) %>%
addPolygons(data = lau_i,
fillColor = ~qpal(lau_i$avg_d),
fillOpacity = 1,
smoothFactor = .2,
color = "#5d5d5d",
opacity = .2,
weight = .25,
label = ~City,
group = "City",
popup = popupTable(lau_i,
zcol = c(12:15),
row.numbers = F,
feature.id = F)) %>%
addLegend(pal = qpal,
values = lau_i$avg_d,
opacity = 1,
position = "bottomright",
title = "Download speed (Mbps)") %>%
addSearchFeatures(targetGroups = 'City',
options = searchFeaturesOptions(zoom = 11,
openPopup = T,
hideMarkerOnCollapse = T))
saveWidget(map, i %>% paste0(".html"), selfcontained = T)
}
## European maps
euro_maps <- c("nuts_0", "nuts_2", "nuts_3")
for (i in euro_maps) {
level_i <- read_csv(here("data", i, i %>% paste("2022_1.csv", sep = "_"))) %>%
left_join(get(i)) %>%
mutate(Name = name,
"Average Download Speed" = avg_d %>% paste0(" Mbps"),
"Average Upload Speed" = avg_u %>% paste0(" Mbps"),
"Average Latency" = avg_l %>% paste0(" ms")) %>%
st_set_geometry(.$geometry)
bins <- c(0,10,20,30,40,50,60,70,80,90,100,120,140,160,180,200,1200)
qpal <- colorBin(palette = cartography::carto.pal("turquoise.pal", 20),
domain = level_i$avg_d,
bins = bins)
map <- leaflet() %>%
addProviderTiles(providers$CartoDB.PositronNoLabels) %>%
addPolygons(data = level_i,
fillColor = ~qpal(level_i$avg_d),
fillOpacity = 1,
smoothFactor = .2,
color = "#5d5d5d",
opacity = .2,
weight = .25,
label = ~Name,
group = "Name",
popup = popupTable(level_i,
zcol = c(8:11),
row.numbers = F,
feature.id = F)) %>%
addPolylines(data = nuts_0 %>%
st_cast("MULTILINESTRING"),
fillColor = NULL,
color = "#FAF9F6",
opacity = 1,
weight = .65) %>%
addLegend(pal = qpal,
values = lau_i$avg_d,
opacity = 1,
position = "bottomright",
title = "Download speed (Mbps)") %>%
addSearchFeatures(targetGroups = 'City',
options = searchFeaturesOptions(zoom = 11,
openPopup = T,
hideMarkerOnCollapse = T)) %>%
setView(13.3, 47.13, 5)
saveWidget(map, i %>% paste0(".html"), selfcontained = T)
}