-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path09 - Mapping.R
160 lines (143 loc) · 5.87 KB
/
09 - Mapping.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# 09 - Mapping
rm(list=ls())
library(tidyverse)
library(terra)
library(sf)
library(rnaturalearth)
library(tmap)
load("Planning_units.RData")
ne_countries(scale = 50, returnclass = "sf") %>% st_transform(st_crs(pus)) -> countries
################################################################################
# Figure S1
# Map of conservation cost
################################################################################
png("Figures/Map_cost.png",
width=20,height=12,res=600,units="cm")
print(
tm_shape(mutate(pus, cost=cost/1000)) +
tm_fill("cost", style="log10_pretty", legend.is.portrait = F, legend.show = T) +
tm_shape(filter(pus, status_0 == 1))+
tm_borders(col = "blue", lwd=0.2) +
tm_shape(countries, bbox = res) +
tm_polygons(col="lightgray", lwd=0.2) +
tm_legend(legend.outside = T, legend.outside.position = "bottom") +
tm_layout(main.title="Conservation cost (M€)", main.title.position = "center")
)
dev.off()
################################################################################
# Figure S2
# Map of sampling points
################################################################################
load("data/sampling.RData")
Diplodus_sampling %>%
group_by(SamplingCell) %>%
summarise(Long=mean(Longitude), Lat=mean(Latitude)) %>%
st_as_sf(coords=c("Long","Lat"),
crs=st_crs(4326)) %>%
st_transform(st_crs(pus)) -> Diplodus_points
Mullus_sampling %>%
group_by(SamplingCell) %>%
summarise(Long=mean(Longitude), Lat=mean(Latitude)) %>%
st_as_sf(coords=c("Long","Lat"),
crs=st_crs(4326)) %>%
st_transform(st_crs(pus)) -> Mullus_points
png("Figures/Sampling_points_Diplodus.png",width=20,height=8,units="cm",res=600)
tm_shape(mutate(pus, Diplodus_sargus=factor(Diplodus_sargus))) +
tm_fill("Diplodus_sargus",
palette = c("grey90","blue"),
legend.show=F) +
tm_shape(countries, bbox = pus) +
tm_polygons(col="lightgray", lwd=0.2) +
tm_shape(Diplodus_points) +
tm_dots(size=0.25)
dev.off()
png("Figures/Sampling_points_Mullus.png",width=20,height=8,units="cm",res=600)
tm_shape(mutate(pus, Mullus_surmuletus=factor(Mullus_surmuletus))) +
tm_fill("Mullus_surmuletus",
palette = c("grey90","blue"),
legend.show=F) +
tm_shape(countries, bbox = pus) +
tm_polygons(col="lightgray", lwd=0.2) +
tm_shape(Mullus_points) +
tm_dots(size=0.25)
dev.off()
################################################################################
# Figure S7 and S8
# Spatially interpolated PCA scores for D. sargus and M. surmuletus
################################################################################
# Diplodus
g_rast <- rast("Results/Diplodus_allAxes_8068.grd")
png(paste0("Genetic_rasters_Diplodus_1.png"),width=20,height=24,units="cm",res=300)
par(mfrow=c(4,3))
for (i in 1 : 12) {
plot(g_rast,i,mar=c(2,0.5,0.5,0.5),axes=F,legend="bottom",main=paste("Axis",i))
polys(countries,col="gray",lwd=0.01)
}
dev.off()
png(paste0("Genetic_rasters_Diplodus_2.png"),width=20,height=24,units="cm",res=300)
par(mfrow=c(4,3))
for (i in 13 : 17) {
plot(g_rast,i,mar=c(2,0.5,0.5,0.5),axes=F,legend="bottom",main=paste("Axis",i))
polys(countries,col="gray",lwd=0.01)
}
dev.off()
# Mullus
g_rast <- rast("Results/Mullus_allAxes_2753.grd")
# Read countries for plotting maps
ne_countries(scale = 50, returnclass = "sf") %>% st_transform(st_crs(g_rast)) -> countries
png(paste0("Genetic_rasters_Mullus_1.png"),width=20,height=24,units="cm",res=300)
par(mfrow=c(4,3))
for (i in 1 : 12) {
plot(g_rast,i,mar=c(2,0.5,0.5,0.5),axes=F,legend="bottom",main=paste("Axis",i))
polys(countries,col="gray",lwd=0.01)
}
dev.off()
png(paste0("Genetic_rasters_Mullus_2.png"),width=20,height=24,units="cm",res=300)
par(mfrow=c(4,3))
for (i in 13 : 24) {
plot(g_rast,i,mar=c(2,0.5,0.5,0.5),axes=F,legend="bottom",main=paste("Axis",i))
polys(countries,col="gray",lwd=0.01)
}
dev.off()
png(paste0("Genetic_rasters_Mullus_3.png"),width=20,height=24,units="cm",res=300)
par(mfrow=c(4,3))
for (i in 25 : 26) {
plot(g_rast,i,mar=c(2,0.5,0.5,0.5),axes=F,legend="bottom",main=paste("Axis",i))
polys(countries,col="gray",lwd=0.01)
}
dev.off()
################################################################################
# Figure S9
# Map of priority sites for protecting 15% of species ranges without explicit genetic objectives.
################################################################################
load("Results/Results_Extension_Amount.RData")
# Calculate selection frequency
selections <- res_so %>%
st_drop_geometry() %>% select(paste0("solution_",c(1:100)))
selection_frequency <- rowSums(selections) / ncol(selections)
# Add selection frequency
pus %>%
mutate(sel_frequency =
# Divide selection frequency into breaks
selection_frequency %>%
cut(breaks=seq(0,1,0.2),include.lowest=T,right=F) %>%
# Make factor with levels
factor(levels = c("Existing","[0,0.2)","[0.2,0.4)","[0.4,0.6)","[0.6,0.8)","[0.8,1]"))
) %>%
# Replace selection_frequency of existing reserves with level "Existing"
mutate(selection_frequency = replace(sel_frequency,
which(pus$status_0 == 1), # These are the existing reserves
"Existing")
) -> pus_map
png("Figures/Maps_selections/Map_selection_frequency_speciesOnly.png",
width=20,height=12,res=600,units="cm")
print(
tm_shape(pus_map) +
tm_fill("selection_frequency", palette=c("gold",brewer.pal(5,"Greens")),
legend.is.portrait = F, legend.show = T) +
tm_shape(countries, bbox = res) +
tm_polygons(col="lightgray", lwd=0.2) +
tm_legend(legend.outside = T, legend.outside.position = "bottom") +
tm_layout(main.title="Range only", main.title.position = "center")
)
dev.off()