forked from cabuelow/intro-rshiny-mapping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path001_leaflet-map.R
46 lines (37 loc) · 1.14 KB
/
001_leaflet-map.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
library(sf)
library(dplyr)
library(leaflet)
# make an interactive leaflet map
m <- leaflet() %>%
addTiles()
m
# read in spatial data
pop <- st_read('data/population.gpkg')
reefs <- st_read('data/reefs.gpkg')
# make interactive leaflet map
m <- leaflet() %>%
addTiles() %>%
addCircleMarkers(data = pop,
weight = 0.1,
radius = ~log(as.numeric(pop$POP_MAX)/1e5)) %>%
addPolygons(data = reefs,
weight = 0.7,
color = 'red')
m
# add some pop-ups
pop_up <- st_drop_geometry(pop) %>%
mutate(popup = paste0("<span style='font-size: 120%'><strong>", NAME ,"</strong></span><br/>",
"<strong>", "Country: ", "</strong>", SOV0NAME,
"<br/>",
"<strong>", "Max population size: ", "</strong>", POP_MAX)) %>%
pull(popup)
m <- leaflet() %>%
addTiles() %>%
addCircleMarkers(data = pop,
weight = 0.1,
radius = ~log(as.numeric(pop$POP_MAX)/1e5),
popup = pop_up) %>%
addPolygons(data = reefs,
weight = 0.7,
color = 'red')
m