-
Notifications
You must be signed in to change notification settings - Fork 6
/
fig_S1_S4_maps.Rmd
314 lines (253 loc) · 11.6 KB
/
fig_S1_S4_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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
---
title: 'Biodiversity n and var two-panel figures'
author: "*Compiled on `r date()` by `r Sys.info()['user']`*"
output:
html_document:
code_folding: hide
toc: true
toc_depth: 3
toc_float: yes
number_sections: true
theme: cerulean
highlight: haddock
includes:
in_header: '~/github/src/templates/ohara_hdr.html'
pdf_document:
toc: true
---
``` {r setup, echo = TRUE, message = FALSE, warning = FALSE}
knitr::opts_chunk$set(fig.width = 6, fig.height = 4, fig.path = 'figs/',
echo = TRUE, message = FALSE, warning = FALSE)
library(raster)
library(data.table)
library(sf)
source('https://raw.githubusercontent.com/oharac/src/master/R/common.R') ###
### includes library(tidyverse); library(stringr); dir_M points to ohi directory
dir_git <- here()
source(file.path(dir_git, '_setup/common_fxns.R'))
```
# Summary
Create a set of maps of the distribution of biodiversity intactness - all species assessed and mapped by IUCN. These maps are generated at 10 km^2^ resolution in a Gall-Peters projection. These maps will be generated using all comprehensively-assessed species:
* S1: Number of species for mean/var calculations
* S3: Variance of risk
# Data sources
* IUCN species API: IUCN. (2019). The IUCN Red List of Threatened Species. Version 2019-2.
* IUCN species shapefiles: IUCN. (2019). The IUCN Red List of Threatened Species. Version 2019-2. Retrieved August 2019, from http://www.iucnredlist.org
* BirdLife International shapefiles: BirdLife International and Handbook of the Birds of the World. (2018). Bird species distribution maps of the world. Version 7.0. Available at http://datazone.birdlife.org/species/requestdis
* Marine Ecoregions of the World: Spalding, M. D., Fox, H. E., Allen, G. R., Davidson, N., Ferdaña, Z. A., Finlayson, M. A. X., … others. (2007). Marine ecoregions of the world: A bioregionalization of coastal and shelf areas. BioScience, 57(7), 573–583.
# Methods
## Spatial distribution of N spp: comprehensively assessed spp
From the 1a and 1b biodiversity risk map scripts, gather the rasters for the various maps:
* N_spp risk (unweighted and range-rarity-weighted)
* Var risk (unweighted and range-rarity-weighted)
``` {r get_rasts}
nspp_un_rast <- raster(file.path(dir_output, 'n_spp_risk_raster_comp.tif'))
nspp_rr_rast <- raster(file.path(dir_output, 'sr_rr_risk_raster_comp.tif'))
var_un_rast <- raster(file.path(dir_output, 'var_risk_raster_comp.tif'))
var_rr_rast <- raster(file.path(dir_output, 'var_rr_risk_raster_comp.tif'))
```
### And now, the maps
The four-panel map chunks create two maps, with two density plots as scales; first map is for uniform-weighting, second is for range-rarity weighting.
### N spp maps
``` {r fig S1 a b n_spp maps}
### Log-transform nspp rasters for more interesting visual scaling
nspp_un_log <- log10(nspp_un_rast) # range 0, 3.146748
nspp_rr_log <- log10(nspp_rr_rast) # -8.23878, -0.9510185
### aggregate rasters for faster testing:
# nspp_un_rast <- nspp_un_rast %>% aggregate(10)
# nspp_rr_rast <- nspp_rr_rast %>% aggregate(10)
nspp_map_df <- data.frame(val_1 = values(nspp_un_log),
val_2 = values(nspp_rr_log)) %>%
cbind(coordinates(nspp_un_log)) %>%
filter(!is.na(val_1))
nspp_cols <- c(viridis::viridis(4, direction = -1))
### set up a dataframe of values to craft a color bar using geom_segment
### separate for each map due to incompatibility of scales
colorbar_df1 <- data.frame(x = seq(0, max(nspp_map_df$val_1),
length.out = 1000),
y = -1)
lbls1 <- c(1, 10, 100, 1000)
brks1 <- c(0, 1, 2, 3)
lims1 <- c(0, max(nspp_map_df$val_1))
colorbar_df2 <- data.frame(x = seq(min(nspp_map_df$val_2),
max(nspp_map_df$val_2),
length.out = 1000),
y = -1)
lbls2 <- c('1e-8', '1e-6', '1e-4', '1e-2', '1')
brks2 <- c(-8, -6, -4, -2, 0)
lims2 <- c(min(nspp_map_df$val_2), max(nspp_map_df$val_2))
land_poly <- sf::read_sf(file.path(dir_spatial, 'ne_10m_land',
'ne_10m_land_no_casp.shp')) %>%
st_transform(gp_proj4)
map1 <- ggplot(nspp_map_df) +
geom_raster(aes(x, y, fill = val_1), show.legend = FALSE) +
geom_sf(data = land_poly, aes(geometry = geometry),
fill = 'grey96', color = 'grey40', size = .10) +
ggtheme_map() +
theme(plot.margin = unit(c(.2, 0, .1, .5), units = 'cm')) +
coord_sf(datum = NA) + ### ditch graticules
scale_fill_gradientn(colors = nspp_cols, limits = lims1,
labels = lbls1, breaks = brks1) +
scale_x_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0))
map2 <- ggplot(nspp_map_df) +
geom_raster(aes(x, y, fill = val_2), show.legend = FALSE) +
geom_sf(data = land_poly, aes(geometry = geometry),
fill = 'grey96', color = 'grey40', size = .10) +
ggtheme_map() +
theme(plot.margin = unit(c(.1, 0, .2, .5), units = 'cm')) +
coord_sf(datum = NA) + ### ditch graticules
scale_fill_gradientn(colors = nspp_cols, limits = lims2,
labels = lbls2, breaks = brks2) +
scale_x_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0))
###################
dens1 <- ggplot(nspp_map_df) +
ggtheme_plot() +
geom_vline(xintercept = mean(nspp_map_df$val_1, na.rm = TRUE)) +
geom_segment(data = colorbar_df1,
aes(x = x, xend = x, color = x),
y = 0, yend = -10, size = 1,
show.legend = FALSE) +
geom_density(aes(x = val_1, ..scaled..), adjust = 5,
alpha = .3, size = .25, fill = 'grey30') +
scale_color_gradientn(colors = nspp_cols, limits = lims1,
labels = lbls1, breaks = brks1) +
theme(axis.text.x = element_blank(),
axis.title = element_blank(),
panel.grid.major.x = element_blank(),
plot.margin = unit(c(1, 0, 1, 0), units = 'cm')) +
scale_x_continuous(labels = lbls1, breaks = brks1,
expand = c(0, 0)) +
scale_y_continuous(limits = c(-.4, 1)) +
coord_flip()
dens2 <- ggplot(nspp_map_df) +
ggtheme_plot() +
geom_vline(xintercept = mean(nspp_map_df$val_2, na.rm = TRUE)) +
geom_segment(data = colorbar_df2,
aes(x = x, xend = x, color = x),
y = 0, yend = -10, size = 1,
show.legend = FALSE) +
geom_density(aes(x = val_2, ..scaled..),
adjust = 5,
alpha = .3, size = .25, fill = 'grey30') +
scale_color_gradientn(colors = nspp_cols, limits = lims2,
labels = lbls2, breaks = brks2) +
theme(axis.text.x = element_blank(),
axis.title = element_blank(),
panel.grid.major.x = element_blank(),
plot.margin = unit(c(1, 0, 1, 0), units = 'cm')) +
scale_x_continuous(labels = lbls2, breaks = brks2,
expand = c(0, 0)) +
scale_y_continuous(limits = c(-.4, 1)) +
coord_flip()
panel_left <- cowplot::plot_grid(map1, dens1,
axis = 'b',
rel_widths = c(5, 1))
panel_right <- cowplot::plot_grid(map2, dens2,
axis = 'b',
rel_widths = c(5, 1))
four_panel <- cowplot::plot_grid(panel_left, panel_right,
labels = c('A', 'B'),
nrow = 2, ncol = 1, align = 'v')
figS1_path <- file.path(dir_git, 'ms_figures/fig_S1_nspp_maps.png')
ggsave(plot = four_panel,
filename = figS1_path,
width = 5, height = 5, units = 'in', dpi = 300)
```
![](ms_figures/fig_S1_nspp_maps.png)
### Variance maps
``` {r fig S4 a b var maps}
var_cols <- c(viridis::viridis(6, direction = -1))
### set up a dataframe of values to craft a color bar using geom_segment
colorbar_df <- data.frame(x = seq(0, .5, length.out = 1000), y = -1)
lbls = c(0, .1, .2, .3, .4, .5)
brks = c(0, .1, .2, .3, .4, .5)
lims = c(0, .5)
land_poly <- sf::read_sf(file.path(dir_spatial, 'ne_10m_land',
'ne_10m_land_no_casp.shp')) %>%
st_transform(gp_proj4)
var_map_df <- data.frame(val_1 = values(var_un_rast),
val_2 = values(var_rr_rast)) %>%
cbind(coordinates(var_un_rast)) %>%
filter(!is.na(val_1))
### unweighted max = .18
### rr weighted max = .499
map1 <- ggplot(var_map_df) +
geom_raster(aes(x, y, fill = val_1), show.legend = FALSE) +
geom_sf(data = land_poly, aes(geometry = geometry),
fill = 'grey96', color = 'grey40', size = .10) +
ggtheme_map() +
theme(plot.margin = unit(c(.2, 0, .1, .5), units = 'cm')) +
coord_sf(datum = NA) + ### ditch graticules
scale_fill_gradientn(colors = var_cols, labels = lbls,
breaks = brks, limits = lims) +
scale_x_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0))
map2 <- ggplot(var_map_df) +
geom_raster(aes(x, y, fill = val_2), show.legend = FALSE) +
geom_sf(data = land_poly, aes(geometry = geometry),
fill = 'grey96', color = 'grey40', size = .10) +
ggtheme_map() +
theme(plot.margin = unit(c(.1, 0, .2, .5), units = 'cm')) +
coord_sf(datum = NA) + ### ditch graticules
scale_fill_gradientn(colors = var_cols, labels = lbls,
breaks = brks, limits = lims) +
scale_x_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0))
###################
dens1 <- ggplot(var_map_df) +
ggtheme_plot() +
geom_vline(xintercept = mean(var_map_df$val_1, na.rm = TRUE)) +
geom_segment(data = colorbar_df,
aes(x = x, xend = x, color = x),
y = 0, yend = -10, size = 1,
show.legend = FALSE) +
geom_density(aes(x = val_1, ..scaled..),
adjust = 5,
alpha = .3, size = .25, fill = 'grey30') +
scale_color_gradientn(colors = var_cols, labels = lbls,
breaks = brks, limits = lims) +
theme(axis.text.x = element_blank(),
axis.title = element_blank(),
panel.grid.major.x = element_blank(),
plot.margin = unit(c(1, 0, 1, 0), units = 'cm')) +
scale_x_continuous(labels = lbls, breaks = brks,
expand = c(0, 0)) +
scale_y_continuous(limits = c(-.4, 1)) +
coord_flip()
dens2 <- ggplot(var_map_df) +
ggtheme_plot() +
geom_vline(xintercept = mean(var_map_df$val_2, na.rm = TRUE)) +
geom_segment(data = colorbar_df,
aes(x = x, xend = x, color = x),
y = 0, yend = -10, size = 1,
show.legend = FALSE) +
geom_density(aes(x = val_2, ..scaled..),
adjust = 5,
alpha = .3, size = .25, fill = 'grey30') +
scale_color_gradientn(colors = var_cols, labels = lbls,
breaks = brks, limits = lims) +
theme(axis.text.x = element_blank(),
axis.title = element_blank(),
panel.grid.major.x = element_blank(),
plot.margin = unit(c(1, 0, 1, 0), units = 'cm')) +
scale_x_continuous(labels = lbls, breaks = brks,
expand = c(0, 0)) +
scale_y_continuous(limits = c(-.4, 1)) +
coord_flip()
panel_left <- cowplot::plot_grid(map1, dens1,
axis = 'b',
rel_widths = c(5, 1))
panel_right <- cowplot::plot_grid(map2, dens2,
axis = 'b',
rel_widths = c(5, 1))
four_panel <- cowplot::plot_grid(panel_left, panel_right,
labels = c('A', 'B'),
nrow = 2, ncol = 1, align = 'v')
figS3_path <- file.path(dir_git, 'ms_figures/fig_S4_var_maps.png')
ggsave(plot = four_panel,
filename = figS3_path,
width = 5, height = 5, units = 'in', dpi = 300)
```
![](ms_figures/fig_S4_var_maps.png)