-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisd_crete_analysis_summary.Rmd
267 lines (218 loc) · 9.3 KB
/
isd_crete_analysis_summary.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
---
title: "Crete soil microbiome summary"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
pdf_document:
toc: yes
toc_depth: '2'
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Load the data
```{r, warning=FALSE, message=FALSE, echo=T, results='hide'}
library(tidyverse)
library(ggnewscale)
library(sf)
library(terra)
library(raster)
library(knitr)
library(kableExtra)
source("functions.R")
```
```{r, warning=FALSE, message=FALSE, echo=T, results='hide'}
## biodiversity
community_matrix_l <- read_delim("../results/community_matrix_l.tsv",delim="\t")
crete_biodiversity <- read_delim("../results/crete_biodiversity_asv.tsv",delim="\t")
asv_metadata <- read_delim("../results/asv_metadata.tsv",delim="\t")
genera_phyla_samples <- read_delim("../results/genera_phyla_samples.tsv",delim="\t")
# Metadata
metadata <- read_delim("../results/sample_metadata.tsv", delim="\t")
metadata$elevation_bin <- factor(metadata$elevation_bin,
levels=unique(metadata$elevation_bin)[order(sort(unique(metadata$elevation_bin)))])
samples_ucie_nmds_genera <- read_delim("../results/samples_ucie_nmds_genera.tsv")
## spatial
locations_spatial <- metadata %>%
st_as_sf(coords=c("longitude", "latitude"),
remove=F,
crs="WGS84")
crete_shp <- sf::st_read("../spatial_data/crete/crete.shp")
crete_peaks <- read_delim("../spatial_data/crete_mountain_peaks.csv", delim=";", col_names=T) %>%
st_as_sf(coords=c("X", "Y"),
remove=F,
crs="WGS84")
clc_crete_shp <- st_read("../spatial_data/clc_crete_shp/clc_crete_shp.shp")
crete_geology <- st_read("../spatial_data/crete_geology/crete_geology.shp")
natura_crete <- sf::st_read("../spatial_data/natura2000/natura2000_crete.shp")
wdpa_crete <- sf::st_read("../spatial_data/wdpa_crete/wdpa_crete.shp") %>% filter(DESIG_ENG=="Wildlife Refugee") %>%
mutate(DESIG_ENG = gsub("Wildlife Refugee", "Wildlife Refuge", DESIG_ENG))
natura_crete_land <- st_intersection(natura_crete, crete_shp)
natura_crete_land_sci <- natura_crete_land %>% filter(SITETYPE=="B")
# raster DEM hangling
dem_crete <- raster("../spatial_data/dem_crete/dem_crete.tif")
dem_crete_pixel <- as(dem_crete, "SpatialPixelsDataFrame")
dem_crete_df <- as.data.frame(dem_crete_pixel) %>% filter(dem_crete>0)
# raster bioclim 1 Annual Mean Temperature
bioclim1_crete <- raster("../spatial_data/world_clim_crete/crete_wc2.1_30s_bio_1.tif")
bioclim1_crete_pixel <- as(bioclim1_crete, "SpatialPixelsDataFrame")
bioclim1_crete_df <- as.data.frame(bioclim1_crete_pixel)
# raster bioclim 12 Annual Mean Precipitation
bioclim12_crete <- raster("../spatial_data/world_clim_crete/crete_wc2.1_30s_bio_12.tif")
bioclim12_crete_pixel <- as(bioclim12_crete, "SpatialPixelsDataFrame")
bioclim12_crete_df <- as.data.frame(bioclim12_crete_pixel)
# raster global aridity index
aridity_crete <- rast("../spatial_data/crete_aridity_index.tif")
aridity_crete[aridity_crete[] == 0 ] = NA
aridity_crete_df <- as.data.frame(aridity_crete, cells=TRUE)
aridity_crete_df$aridity <- aridity_crete_df$awi_pm_sr_yr*0.0001
aridity_crete_df$aridity_class <- cut(aridity_crete_df$aridity,
breaks=c(0,0.03,0.2,0.5, 0.65,0.9),
labels=c("Hyper Arid", "Arid", "Semi-Arid", "Dry sub-humid", "Humid"))
# raster desertification and Environmental Sensitive Areas Index
desertification_crete <- rast("../spatial_data/crete_desertification_risk/esa3rdp_crete.tif")
desertification_crete_cat <- read_delim("../spatial_data/crete_desertification_risk/esa3rdp_crete.tsv", delim="\t")
desertification_crete_df <- as.data.frame(desertification_crete,xy=T, cells=T)
# harmonised world soil database v2
hwsd2 <- rast("../spatial_data/hwsd2_crete/hwsd2_crete.tif")
# hswd metadata
# with trimws the leading spaces are removed for the values.
HWSD2_wrb4 <- read_delim("../spatial_data/hwsd2_crete/HWSD2_D_WRB4.tsv", delim="\t") |>
mutate(VALUE=trimws(VALUE)) |>
distinct(VALUE, CODE)
HWSD2_SMU <- read_delim("../spatial_data/hwsd2_crete/HWSD2_SMU.tsv", delim="\t") |>
distinct(HWSD2_SMU_ID, WRB4) |>
left_join(HWSD2_wrb4, by=c("WRB4"="CODE"))
```
# Crete data cube maps
Here are some maps of Crete with different layers.









