-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_analysis.Rmd
189 lines (153 loc) · 6.08 KB
/
data_analysis.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
---
title: "TTD studies analysis"
output:
html_document:
toc: true
---
```{r message=FALSE, warning=FALSE, include=FALSE}
# LOAD PACKAGES AND PROCESS THE TABLES
# load all packages
library(readr)
library(dplyr)
library(tidyr)
library(stringr)
library(glue)
library(tibble)
library(knitr)
library(kableExtra)
library(DT)
library(ggplot2)
library(ggmap)
library(leaflet)
library(htmlwidgets)
library(htmltools)
```
This document explores the list of scientific studies included in the 'data' folder
```{r message=FALSE, warning=FALSE, include=FALSE}
# some settings
data_dir <- file.path("data") #directory where all the data is
# load some functions
source(file.path("scripts","functions.R"))
# process all the data through script "data_import.R" and import 3 tibbles:
# T, with all the data on the studies and their sites (not really needed)
# Tdisplay, which is the same as T but with html entries that are good for html display
# Tsites, with all the info on the study sites
source(file.path("scripts","data_import.R"))
# some settings
file_export <- TRUE #to export figures
```
## TABLES
### The studies
The table below lists the considered `r nrow(Tdisplay)` applications, from `r length(unique(Tdisplay$study))` papers published between `r min(Tdisplay$year)` and `r max(Tdisplay$year)`.
```{r echo=FALSE, message=FALSE, warning=FALSE, include=TRUE}
# display as an html datatable
pglngth <- 10 #number of lines to display per page
table_studies <- generate_table_studies(Tdisplay,pglngth)
table_studies
```
### The study sites
The table below shows the main characteristics of the `r T %>% distinct(site, system) %>% count()` distinct sites where the studies were conducted.
```{r echo=FALSE, message=FALSE, warning=FALSE, include=TRUE}
# display as an html datatable
pglngth <- 10 #number of lines to display per page
table_sites <- generate_table_sites(Tsites,pglngth)
table_sites
```
## Map of the study sites
```{r echo=FALSE, message=FALSE, warning=FALSE, fig.width=10, include = TRUE}
# display the html map
map_sites <- generate_map_sites(Tdisplay)
map_sites
# if (file_export){
# saveWidget(map_sites,"Map.html", title="Map TTD sites") #save to a separate html file
# file.rename("Map.html", file.path("html_files","Map.html"))
# }
```
## FIGURES
### TTD approaches
As important theoretical and experimental work consolidated between 2010 and 2015, the number of applications steadily grew in the following years.
```{r echo=FALSE, message=FALSE, warning=FALSE}
yrthresh <- 2006
F1 <- Tdisplay %>%
filter(as.numeric(year) > yrthresh & as.numeric(year) < max(as.numeric(year))) %>%
distinct(study, .keep_all = TRUE) %>%
arrange(year) %>%
ggplot(mapping = aes(x = as.numeric(year),
fill = `TTD approach`
))+
geom_bar()+
labs(#title = "Publications 2006-2021, grouped by TTD approach",
#subtitle = " ",
#caption = "Figure S1",
x = "year",
y = "number") +
theme_classic()
F1
if (file_export){
ggsave(file.path("figures","SI_approaches.pdf")) #save to separate pdf file
}
```
### Sites' size
```{r echo=FALSE, message=FALSE, warning=FALSE, fig.height = 3}
# save info on largest and smallest catchment
area_max <- Tsites %>% filter(system=="Catchment") %>% slice_max(size_km2)
area_min <- Tsites %>% filter(system=="Catchment") %>% slice_min(size_km2)
```
The catchments' areas range between `r area_max$size_km2` km^2 (`r area_max$site`, `r area_max$country`) and `r area_min$size_km2` km^2 (`r area_min$site`, `r area_min$country`). The median catchment size is `r median(as.numeric(Tsites$size_km2),na.rm = TRUE)` km^2.
```{r echo=FALSE, message=FALSE, warning=FALSE, fig.height = 3}
# make the figure with the site sizes
F2 <- Tsites %>%
filter(system=="Catchment") %>%
dplyr::select(site,size_km2) %>%
distinct(site,size_km2) %>%
mutate(tmp = 1) %>%
mutate(randoffset = 0*size_km2+runif(sum(tmp), min = 0, max = 1)) %>%
ggplot(mapping = aes(x = size_km2,
y = "",
label = site))+
geom_boxplot(color = "grey", alpha = .3)+
geom_jitter(color = "red", alpha = .8, height = 0.2, width = 0)+
#geom_point(color = "red", alpha = .8)+
scale_x_continuous(trans='log10',
breaks = c(0.01, 0.1, 1, 10, 100),
label = c(0.01, 0.1, 1, 10, 100))+
#ggrepel::geom_text_repel(size = 3,
# force = 1,
# min.segment.length = 0) +
labs(#title = "Catchments' size",
#subtitle = " ",
#caption = "Figure S2",
x = "Size (km2)",
y = "") +
theme_classic()
F2
if (file_export){
ggsave(file.path("figures","SI_sites_size.pdf"),width = 8, height = 3) #save to separate pdf file
}
```
### Climates of the study sites
The large majority of the studies were carried out in temperate and continental/cold climates ('C' and 'D' main codes, respectively), mainly without a dry season. Tropical and dry climates ('A' and 'B') are almost absent from the list. This reflects the known bias of hydrologic research for experimental sites located at mid-latitudes in Europe and the United States. Climate classification (after [Beck et al., 2018](https://doi.org/10.1038/sdata.2018.214)) is based on one single point and may thus be inaccurate for large catchments.
```{r echo=FALSE, message=FALSE, warning=FALSE}
# show the climates
F3 <- Tdisplay %>%
#filter(system==c("Catchment")) %>%
filter(!is.na(climate_id)) %>%
distinct(site, .keep_all = TRUE) %>%
mutate(climate_code_main = str_sub(climate_code,1,1),
climate_description = str_c(climate_code,climate_description, sep = ": ")) %>%
ggplot(mapping = aes(x = climate_code_main,
fill = climate_description))+
geom_bar(color = "white")+
#coord_flip() +
labs(title = "Sites by Köppen-Geiger climate",
subtitle = "Classification according to Beck et al. (2018)",
#caption = "Figure S3",
x = "class",
y = "count",
fill = "Climate codes") +
theme_classic()
F3
if (file_export){
ggsave(file.path("figures","SI_sites_climate.pdf")) #save to separate pdf file
}
```