-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path07_grassland-forest-comparisons.Rmd
400 lines (339 loc) · 14.3 KB
/
07_grassland-forest-comparisons.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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
---
editor_options:
chunk_output_type: console
bibliography: references.bib
---
# Grassland contractions & forest expansions
In the previous script, we inferred that grasslands have contracted dramatically, plantations have increased drastically and forests have expanded as well. In this script, we will compare and contrasts areas where forests and plantations have increased over time and if these areas overlap with grassland habitats (in the past).
## Load necessary libraries
```{r}
library(sf)
library(raster)
library(terra)
library(dplyr)
library(tidyverse)
library(mapview)
library(scico)
library(extrafont)
library(ggstatsplot)
```
## Load processed land cover rasters
```{r}
rast1848 <- terra::rast("results/landcover/1848.tif")
rast2018 <- terra::rast("results/landcover/2018reclassified.tif")
```
## Visualize forests across the two time periods
```{r}
## saving a high resolution visualization
png(filename = "figs/fig_forests_1848_vs_2018.png",
width = 12, height = 7, units = "in", res = 300)
par(mfrow = c(1,2))
plot(rast1848 == "shola_forest",
main = "1848 forest cover",
legend = FALSE)
plot(rast2018 == "shola_forest",
main = "2018 forest cover",
legend=FALSE)
dev.off()
```
![Forest cover differences between 1848 and 2018](figs/fig_forests_1848_vs_2018.png)
## Visualize grassland area across the two time periods
```{r}
## saving a high resolution visualization
png(filename = "figs/fig_grasslands_1848_vs_2018.png",
width = 12, height = 7, units = "in", res = 300)
par(mfrow = c(1,2))
plot(rast1848 == "shola_grassland",
main = "1848 grassland cover",
legend = FALSE)
plot(rast2018 == "shola_grassland",
main = "2018 grassland cover",
legend=FALSE)
dev.off()
```
![Comparing grassland areas between 1848 and 2018](figs/fig_grasslands_1848_vs_2018.png)
## Comparing if forests have increased in locations where grasslands were formerly found?
```{r}
# first, we will polygonize the rasters
vect1848 <- st_as_sf(as.polygons(rast1848))
vect2018 <- st_as_sf(as.polygons(rast2018))
# add a year column to the polygons
vect1848$year <- "1848"
vect2018$year <- "2018"
# overlay shola_forests from 2018 over shola_grasslands from 1848
# first, we will interactively view the visualization
grass1848 <- mapview(vect1848[vect1848$name == "shola_grassland",], col.regions = '#cbb315')
for2018 <- mapview(vect2018[vect2018$name == "shola_forest",], col.regions = '#04a310',
alpha.regions = 0.5)
map_vis <- grass1848+for2018
## save the interactive visualization
html_fl <- tempfile(tmpdir = getwd(), fileext = ".html")
# create standalone .html
mapview::mapshot(map_vis, url = html_fl)
# clearly the above analyses reveals that large number of areas that were formerly grasslands in 1848 are now forests in 2018.
# producing a static visualization
grass1848 <- vect1848[vect1848$name=="shola_grassland",]
for2018 <- vect2018[vect2018$name=="shola_forest",]
fig_for2018_grass1848 <- ggplot() +
geom_sf(data = grass1848, fill = '#cbb315') +
geom_sf(data = for2018, fill = '#04a310') +
facet_wrap(name~year) +
theme_bw() +
theme(text = element_text(size=14, family="Century Gothic"),
axis.title = element_text(
family = "Century Gothic",
size = 14, face = "bold"),
axis.text = element_text(family = "Century Gothic",
size = 14),
axis.text.x = element_text(angle = 90, vjust = 0.5,
hjust = 1),
legend.position = "none")
ggsave(fig_for2018_grass1848,
filename = "figs/fig_forests2018_vs_grasslands1848.png", width = 22, height = 8, device = png(), units = "in", dpi = 600)
dev.off()
```
![Several areas across the landscape that were formerly grasslands in 1848 are now forests in 2018](figs/fig_forests2018_vs_grasslands1848.png)
## Have forests expanded across elevations?
In the above visualizations, we observed that forests have expanded across areas that were formerly grasslands. We ask if these expansions vary as a function of elevation. In other words, are forests expanding upslope?
```{r}
# add elevation raster
# adding a higher resolution DEM from ALOS
alt <- rast("data/elevation/alos-elevation-30m.tif") # this layer is not added to github as a result of its large size and can be downloaded from SRTM (Farr et al. (2007))
# use shapefile to crop the elevation raster
outline <- st_transform(vect1848, 4326)
alt.hills <- terra::crop(alt, outline)
# transform to wgs84 to extract elev
vect1848poly <- st_transform(vect1848,4326)
vect2018poly <- st_transform(vect2018, 4326)
## convert data from multipolygon to polygon
vect1848poly <- st_cast(vect1848poly, "POLYGON")
vect2018poly <- st_cast(vect2018poly, "POLYGON")
# extract values from that raster (note: transformation of coordinate system)
# we will extract minimum, mean and maximum elevation from polygon objects
# for 1848 data
elevMin <- terra::extract(alt.hills, vect1848poly,
fun = min, na.rm = T)
elevMean <- terra::extract(alt.hills, vect1848poly,
fun = mean, na.rm = TRUE)
elevMax <- terra::extract(alt.hills, vect1848poly,
fun = max, na.rm = TRUE)
names(elevMin) <- c("ID","elevMin")
names(elevMean) <- c("ID","elevMean")
names(elevMax) <- c("ID","elevMax")
vect1848poly <- cbind(vect1848poly, elevMin[,-1],
elevMean[,-1], elevMax[,-1])
names(vect1848poly) <- c("name","year","elevMin",
"elevMean","elevMax","geometry")
# for 2018 data
# please note: despite using terra functions, the following lines of code take ~ 3-5 minutes of time
elevMin <- terra::extract(alt.hills, vect2018poly,
fun = min, na.rm = TRUE)
elevMean <- terra::extract(alt.hills, vect2018poly,
fun = mean, na.rm = TRUE)
elevMax <- raster::extract(alt.hills, vect2018poly,
fun = max, na.rm = TRUE)
names(elevMin) <- c("ID","elevMin")
names(elevMean) <- c("ID","elevMean")
names(elevMax) <- c("ID","elevMax")
vect2018poly <- cbind(vect2018poly, elevMin[,-1],
elevMean[,-1], elevMax[,-1])
names(vect2018poly) <- c("name","year","elevMin",
"elevMean","elevMax","geometry")
# visualization
gc()
elev1848 <- vect1848poly %>% st_drop_geometry()
elev2018 <- vect2018poly %>% st_drop_geometry()
data_for_plotting <- bind_rows(elev1848,
elev2018)
write.csv(data_for_plotting, "results/elevation-landCover-overTime.csv",
row.names = F
)
# get only forest data
data_forest <- data_for_plotting %>%
filter(name == "shola_forest")
# has minimum elevation increased over time?
fig_forest_minElev <- ggbetweenstats(
data = data_forest,
x = year,
y = elevMin,
xlab = "Time Period",
ylab = "Minimum elevation in meters",
title = "Minimum elevation across which shola forest patches
occurred in 1848 and 2018",
plot.type = "box",
pairwise.comparisons = T) +
theme(plot.title = element_text(family = "Century Gothic",
size = 18, face = "bold"),
axis.title = element_text(family = "Century Gothic",
size = 16, face = "bold"),
axis.text = element_text(family="Century Gothic",
size = 14),
plot.subtitle = element_text(
family = "Century Gothic",
size = 14,
face = "bold",
color="#1b2838"
))
ggsave(fig_forest_minElev, filename = "figs/fig_sholaForests_minimumElevation.png", width = 12, height = 7, device = png(), units = "in", dpi = 300)
dev.off()
# has mean elevation increased over time?
fig_forest_meanElev <- ggbetweenstats(
data = data_forest,
x = year,
y = elevMean,
xlab = "Time Period",
ylab = "Mean elevation in meters",
title = "Mean elevation across which shola forest patches occurred in 1848 and 2018",
plot.type = "box",
pairwise.comparisons = T) +
theme(plot.title = element_text(family = "Century Gothic",
size = 18, face = "bold"),
axis.title = element_text(family = "Century Gothic",
size = 16, face = "bold"),
axis.text = element_text(family="Century Gothic",
size = 14),
plot.subtitle = element_text(
family = "Century Gothic",
size = 14,
face = "bold",
color="#1b2838"
))
ggsave(fig_forest_meanElev, filename = "figs/fig_sholaForests_meanElevation.png", width = 12, height = 7, device = png(), units = "in", dpi = 300)
dev.off()
## significant differences were observed in mean elevation across time periods, with mean elevation of shola forests being significantly lower in modern time periods compared to historical time periods
fig_forest_maxElev <- ggbetweenstats(
data = data_forest,
x = year,
y = elevMax,
xlab = "Time Period",
ylab = "Max elevation in meters",
title = "Max elevation across which shola forest patches occurred in 1848 and 2018",
plot.type = "box",
pairwise.comparisons = T) +
theme(plot.title = element_text(family = "Century Gothic",
size = 18, face = "bold"),
axis.title = element_text(family = "Century Gothic",
size = 16, face = "bold"),
axis.text = element_text(family="Century Gothic",
size = 14),
plot.subtitle = element_text(
family = "Century Gothic",
size = 14,
face = "bold",
color="#1b2838"
))
ggsave(fig_forest_maxElev, filename = "figs/fig_sholaForests_maxElevation.png", width = 12, height = 7, device = png(), units = "in", dpi = 300)
dev.off()
```
![Mean elevation of shola forest patches in 1848 vs. 2018 suggests a significant decrease in elevation in the modern era](figs/fig_sholaForests_meanElevation.png)
## How do grassland patches vary by elevation across time periods?
```{r}
data_grassland <-data_for_plotting %>% # get only grasslands
filter(name == "shola_grassland")
# has minimum elevation increased over time?
fig_grassland_minElev <- ggbetweenstats(
data = data_grassland,
x = year,
y = elevMin,
xlab = "Time Period",
ylab = "Minimum elevation in meters",
title = "Minimum elevation across which shola grassland patches occurred in 1848 and 2018",
plot.type = "box",
pairwise.comparisons = T) +
theme(plot.title = element_text(family = "Century Gothic",
size = 18, face = "bold"),
axis.title = element_text(family = "Century Gothic",
size = 16, face = "bold"),
axis.text = element_text(family="Century Gothic",
size = 14),
plot.subtitle = element_text(
family = "Century Gothic",
size = 14,
face = "bold",
color="#1b2838"
))
ggsave(fig_grassland_minElev, filename = "figs/fig_sholaGrasslands_minimumElevation.png", width = 12, height = 7, device = png(), units = "in", dpi = 300)
dev.off()
# has mean elevation increased over time?
fig_grassland_meanElev <- ggbetweenstats(
data = data_grassland,
x = year,
y = elevMean,
xlab = "Time Period",
ylab = "Mean elevation in meters",
title = "Mean elevation across which shola grassland patches occurred in 1848 and 2018",
plot.type = "box",
pairwise.comparisons = T) +
theme(plot.title = element_text(family = "Century Gothic",
size = 18, face = "bold"),
axis.title = element_text(family = "Century Gothic",
size = 16, face = "bold"),
axis.text = element_text(family="Century Gothic",
size = 14),
plot.subtitle = element_text(
family = "Century Gothic",
size = 14,
face = "bold",
color="#1b2838"
))
ggsave(fig_grassland_meanElev, filename = "figs/fig_sholaGrasslands_meanElevation.png", width = 12, height = 7, device = png(), units = "in", dpi = 300)
dev.off()
fig_grassland_maxElev <- ggbetweenstats(
data = data_grassland,
x = year,
y = elevMax,
xlab = "Time Period",
ylab = "Max elevation in meters",
title = "Max elevation across which shola grassland patches occurred in 1848 and 2018",
plot.type = "box",
pairwise.comparisons = T) +
theme(plot.title = element_text(family = "Century Gothic",
size = 18, face = "bold"),
axis.title = element_text(family = "Century Gothic",
size = 16, face = "bold"),
axis.text = element_text(family="Century Gothic",
size = 14),
plot.subtitle = element_text(
family = "Century Gothic",
size = 14,
face = "bold",
color="#1b2838"
))
ggsave(fig_grassland_maxElev, filename = "figs/fig_sholaGrasslands_maxElevation.png", width = 12, height = 7, device = png(), units = "in", dpi = 300)
dev.off()
```
![Comparison of mean elevation of grassland patches between 1848 and 2018 revealed a significant decline in elevation in the modern era](figs/fig_sholaGrasslands_meanElevation.png)
## Comparing if plantations have increased in locations where grasslands were formerly found?
```{r}
# overlay plantations from 2018 over shola_grasslands from 1848
# first, we will interactively view the visualization
grass1848 <- mapview(vect1848[vect1848$name == "shola_grassland",], col.regions = '#cbb315')
plant2018 <- mapview(vect2018[vect2018$name == "plantations",], col.regions = '#c17111', alpha.regions = 0.5)
map_vis <- grass1848+plant2018
## save the interactive visualization
html_fl <- tempfile(tmpdir = getwd(), fileext = ".html")
# create standalone .html
mapview::mapshot(map_vis, url = html_fl)
# producing a static visualization
grass1848 <- vect1848[vect1848$name=="shola_grassland",]
plant2018 <- vect2018[vect2018$name=="plantations",]
fig_plant2018_grass1848 <- ggplot() +
geom_sf(data = grass1848, fill = '#cbb315') +
geom_sf(data = plant2018, fill = '#c17111') +
facet_wrap(name~year) +
theme_bw() +
theme(text = element_text(size=14, family="Century Gothic"),
axis.title = element_text(
family = "Century Gothic",
size = 14, face = "bold"),
axis.text = element_text(family = "Century Gothic",
size = 14),
axis.text.x = element_text(angle = 90, vjust = 0.5,
hjust = 1),
legend.position = "none")
ggsave(fig_plant2018_grass1848,
filename = "figs/fig_plantations2018_vs_grasslands1848.png", width = 22, height = 8, device = png(), units = "in", dpi = 600)
dev.off()
```
![Plantations have largely colonized former grassland habitat over time](figs/fig_plantations2018_vs_grasslands1848.png)
Interactive visualizations of forests in 2018 and grasslands in 1848 can be accessed via Zenodo (the files are very large for a GitHub upload).