-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_sites.R
148 lines (111 loc) · 5.62 KB
/
map_sites.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
library(raster)
library(ggspatial)
library(ggrepel)
library(cowplot)
# If changes applied re-run source, ~ 10 min
# source('maps_base.R')
load('maps_base.RData')
# High quality versions ---------------------------------------------------
# 1. Map, numeric codes, ggrepel not aligned ------------------------------------------------------
# a) Site labels
# b) Select countries to plot
countries_sfn <- unique(sapply(strsplit(sfn_allsites$si_code,"_"),"[[",1))
countries_label <- c('ARG','BRA','COL','CRI','CHN','GUF','IDN','ISR','KOR','MDG','MEX','NZL','RUS','SEN','THA','UZB')
countries_europe <- c('AUT','CHE','CZE','DEU','ESP','FIN','FRA','GBR','HUN','ITA','NLD','PRT','SWE')
countries_america <- c('CAN','USA')
countries_austral <- c('AUS')
countries_africa <- c('MDG','ZAF')
# c) Add numeric codes
sfn_allsites_country<- sfn_allsites %>%
mutate(country=sapply(strsplit(si_code,"_"),"[[",1),
num_code = as.integer(factor(si_code)))
# d) Create maps
# world
sfnsites_world <- globforest_rec_0_1 +
geom_point(data=sfn_allsites,aes(x=si_long,y=si_lat),shape=21,color='black',fill='yellow')+
geom_text_repel(data = subset(sfn_allsites_country,country%in%countries_label),
aes(si_long, si_lat, label = num_code), size = 3,
segment.alpha=0.5, nudge_x = -0.35,direction = "y",hjust = 1,
box.padding = unit(0.1, 'lines'), force = 0.5)+geom_label_repel()+guides(fill='none')+xlab(NULL)+ylab(NULL)
# europe
sfnsites_europe<- globforestrec_rec_0_1 +
geom_point(data=sfn_allsites,aes(x=si_long,y=si_lat),shape=21,color='black',fill='yellow')+
geom_text_repel(data = subset(sfn_allsites_country,country%in%countries_europe),
aes(si_long, si_lat, label = num_code), size = 3,
segment.alpha=0.5, nudge_y = -0.35,direction = "y",hjust = 1,
box.padding = unit(0.1, 'lines'), force = 0.5)+
coord_sf(xlim = c(-20, 40), ylim = c(32, 67), expand = FALSE)+
geom_label_repel()+guides(fill='none')+xlab(NULL)+ylab(NULL)
# america
sfnsites_america<- globforest_rec_0_1 +
geom_point(data=sfn_allsites,aes(x=si_long,y=si_lat),shape=21,color='black',fill='yellow')+
geom_text_repel(data = subset(sfn_allsites_country,country%in%countries_america),
aes(si_long, si_lat, label = num_code), size = 3,
segment.alpha=0.5, nudge_x = -0.35,direction = "y",hjust = 1,
box.padding = unit(0.1, 'lines'), force = 0.5)+
coord_sf(xlim = c(-130, -60), ylim = c(30, 55), expand = FALSE)+
geom_label_repel()+guides(fill='none')+xlab(NULL)+ylab(NULL)
# austral
sfnsites_austral<- globforest_rec_0_1 +
geom_point(data=sfn_allsites,aes(x=si_long,y=si_lat),shape=21,color='black',fill='yellow')+
geom_text_repel(data = subset(sfn_allsites_country,country%in%countries_austral),
aes(si_long, si_lat, label = num_code), size = 3,
segment.alpha=0.5, nudge_x = -0.35,
box.padding = unit(0.1, 'lines'), force = 0.5)+
coord_sf(xlim = c(110, 162), ylim = c(-10, -50), expand = FALSE)+
geom_label_repel()+guides(fill='none')+xlab(NULL)+ylab(NULL)
# africa
sfnsites_africa<- globforest_rec_0_1 +
geom_point(data=sfn_allsites,aes(x=si_long,y=si_lat),shape=21,color='black',fill='yellow')+
geom_text_repel(data = subset(sfn_allsites_country,country%in%countries_africa), aes(si_long, si_lat, label = num_code), size = 3,
box.padding = unit(0.1, 'lines'), force = 0.5)+
coord_sf(xlim = c(10, 50), ylim = c(-10, -40), expand = FALSE)+
geom_label_repel()+guides(fill='none')+xlab(NULL)+ylab(NULL)
# e) Build figure
sfn_sitesmap_numcodes <- plot_grid(
# row 1
plot_grid(sfnsites_world, labels='(a)'),
# row 2
plot_grid(sfnsites_europe, sfnsites_america,labels=c('(b)','(c)'),rel_widths=c(1,1)),
# row3
plot_grid(sfnsites_austral, sfnsites_africa, labels=c('(d)','(e)')),
#
labels=c('', '',''), ncol=1)
# save_plot('./output/figs/sfn_sitesmap.tiff', sfn_sitesmap)
# save_plot('./output/figs/sfn_sitesmap.eps', sfn_sitesmap)
# 2. Map, no codes ---------------------------------------------
# d) Create maps
# world
sfnsites_world_nc <- globforest_rec_0_1 +
geom_point(data=sfn_allsites,aes(x=si_long,y=si_lat),shape=21,color='black',fill='yellow')+
guides(fill='none')+xlab(NULL)+ylab(NULL)
# europe
sfnsites_europe_nc<- globforest_rec_0_1 +
geom_point(data=sfn_allsites,aes(x=si_long,y=si_lat),shape=21,color='black',fill='yellow')+
coord_sf(xlim = c(-20, 40), ylim = c(32, 67), expand = FALSE)+
guides(fill='none')+xlab(NULL)+ylab(NULL)
# america
sfnsites_america_nc<- globforest_rec_0_1 +
geom_point(data=sfn_allsites,aes(x=si_long,y=si_lat),shape=21,color='black',fill='yellow')+
coord_sf(xlim = c(-130, -60), ylim = c(30, 55), expand = FALSE)+
guides(fill='none')+xlab(NULL)+ylab(NULL)
# austral
sfnsites_austral_nc<- globforest_rec_0_1 +
geom_point(data=sfn_allsites,aes(x=si_long,y=si_lat),shape=21,color='black',fill='yellow')+
coord_sf(xlim = c(110, 162), ylim = c(-10, -50), expand = FALSE)+
guides(fill='none')+xlab(NULL)+ylab(NULL)
# africa
sfnsites_africa_nc<- globforest_rec_0_1 +
geom_point(data=sfn_allsites,aes(x=si_long,y=si_lat),shape=21,color='black',fill='yellow')+
coord_sf(xlim = c(10, 50), ylim = c(-10, -40), expand = FALSE)+
guides(fill='none')+xlab(NULL)+ylab(NULL)
# e) Build figure
sfn_sitesmap_nocodes <- plot_grid(
# row 1
plot_grid(sfnsites_world_nc, labels='(a)'),
# row 2
plot_grid(sfnsites_europe_nc, sfnsites_america_nc,labels=c('(b)','(c)'),rel_widths=c(1,1)),
# row3
plot_grid(sfnsites_austral_nc, sfnsites_africa_nc, labels=c('(d)','(e)')),
#
labels=c('', '',''), ncol=1)