-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtmap.R
More file actions
87 lines (63 loc) · 2.86 KB
/
Copy pathtmap.R
File metadata and controls
87 lines (63 loc) · 2.86 KB
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
# Script for building maps based on country data
# 2024
# Tutorial
# https://r-tmap.github.io/tmap-book/visual-variables.html
# Install packages
install.packages("tmap")
install.packages("sf")
install.packages("rnaturalearth")
# Load
require(sf)
require(tmap)
require(rnaturalearth)
# List relevant countries here
target <- ne_countries(type = "countries", country = c('Bangladesh',
'Bhutan',
'Brunei',
'Cambodia',
'China',
'India',
'Indonesia',
'Laos',
'Malaysia',
'Myanmar',
'Nepal',
'Philippines',
'Singapore',
'Sri Lanka',
'Thailand',
'Timor-Leste',
'Vietnam'))
target@data$name #check names
# Pick up colours of our preference here
colours()
# Map
worldmap_bat_coronavirus <- tm_shape(World) +
tm_polygons(col = "gray")+
tm_shape(target) +
tm_polygons(col = "maroon")+
tm_text("name_en", size = 0.5)+
tm_compass(type = "4star", size = 1, position = c("right", "top"))+
tm_scale_bar(breaks = c(0, 2000, 4000), text.size = 1) # meters
worldmap_bat_coronavirus
# Exporting map
setwd("C://Users//rdelaram//Documents//") # change it according to your folder path
tmap_save(worldmap_bat_coronavirus, "worldmap_bat_coronavirus.png",
width = 3000, height = 2100, dpi = 300)
# Zoom in
data("World")
bbox_zoom <- st_bbox(World %>% filter(name %in% c("Bhutan", "India",
"China", "Nepal",
'Indonesia', 'Papua New Guinea')))
worldmap_bat_coronavirus_zoom <- tm_shape(World, bbox = bbox_zoom) +
tm_polygons(col = "gray")+
tm_shape(target) +
tm_polygons(col = "maroon")+
tm_text("name_en", size = 0.5)+
tm_compass(type = "4star", size = 1.2, position = c("right", "top"))+
tm_scale_bar(breaks = c(0, 1000, 2000), text.size = 0.8,
position = c("left", "bottom")) # meters
worldmap_bat_coronavirus_zoom
tmap_save(worldmap_bat_coronavirus_zoom, "zoomed_map_bat_coronavirus.png",
width = 3000, height = 2100, dpi = 300)
#--------------------------------------------------