-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathinteractive-maps.Rmd
88 lines (64 loc) · 1.39 KB
/
interactive-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
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
---
title: "Practice Interactive Maps"
author: "Angela Li"
date: "5/29/2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Load packages
```{r}
library(tmap)
library(mapview)
library(leaflet)
library(spData)
library(dplyr)
```
## Data wrangling
```{r}
urban10 <- filter(urban_agglomerations, year == 2010)
urban15 <- filter(urban_agglomerations, year == 2015)
```
## Arrange tmaps
```{r}
urban10_map <- qtm(urban10)
urban15_map <- qtm(urban15)
tmap_mode("view")
tmap_arrange(urban10_map, urban15_map, ncol = 2)
```
```{r}
leaflet::providers
```
## Make static tmap
```{r}
tmap_mode("plot")
tm_shape(world) +
tm_polygons() +
tm_shape(urban) +
tm_dots(size = "population_millions")
```
## Make interactive tmap
```{r}
tmap_mode("view")
tm_shape(urban) +
tm_dots("population_millions") +
tm_basemap(server = "Stamen.Terrain")
```
## Make mapview interactive map
```{r}
mapview(urban10, popup = popupTable(urban10,
zcol = c("year",
"country_or_area",
"urban_agglomeration",
"population_millions")))
```
```{r}
viewExtent(urban10, alpha.regions = 0.5)
```
# Leaflet map
```{r}
leaflet(data = urban10) %>%
addTiles() %>%
addMarkers(popup = ~urban_agglomeration)
```