# Table summary
A summary table of each order.
```{r}
# the number of samples per layer
classes <- c("LABEL2", "geology_na", "ESA_12CL", "aridity_class" )
classes_samples <- list()
for (i in seq_along(classes)){
print(i)
classes_samples[[i]] <- metadata |>
group_by(metadata[[classes[i]]]) |>
summarise(samples=n(),
taxa_richness=sum(taxa),
asv_richness=sum(asvs),
mean_shannon=mean(shannon),
sd_shannon=sd(shannon))
}
samples_total <- do.call(rbind, classes_samples)
colnames(samples_total)[1] <- c("class")
# the area of different layers in Crete
clc_label2_area <- clc_crete_shp |>
mutate(area_polygon=units::set_units(st_area(geometry),km^2)) |>
st_drop_geometry() |>
group_by(LABEL2) |>
rename(class=LABEL2) |>
group_by(class) |>
summarise(area=sum(area_polygon)) |>
mutate(category="CLC LABEL2")
geology_area <- crete_geology |>
st_make_valid() |>
mutate(area_polygon=units::set_units(st_area(geometry),km^2)) |>
st_drop_geometry() |>
rename(class=geology_na) |>
group_by(class) |>
summarise(area=sum(area_polygon)) |>
mutate(category="Geology")
desertification_crete_area <- terra::freq(desertification_crete) |>
as_tibble() |>
mutate(area=units::set_units(count*4.4,km^2)) |>
rename(class=value) |>
dplyr::select(class,area) |>
mutate(category="Desertification Risk")
aridity_area <- aridity_crete_df |>
as_tibble() |>
rename(class=aridity_class) |>
group_by(class) |>
summarise(cells=n()) |>
mutate(area=units::set_units(cells*0.69,km^2)) |>
dplyr::select(class,area) |>
mutate(category="Aridity class")
area_total <- do.call(rbind,
list(clc_label2_area,
geology_area,
desertification_crete_area,
aridity_area)) |>
left_join(samples_total) |>
mutate(area=round(area, digits=0), mean_shannon=round(mean_shannon, digits=2), sd_shannon=round(sd_shannon, digits=2))
write_delim(area_total, "../results/data_cube_summary_table.tsv", delim="\t")
area_total |> arrange(category, class, area) |> kbl() |> kable_styling(latex_options = "scale_down")
```
```{r}
#order_taxa <- endemic_species |>
# group_by(order) |>
# summarise(taxa=n())
#
#order_sites <- locations_shp |>
# distinct(order,decimalLatitude,decimalLongitude) |>
# group_by(order) |>
# summarise(sites=n())
#
#order_occ <- locations_shp |>
# group_by(order) |>
# summarise(occurrences=n()) |>
# st_drop_geometry()
#
#order_locations <- locations_grid |>
# distinct(CELLCOD, order) |>
# group_by(order) |>
# summarise(locations=n())
#
#order_iucn <- endemic_species_s_i |>
# pivot_wider(names_from=iucn,
# values_from=c(n_species,proportion),
# id_cols=order) |>
# group_by(order) |>
# rowwise() |>
# mutate(threatened=sum(n_species_EN,n_species_VU,n_species_CR,na.rm=TRUE),
# proportion_threatened=threatened/sum(n_species_EN,n_species_VU,n_species_CR,`n_species_NT/LC`, na.rm=TRUE))
#
#order_paca <- endemic_species_s_o |>
# pivot_wider(names_from=paca,
# values_from=c(n_species,proportion),
# id_cols=order)
#
#order_total_l <- list(order_taxa,order_sites,order_occ,order_locations,order_iucn,order_paca)
#
#order_total <- order_total_l |> reduce(full_join, by="order")
#
#total_iucn <- endemic_species_i |>
# pivot_wider(names_from=iucn,
# values_from=c(n_species,proportion)) |>
# dplyr::select(-method) |>
# rowwise() |>
# mutate(threatened=sum(n_species_EN,n_species_VU,n_species_CR,na.rm=TRUE),
# proportion_threatened=threatened/sum(n_species_EN,n_species_VU,n_species_CR,`n_species_NT/LC`, na.rm=TRUE))
#
#total_paca <- endemic_species_p |>
# pivot_wider(names_from=paca,
# values_from=c(n_species,proportion)) |>
# dplyr::select(-method)
#
#
#total_data <- data.frame(order="total",
# taxa = length(unique(endemic_species$scientificName)),
# sites = nrow(unique(st_coordinates(locations_shp))),
# occurrences = nrow(locations_shp),
# locations = length(unique(locations_grid$CELLCOD)))
#
#total_row <- cbind(total_data, total_paca, total_iucn)
#
#total_summary <- rbind(total_row, order_total)
#write_delim(total_summary, "../results/total_summary.tsv", delim="\t")
```