-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteractive_effect_rcp45_high auc.R
706 lines (658 loc) · 55.9 KB
/
interactive_effect_rcp45_high auc.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
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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
library(rgeos)
library(raster)
library(rgdal)#for reading shp file
library(sp)
library(rJava)
library(readxl)
library(ggplot2)
library(devtools)
library(rgeos)
library(xlsx)
library(dplyr)
library(tmap)
library(dismo)
library(ggpubr)#for assembling figures
library(RColorBrewer) # for making color
latlong <- CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
SR.ORG8287 <- CRS('+proj=cea +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs')
extent.asia.sr <- extent(11000000, 13000000, 900000, 2600000)
vn.raster <- raster('F:/Working/2018/PhD_research/SDM output R/Map/vn raster.tif') #import Vietnam
#import list of species
species.list <- read_excel('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/model performance_block_LQH.xlsx')
species.list <- species.list%>%filter(auc.m1.5 > 0.7)
#generate consensus species richness
sr.current <- lapply(species.list$species, function(sp){
raster(paste0("F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/output_maps/",sp," current.tif"))*vn.raster
})
batsr.current <- overlay(stack(sr.current),fun=sum)
writeRaster(batsr.current, filename = 'F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_current_highauc.tif', format="GTiff", overwrite=T)
#species richness for individual GCMs
#combined model
for(gcm in c('ac', 'bc','ca','cm','cn','cs','gf','gi','ip','mi')){
sr.2050.rcp45.both <- lapply(species.list$species, function(sp){
raster(paste0("F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/output_maps/",sp," 2050 rcp45 both ",gcm,".tif"))*vn.raster
})
batsr.2050.rcp45.both <- overlay(stack(sr.2050.rcp45.both),fun=sum)
writeRaster(batsr.2050.rcp45.both, filename = paste0('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_2050_rcp45_both_',gcm,'_highauc.tif'), format="GTiff", overwrite=T)
print(gcm)
}
#climate model
for(gcm in c('ac', 'bc','ca','cm','cn','cs','gf','gi','ip','mi')){
sr.2050.rcp45.cl <- lapply(species.list$species, function(sp){
raster(paste0("F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/output_maps/",sp," 2050 rcp45 cl ",gcm,".tif"))*vn.raster
})
batsr.2050.rcp45.cl <- overlay(stack(sr.2050.rcp45.cl),fun=sum)
writeRaster(batsr.2050.rcp45.cl, filename = paste0('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_2050_rcp45_cl_',gcm,'_highauc.tif'), format="GTiff", overwrite=T)
print(gcm)
}
#land-cover models
sr.2050.rcp45.lc <- lapply(species.list$species, function(sp){
raster(paste0("F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/output_maps/",sp," 2050 rcp45 lc.tif"))*vn.raster
})
batsr.2050.rcp45.lc <- overlay(stack(sr.2050.rcp45.lc),fun=sum)
writeRaster(batsr.2050.rcp45.lc, filename = 'F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_2050_rcp45_lc_highauc.tif', format="GTiff", overwrite=T)
gcm <- c('ac', 'bc','ca','cm','cn','cs','gf','gi','ip','mi')
#concensus future prediction rcp45
sr.2050.both <- lapply(gcm, function(x){
raster(paste0('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_2050_rcp45_both_',x,'_highauc.tif'))
})
batsr.2050.both.median <- overlay(stack(sr.2050.both), fun=median)
batsr.2050.both.min <- overlay(stack(sr.2050.both), fun= min)
batsr.2050.both.max <- overlay(stack(sr.2050.both), fun= max)
sr.2050.cl <- lapply(gcm, function(x){
raster(paste0('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_2050_rcp45_cl_',x,'_highauc.tif'))
})
batsr.2050.cl.median <- overlay(stack(sr.2050.cl), fun=median)
writeRaster(batsr.2050.both.median, filename = paste0('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_2050_rcp45_both_median_highauc.tif'), format="GTiff", overwrite=T)
writeRaster(batsr.2050.cl.median, filename = paste0('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_2050_rcp45_cl_median_highauc.tif'), format="GTiff", overwrite=T)
#plot maps species richness change
batsr.current <- raster('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_current_highauc.tif')
batsr.2050.both <- raster('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_2050_rcp45_both_median_highauc.tif')
batsr.2050.cl <- raster('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_2050_rcp45_cl_median_highauc.tif')
batsr.2050.lc <- raster('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_2050_rcp45_lc_highauc.tif')
SR.ORG8287 <- CRS('+proj=cea +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs')
vn <- spTransform(getData('GADM', country='VN', level=0), SR.ORG8287)
paracell.islands <- spTransform(readOGR('F:/Working/2018/PhD_research/SDM output R/Map/paracel islands.shp'), SR.ORG8287)
spratly.islands <- spTransform(readOGR('F:/Working/2018/PhD_research/SDM output R/Map/spratly islands.shp'), SR.ORG8287)
batsr.cl.current <- (batsr.2050.cl - batsr.current)/batsr.current*100
batsr.lc.current <- (batsr.2050.lc - batsr.current)/batsr.current*100
batsr.both.current <- (batsr.2050.both - batsr.current)/batsr.current*100
gcm <- c('ac', 'bc','ca','cm','cn','cs','gf','gi','ip','mi')
sr.interaction <- lapply(gcm, function(x){
raster(paste0('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/interaction_types_rcp45_',x,'_highauc.tif'))
})
select.major <- function(x){
modal(x, na.rm=T, freq=F, ties='random')
}
sr.interaction.ensemble <- overlay(stack(sr.interaction), fun=select.major)#select major interaction types across GCMs
plot.srchange.rcp45.both <- tm_shape(batsr.both.current, bbox = c(11380000, 930000,12450000, 2517140)) +
tm_raster('layer',breaks = c(-Inf,-30,-0.0001,0.0001,30,Inf),palette = c('red','orange','grey70','lightblue','blue'),
title = '',labels = c('< -30','-30~0','0','0~30','> 30'))+
tm_shape(vn)+ tm_polygons(border.col = 'dark gray', alpha = 0, lwd = 0.5)+
tm_shape(paracell.islands) + tm_lines(col = 'grey')+
tm_shape(spratly.islands) + tm_lines(col = 'grey')+
tm_layout(legend.outside = F, title = '', title.size = 1, legend.position = c(0, 0.25),
title.position = c(0,1), frame = F, legend.text.size = 0.7, legend.title.size = 1, legend.show = F)
plot.srchange.rcp45.cl <- tm_shape(batsr.cl.current, bbox = c(11380000, 930000,12450000, 2517140)) +
tm_raster('layer',breaks = c(-Inf,-25,-0.0001,0.0001,25,Inf),palette = c('red','orange','grey70','lightblue','blue'),
title = '% SR change')+
tm_shape(vn)+ tm_polygons(border.col = 'gray', alpha = 0, lwd = 0.5)+
tm_shape(paracell.islands) + tm_lines(col = 'grey')+
tm_shape(spratly.islands) + tm_lines(col = 'grey')+
tm_layout(title = '', title.size = 1,title.position = c('left','top'), frame = F,legend.show = F)
plot.srchange.rcp45.lc <- tm_shape(batsr.lc.current, bbox = c(11380000, 930000,12450000, 2517140)) +
tm_raster('layer',breaks = c(-Inf,-25,-0.0001,0.0001,25,Inf),palette = c('red','orange','grey70','lightblue','blue'),
title = '% SR change')+
tm_shape(vn)+ tm_polygons(border.col = 'dark gray', alpha = 0, lwd = 0.5)+
tm_shape(paracell.islands) + tm_lines(col = 'grey')+
tm_shape(spratly.islands) + tm_lines(col = 'grey')+
tm_layout(title = '', title.size = 1, title.position = c('left','top'), frame = F, legend.show = F)
plot.interaction <- tm_shape(sr.interaction.ensemble,bbox = c(11380000, 930000,12450000, 2517140)) +
tm_raster('layer', breaks = c(-0.5,0.5,1.5,2.5,3.5,4.5,5.5),palette = c('white','purple4','purple','grey70','aquamarine','aquamarine4'),
labels = c("","-S", "+A", "AD","-A","+S"),title = '')+
tm_shape(vn)+tm_polygons(col = 'white', alpha = 0, border.col = 'grey')+
tm_shape(paracell.islands) + tm_lines(col = 'grey')+
tm_shape(spratly.islands) + tm_lines(col = 'grey')+
tm_layout(title = '',title.position = c(0,0.95),legend.position = c(0.1,0.5), frame = F,legend.show = F)
figure <- tmap_arrange(plot.srchange.rcp45.both,plot.srchange.rcp45.cl,plot.srchange.rcp45.lc,plot.interaction, nrow = 1)
tmap_save(figure, filename = 'F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/figures/srchange_interaction_rcp45_highauc.tiff',
units = 'cm', width = 30, height = 11, dpi=300)
#
# #plot species richness in current and in 2050 under combined changes
# batsr.current <- raster('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_current_highauc.tif')
# batsr.2050.both.rcp45 <- raster('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_2050_rcp45_both_median_highauc.tif')
# batsr.2050.both.rcp85 <- raster('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_2050_rcp85_both_median_highauc.tif')
# SR.ORG8287 <- CRS('+proj=cea +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs')
# vn <- spTransform(getData('GADM', country='VN', level=0), SR.ORG8287)
# paracell.islands <- spTransform(readOGR('F:/Working/2018/PhD_research/SDM output R/Map/paracel islands.shp'), SR.ORG8287)
# spratly.islands <- spTransform(readOGR('F:/Working/2018/PhD_research/SDM output R/Map/spratly islands.shp'), SR.ORG8287)
#
# plot.current<- tm_shape(batsr.current, bbox = c(11380000, 930000,12450000, 2517140)) +
# tm_raster('layer',breaks = c(0,2,4,6,8,10,15,20,25,30,35,40,50,65), palette = 'Greens', style = 'fixed',
# title = 'Species richness')+
# tm_shape(paracell.islands) + tm_lines(col = 'grey')+
# tm_shape(spratly.islands) + tm_lines(col = 'grey')+
# # tm_shape(pas) + tm_polygons(col = 'green', alpha = 0,border.col = 'darkgreen')+
# tm_shape(vn)+ tm_polygons(border.col = 'dark gray', alpha = 0, lwd = 0.5)+
# tm_layout(legend.outside = F, title = '(a) Current',title.position = c('left','top'),title.size = 1,
# legend.text.size = 0.5, legend.title.size = 1,legend.position = c(0,0.3), frame = F, legend.show = F)
# plot.both.rcp45 <- tm_shape(batsr.2050.both.rcp45, bbox = c(11380000, 930000,12450000, 2517140)) +
# tm_raster('layer',breaks = c(0,2,4,6,8,10,15,20,25,30,35,40,50,65), palette = 'Greens', style = 'fixed',
# title = 'Species richness')+
# tm_shape(paracell.islands) + tm_lines(col = 'grey')+
# tm_shape(spratly.islands) + tm_lines(col = 'grey')+
# # tm_shape(pas) + tm_polygons(col = 'green', alpha = 0,border.col = 'darkgreen')+
# tm_shape(vn)+ tm_polygons(border.col = 'dark gray', alpha = 0, lwd = 0.5)+
# tm_layout(legend.outside = F, title = '(b) Moderate',title.position = c('left','top'),title.size = 1,
# legend.text.size = 0.5, legend.title.size = 1,legend.position = c(0,0.3), frame = F, legend.show = F)
# plot.both.rcp85 <- tm_shape(batsr.2050.both.rcp85, bbox = c(11380000, 930000,12450000, 2517140)) +
# tm_raster('layer',breaks = c(0,2,4,6,8,10,15,20,25,30,35,40,50,65), palette = 'Greens', style = 'fixed',
# title = 'Species richness')+
# tm_shape(paracell.islands) + tm_lines(col = 'grey')+
# tm_shape(spratly.islands) + tm_lines(col = 'grey')+
# # tm_shape(pas) + tm_polygons(col = 'green', alpha = 0,border.col = 'darkgreen')+
# tm_shape(vn)+ tm_polygons(border.col = 'dark gray', alpha = 0, lwd = 0.5)+
# tm_layout(legend.outside = F, title = '(c) Extreme',title.position = c('left','top'),title.size = 1,
# legend.text.size = 0.5, legend.title.size = 1,legend.position = c(0,0.3), frame = F, legend.show = F)
# figure <- tmap_arrange(plot.current, plot.both.rcp45,plot.both.rcp85)
# tmap_save(figure, filename = 'F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/figures/current and 2050_highauc.tiff',
# units = 'cm', width = 24, height = 15, dpi=300)
#
#percent change in species richness bar chart
vn.raster <- raster('F:/Working/2018/PhD_research/SDM output R/Map/vn raster.tif') #import Vietnam
batsr.current <- raster('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_current_highauc.tif')
batsr.lc.rcp45 <- raster('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_2050_rcp45_lc_highauc.tif')
batsr.lc.rcp45.current <- (batsr.lc.rcp45 - batsr.current)/batsr.current*100
pro.lc.rcp45 <- c(cellStats(batsr.lc.rcp45.current>=30,'sum')/cellStats(vn.raster,'sum')*100,
cellStats(batsr.lc.rcp45.current < 30 & batsr.lc.rcp45.current > 0,'sum')/cellStats(vn.raster,'sum')*100,
cellStats(batsr.lc.rcp45.current == 0,'sum')/cellStats(vn.raster,'sum')*100,
cellStats(batsr.lc.rcp45.current < 0 & batsr.lc.rcp45.current > -30,'sum')/cellStats(vn.raster,'sum')*100,
cellStats(batsr.lc.rcp45.current <= -30,'sum')/cellStats(vn.raster,'sum')*100)
#effect of combined change
for(gcm in c('ac', 'bc','ca','cm','cn','cs','gf','gi','ip','mi')){
batsr.both.rcp45 <- raster(paste0('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_2050_rcp45_both_',gcm,'_highauc.tif'))
batsr.both.rcp45.current <- (batsr.both.rcp45 - batsr.current)/batsr.current*100
pro.both.rcp45 <- c(cellStats(batsr.both.rcp45.current>=30,'sum')/cellStats(vn.raster,'sum')*100,
cellStats(batsr.both.rcp45.current < 30 & batsr.both.rcp45.current > 0,'sum')/cellStats(vn.raster,'sum')*100,
cellStats(batsr.both.rcp45.current == 0,'sum')/cellStats(vn.raster,'sum')*100,
cellStats(batsr.both.rcp45.current < 0 & batsr.both.rcp45.current > -30,'sum')/cellStats(vn.raster,'sum')*100,
cellStats(batsr.both.rcp45.current <= -30,'sum')/cellStats(vn.raster,'sum')*100,
cellStats(batsr.both.rcp45.current < 0, 'sum')/cellStats(vn.raster,'sum')*100,
cellStats(batsr.both.rcp45.current > 0, 'sum')/cellStats(vn.raster,'sum')*100)
assign(paste0('pro.both.rcp45.',gcm),pro.both.rcp45)
print(gcm)
}
pro.both.all <- data.frame(pro.both.rcp45.ac,pro.both.rcp45.bc,pro.both.rcp45.ca,pro.both.rcp45.cm,pro.both.rcp45.cn,
pro.both.rcp45.cs,pro.both.rcp45.gf,pro.both.rcp45.gi,pro.both.rcp45.ip,pro.both.rcp45.mi)
#effect of climate change only
for(gcm in c('ac', 'bc','ca','cm','cn','cs','gf','gi','ip','mi')){
batsr.cl.rcp45 <- raster(paste0('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_2050_rcp45_cl_',gcm,'_highauc.tif'))
batsr.cl.rcp45.current <- (batsr.cl.rcp45 - batsr.current)/batsr.current*100
pro.cl.rcp45 <- c(cellStats(batsr.cl.rcp45.current>=30,'sum')/cellStats(vn.raster,'sum')*100,
cellStats(batsr.cl.rcp45.current < 30 & batsr.cl.rcp45.current > 0,'sum')/cellStats(vn.raster,'sum')*100,
cellStats(batsr.cl.rcp45.current == 0,'sum')/cellStats(vn.raster,'sum')*100,
cellStats(batsr.cl.rcp45.current < 0 & batsr.cl.rcp45.current > -30,'sum')/cellStats(vn.raster,'sum')*100,
cellStats(batsr.cl.rcp45.current <= -30,'sum')/cellStats(vn.raster,'sum')*100,
cellStats(batsr.cl.rcp45.current < 0, 'sum')/cellStats(vn.raster,'sum')*100,
cellStats(batsr.cl.rcp45.current > 0, 'sum')/cellStats(vn.raster,'sum')*100)
assign(paste0('pro.cl.rcp45.',gcm),pro.cl.rcp45)
print(gcm)
}
pro.cl.all <- data.frame(pro.cl.rcp45.ac, pro.cl.rcp45.bc, pro.cl.rcp45.ca, pro.cl.rcp45.cm, pro.cl.rcp45.cn,
pro.cl.rcp45.cs, pro.cl.rcp45.gf, pro.cl.rcp45.gi, pro.cl.rcp45.ip, pro.cl.rcp45.mi)
pro.both.median <- apply(pro.both.all,1,median)
pro.both.min <- apply(pro.both.all,1,min)
pro.both.max <- apply(pro.both.all,1,max)
pro.cl.median <- apply(pro.cl.all,1,median)
pro.cl.min <- apply(pro.cl.all,1,min)
pro.cl.max <- apply(pro.cl.all,1,max)
class <- c('>30','0~30','0','-30~0','<-30')
sum.both.sr <- data.frame(class,pro.both.median[1:5],pro.both.min[1:5], pro.both.max[1:5])
sum.cl.sr <- data.frame(class,pro.cl.median[1:5], pro.cl.min[1:5], pro.cl.max[1:5])
sum.lc.sr <- data.frame(class,pro.lc.rcp45)
sum.both.sr$class <- factor(sum.both.sr$class, levels = c('<-30','-30~0','0','0~30','>30'))
sum.cl.sr$class <- factor(sum.cl.sr$class, levels = c('<-30','-30~0','0','0~30','>30'))
sum.lc.sr$class <- factor(sum.lc.sr$class, levels = c('<-30','-30~0','0','0~30','>30'))
write.xlsx(sum.both.sr,'F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/srchange_both_rcp45_highauc.xlsx')
write.xlsx(sum.cl.sr,'F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/srchange_cl_rcp45_highauc.xlsx')
write.xlsx(sum.lc.sr,'F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/srchange_lc_rcp45_highauc.xlsx')
#additive species richness for each GCMs
species.list <- read_excel('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/model performance_block_LQH.xlsx')
species.list <- species.list%>%filter(auc.m1.5 > 0.7)
vn.raster <- raster('F:/Working/2018/PhD_research/SDM output R/Map/vn raster.tif') #import Vietnam
for(gcm in c('ac', 'bc','ca','cm','cn','cs','gf','gi','ip','mi')){
sp.2050.rcp45.add <- lapply(species.list$species, function(sp){
raster(paste0("F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/",sp," 2050 rcp45 additive ",gcm,".tif"))*vn.raster
})
batsr.2050.rcp45 <- overlay(stack(sp.2050.rcp45.add),fun=sum)
writeRaster(batsr.2050.rcp45, filename = paste0('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_2050_rcp45_add_',gcm,'_highauc.tif'), format="GTiff", overwrite=T)
print(gcm)
}
#classify interaction effects
extent.asia.sr <- extent(11000000, 13000000, 900000, 2600000)
vn.raster <- raster('F:/Working/2018/PhD_research/SDM output R/Map/vn raster.tif') #import Vietnam
lc.current <- crop(raster('F:/Working/2018/PhD_research/enviromental_variables/land-cover/MODISLandcover_2010_srorg8287.tif'),extent.asia.sr)*vn.raster
lc.2050.rcp45 <- crop(raster('F:/Working/2018/PhD_research/enviromental_variables/land-cover/MODISLandcover_2050_rcp45_srorg8287.tif'),extent.asia.sr)*vn.raster
area.withlcchange <- lc.2050.rcp45 != lc.current
cellStats(area.withlcchange,'sum')/cellStats(vn.raster,'sum')
batsr.current <- raster('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_current_highauc.tif')
batsr.2050.lc <- raster('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_2050_rcp45_lc_highauc.tif')
for(gcm in c('ac', 'bc','ca','cm','cn','cs','gf','gi','ip','mi')){
batsr.2050.cl <- raster(paste0('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_2050_rcp45_cl_',gcm,'_highauc.tif'))
batsr.2050.both <- raster(paste0('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_2050_rcp45_both_',gcm,'_highauc.tif'))
batsr.2050.add <- raster(paste0('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/batsr_2050_rcp45_add_',gcm,'_highauc.tif'))
sr.interaction <- batsr.current*0
#two negative and negative neutral
sr.interaction[batsr.2050.cl <= batsr.current & batsr.2050.lc <= batsr.current & (batsr.2050.cl + batsr.2050.lc != 2* batsr.current)&
batsr.2050.both < batsr.2050.add] <- 1
sr.interaction[batsr.2050.cl <= batsr.current & batsr.2050.lc <= batsr.current & (batsr.2050.cl + batsr.2050.lc != 2* batsr.current)&
batsr.2050.both == batsr.2050.add] <- 3
sr.interaction[batsr.2050.cl <= batsr.current & batsr.2050.lc <= batsr.current & (batsr.2050.cl + batsr.2050.lc != 2* batsr.current)&
batsr.2050.both > batsr.2050.add & batsr.2050.both <= batsr.current] <- 4
sr.interaction[batsr.2050.cl <= batsr.current & batsr.2050.lc <= batsr.current & (batsr.2050.cl + batsr.2050.lc != 2* batsr.current)&
batsr.2050.both > batsr.current] <- 5
#two positive and positive neutral
sr.interaction[batsr.2050.cl >= batsr.current & batsr.2050.lc >= batsr.current& (batsr.2050.cl + batsr.2050.lc != 2* batsr.current)&
batsr.2050.both < batsr.current] <- 1
sr.interaction[batsr.2050.cl >= batsr.current & batsr.2050.lc >= batsr.current& (batsr.2050.cl + batsr.2050.lc != 2* batsr.current)&
batsr.2050.both >= batsr.current & batsr.2050.both < batsr.2050.add] <- 2
sr.interaction[batsr.2050.cl >= batsr.current & batsr.2050.lc >= batsr.current& (batsr.2050.cl + batsr.2050.lc != 2* batsr.current)&
batsr.2050.both == batsr.2050.add] <- 3
sr.interaction[batsr.2050.cl >= batsr.current & batsr.2050.lc >= batsr.current& (batsr.2050.cl + batsr.2050.lc != 2* batsr.current)&
batsr.2050.both > batsr.2050.add] <- 5
#opposite
sr.interaction[(batsr.2050.cl - batsr.current)*(batsr.2050.lc - batsr.current) < 0 &
batsr.2050.both < min(batsr.2050.cl, batsr.2050.lc)] <- 1
sr.interaction[(batsr.2050.cl - batsr.current)*(batsr.2050.lc - batsr.current) < 0 &
batsr.2050.both >= min(batsr.2050.cl, batsr.2050.lc) & batsr.2050.both < batsr.2050.add] <- 2
sr.interaction[(batsr.2050.cl - batsr.current)*(batsr.2050.lc - batsr.current) < 0 &
batsr.2050.both == batsr.2050.add] <- 3
sr.interaction[(batsr.2050.cl - batsr.current)*(batsr.2050.lc - batsr.current) < 0 &
batsr.2050.both > batsr.2050.add & batsr.2050.both <= max(batsr.2050.cl, batsr.2050.lc)] <- 4
sr.interaction[(batsr.2050.cl - batsr.current)*(batsr.2050.lc - batsr.current) < 0 &
batsr.2050.both > max(batsr.2050.cl, batsr.2050.lc)] <- 5
#double neutral
sr.interaction[batsr.2050.cl == batsr.current & batsr.2050.lc == batsr.current &
batsr.2050.both < batsr.2050.add] <- 1
sr.interaction[batsr.2050.cl == batsr.current & batsr.2050.lc == batsr.current &
batsr.2050.both == batsr.2050.add] <- 3
sr.interaction[batsr.2050.cl == batsr.current & batsr.2050.lc == batsr.current &
batsr.2050.both > batsr.2050.add] <- 5
writeRaster(sr.interaction, filename = paste0('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/interaction_types_rcp45_',gcm,'_highauc.tif'), format="GTiff", overwrite=T)
print(gcm)
}
#compute proportion of interaction types within areas with land-cover change only
extent.asia.sr <- extent(11000000, 13000000, 900000, 2600000)
vn.raster <- raster('F:/Working/2018/PhD_research/SDM output R/Map/vn raster.tif') #import Vietnam
lc.current <- crop(raster('F:/Working/2018/PhD_research/enviromental_variables/land-cover/MODISLandcover_2010_srorg8287.tif'),extent.asia.sr)*vn.raster
lc.2050.rcp45 <- crop(raster('F:/Working/2018/PhD_research/enviromental_variables/land-cover/MODISLandcover_2050_rcp45_srorg8287.tif'),extent.asia.sr)*vn.raster
area.withlcchange <- lc.2050.rcp45 != lc.current
area.withlcchange.area <- cellStats(area.withlcchange, 'sum')
for(gcm in c('ac', 'bc','ca','cm','cn','cs','gf','gi','ip','mi')){
sr.interaction <- raster(paste0('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/interaction_types_rcp45_',gcm,'_highauc.tif'))*area.withlcchange
pro.interaction <- c(cellStats(sr.interaction==1,'sum')/area.withlcchange.area*100,
cellStats(sr.interaction==2,'sum')/area.withlcchange.area*100,
cellStats(sr.interaction==3,'sum')/area.withlcchange.area*100,
cellStats(sr.interaction==4,'sum')/area.withlcchange.area*100,
cellStats(sr.interaction==5,'sum')/area.withlcchange.area*100)
assign(paste0('pro.interaction.',gcm), pro.interaction)
print(gcm)
}
pro.interaction.all <- data.frame(pro.interaction.ac, pro.interaction.bc, pro.interaction.ca, pro.interaction.cm, pro.interaction.cn,
pro.interaction.cs, pro.interaction.gf, pro.interaction.gi, pro.interaction.ip, pro.interaction.mi)
pro.interaction.median <- apply(pro.interaction.all,1,median)
pro.interaction.min <- apply(pro.interaction.all,1,min)
pro.interaction.max <- apply(pro.interaction.all,1,max)
interaction <- c('-S','+A','AD','-A','+S')
sum <- data.frame(interaction, pro.interaction.median)
sum.both.sr <- read_excel('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/srchange_both_rcp45_highauc.xlsx')[2:5]
sum.cl.sr <- read_excel('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/srchange_cl_rcp45_highauc.xlsx')[2:5]
sum.lc.sr <- read_excel('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/srchange_lc_rcp45_highauc.xlsx')[2:3]
names(sum.both.sr) <- c('class','pro.both.median','pro.both.min','pro.both.max')
names(sum.cl.sr) <- c('class','pro.cl.median','pro.cl.min','pro.cl.max')
figure.bar.both <- sum.both.sr%>%ggplot(aes(x=factor(class,levels = c('<-30','-30~0','0','0~30','>30')),y=pro.both.median[1:5],fill=class))+
geom_bar(stat = 'identity')+ theme_classic()+
scale_fill_manual('',values = c('>30'='blue','0~30'='lightblue','0'='grey70','-30~0'='orange','<-30'='red'))+
xlab('')+ylab('')+labs(title = '')+ ylim(0,70)+
geom_errorbar(aes(ymin=pro.both.min[1:5], ymax=pro.both.max[1:5]), width=.2,position=position_dodge(.9))+
theme(legend.position = 'none',
axis.text.y = element_text(size = 12),
axis.text.x = element_text(size = 12, angle = 0, vjust = 0.5),
title = element_text(size = 14))
figure.bar.cl <- sum.cl.sr%>%ggplot(aes(x=factor(class,levels = c('<-30','-30~0','0','0~30','>30')),y=pro.cl.median[1:5],fill=class))+
geom_bar(stat = 'identity')+ theme_classic()+
scale_fill_manual('',values = c('>30'='blue','0~30'='lightblue','0'='grey70','-30~0'='orange','<-30'='red'))+
xlab('')+ylab('')+labs(title = '')+ ylim(0,70)+
geom_errorbar(aes(ymin=pro.cl.min[1:5], ymax=pro.cl.max[1:5]), width=.2,position=position_dodge(.9))+
theme(legend.position = 'none',
axis.text.y = element_text(size = 12),
axis.text.x = element_text(size = 12, angle = 0, vjust = 0.5),
title = element_text(size = 14))
figure.bar.lc <- sum.lc.sr%>%ggplot(aes(x=factor(class,levels = c('<-30','-30~0','0','0~30','>30')),y=pro.lc.rcp45[1:5],fill=class))+
geom_bar(stat = 'identity')+ theme_classic()+
scale_fill_manual('',values = c('>30'='blue','0~30'='lightblue','0'='grey70','-30~0'='orange','<-30'='red'))+
xlab('')+ylab('')+labs(title = '')+ ylim(0,70)+
theme(legend.position = 'none',
axis.text.y = element_text(size = 12),
axis.text.x = element_text(size = 12),
title = element_text(size = 14))
figure.interaction <- ggplot(sum, aes(fill=interaction, y=pro.interaction.median, x=factor(interaction,levels = c('-S','+A','AD','-A','+S')))) +
geom_bar(position="stack", stat="identity")+ ylim(0,70)+ theme_classic()+
scale_fill_manual('',values = c('-S'='purple4','+A'='purple','AD'='grey70', '-A'='aquamarine','+S'='aquamarine4'))+
annotate("text", label = "", size = 4, x = 3, y = 70)+
xlab('')+ylab('')+labs(title = '')+
geom_errorbar(aes(ymin=pro.interaction.min, ymax=pro.interaction.max), width=.2,position=position_dodge(.9))+
theme(text = element_text(size = 14), legend.position = 'none',
axis.text.y = element_text(size = 12),
axis.text.x = element_text(size = 12))
figure <- ggarrange(figure.bar.both,figure.bar.cl,figure.bar.lc,figure.interaction,nrow = 1)
ggsave(figure, filename = 'F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/figures/srchange_interaction_bar_rcp45_highauc.tiff',
units = 'cm', width = 28, height = 8, dpi=300)
#
# #Plot interaction maps
# SR.ORG8287 <- CRS('+proj=cea +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs')
# vn <- spTransform(getData('GADM', country='VN', level=0), SR.ORG8287)
# paracell.islands <- spTransform(readOGR('F:/Working/2018/PhD_research/SDM output R/Map/paracel islands.shp'), SR.ORG8287)
# spratly.islands <- spTransform(readOGR('F:/Working/2018/PhD_research/SDM output R/Map/spratly islands.shp'), SR.ORG8287)
# # pas <- readOGR('F:/Working/2018/PhD_research/SDM output R/Map/vn_pas.shp')
# gcm <- c('ac', 'bc','ca','cm','cn','cs','gf','gi','ip','mi')
# sr.interaction <- lapply(gcm, function(x){
# raster(paste0('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/output_maps/interaction_types_rcp45_',x,'_highauc.tif'))
# })
# select.major <- function(x){
# modal(x, na.rm=T, freq=F, ties='random')
# }
# sr.interaction.ensemble <- overlay(stack(sr.interaction), fun=select.major)#select major interaction types across GCMs
# figure.map <- tm_shape(sr.interaction.ensemble,bbox = c(11070729, 943456.3,12186081, 2517140)) +
# tm_raster('layer', breaks = c(-0.5,0.5,1.5,2.5,3.5,4.5,5.5),palette = c('white','tomato4','tomato','grey70','turquoise2','turquoise4'),
# labels = c("","-S", "+A", "AD","-A","+S"),title = '')+
# tm_shape(vn)+tm_polygons(col = 'white', alpha = 0, border.col = 'grey')+
# tm_shape(paracell.islands) + tm_lines(col = 'grey')+
# tm_shape(spratly.islands) + tm_lines(col = 'grey')+
# # tm_shape(pas) + tm_polygons(col = 'green', alpha = 0,border.col = 'darkgreen')+
# tm_layout(title = '(a)',title.position = c(0,0.95),legend.position = c(0.1,0.5), frame = F)
# tmap_save(figure.map, filename = 'F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/figures/interaction_sr_rcp45_highauc.tiff',width = 8, height = 10, units = 'cm',dpi = 300)
#
#compare impact of climate & lc change on distribution range
species.list <- read_excel('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/model performance_block_LQH.xlsx')
species.list <- species.list%>%filter(auc.m1.5 > 0.7)
area.sum <- read.xlsx("F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/area sum rcp45.xlsx", sheetName = 'Sheet1')
area.sum <- area.sum%>%filter(Scientific_name%in%species.list$species)
area.sum <- area.sum%>%mutate(area.change.rcp45.lc = (area.2050.rcp45.lc - area.current)/area.current*100)
no.species.increase30.rcp45.lc <- nrow(area.sum%>%filter(area.change.rcp45.lc >= 30))/nrow(area.sum)*100
no.species.increase0.rcp45.lc <- nrow(area.sum%>%filter(area.change.rcp45.lc < 30 & area.change.rcp45.lc>0))/nrow(area.sum)*100
no.species.decrease0.rcp45.lc <- nrow(area.sum%>%filter(area.change.rcp45.lc <= 0 &area.change.rcp45.lc > -30))/nrow(area.sum)*100
no.species.decrease30.rcp45.lc <- nrow(area.sum%>%filter(area.change.rcp45.lc <= -30 & area.2050.rcp45.lc > 0))/nrow(area.sum)*100
for(gcm in c('ac', 'bc','ca','cm','cn','cs','gf','gi','ip','mi')){
area.sum[,'area.change.rcp45.both'] <- (area.sum[,paste0('area.2050.rcp45.both.',gcm)] - area.sum[,"area.current"])/area.sum[,"area.current"]*100
area.sum[,'area.change.rcp45.cl'] <- (area.sum[,paste0('area.2050.rcp45.cl.',gcm)] - area.sum[,"area.current"])/area.sum[,"area.current"]*100
area.sum[,'area.2050.rcp45.both'] <- area.sum[,paste0('area.2050.rcp45.both.',gcm)]
area.sum[,'area.2050.rcp45.cl'] <- area.sum[,paste0('area.2050.rcp45.cl.',gcm)]
no.species.increase30.rcp45.both <- nrow(area.sum%>%filter(area.change.rcp45.both>= 30))/nrow(area.sum)*100
no.species.increase0.rcp45.both <- nrow(area.sum%>%filter(area.change.rcp45.both< 30 & area.change.rcp45.both >0))/nrow(area.sum)*100
no.species.decrease0.rcp45.both <- nrow(area.sum%>%filter(area.change.rcp45.both <= 0 & area.change.rcp45.both > -30))/nrow(area.sum)*100
no.species.decrease30.rcp45.both <- nrow(area.sum%>%filter(area.change.rcp45.both <= -30))/nrow(area.sum)*100
no.species.increase30.rcp45.cl <- nrow(area.sum%>%filter(area.change.rcp45.cl>= 30))/nrow(area.sum)*100
no.species.increase0.rcp45.cl <- nrow(area.sum%>%filter(area.change.rcp45.cl< 30 & area.change.rcp45.cl>0))/nrow(area.sum)*100
no.species.decrease0.rcp45.cl <- nrow(area.sum%>%filter(area.change.rcp45.cl <= 0 & area.change.rcp45.cl > -30))/nrow(area.sum)*100
no.species.decrease30.rcp45.cl <- nrow(area.sum%>%filter(area.change.rcp45.cl <= -30 & area.2050.rcp45.cl > 0))/nrow(area.sum)*100
no.species.rcp45 <- c(no.species.increase30.rcp45.both, no.species.increase0.rcp45.both,no.species.decrease0.rcp45.both,no.species.decrease30.rcp45.both,
no.species.increase30.rcp45.cl, no.species.increase0.rcp45.cl,no.species.decrease0.rcp45.cl, no.species.decrease30.rcp45.cl,
no.species.increase30.rcp45.lc, no.species.increase0.rcp45.lc,no.species.decrease0.rcp45.lc,no.species.decrease30.rcp45.lc)
assign(paste0('no.rcp45.',gcm), no.species.rcp45)
print(gcm)
}
pro <- data.frame(rbind(no.rcp45.ac, no.rcp45.bc, no.rcp45.ca, no.rcp45.cm, no.rcp45.cn,
no.rcp45.cs, no.rcp45.gf, no.rcp45.gi, no.rcp45.ip, no.rcp45.mi))
pro <- pro%>%mutate(in.both = X1 + X2, de.both = X3 + X4, in.cl = X5+ X6, de.cl = X7 + X8, in.lc = X9+ X10, de.lc = X11 + X12)
pro.median <- apply(pro,2,median)
pro.min <- apply(pro,2,min)
pro.max <- apply(pro,2,max)
class <- c('>30','0~30',' -30~0','< -30')
sum.both <- data.frame(class, pro.median[1:4], pro.min[1:4], pro.max[1:4])
sum.cl <- data.frame(class, pro.median[5:8], pro.min[5:8], pro.max[5.8])
sum.lc <- data.frame(class, pro.median[9:12])
sum.both$class <- factor(sum.both$class, levels = c('< -30',' -30~0','0~30','>30'))
#interaction effects on distribution range size
for(gcm in c('ac', 'bc','ca','cm','cn','cs','gf','gi','ip','mi')){
area.sum <- read_xlsx('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/area sum rcp45.xlsx')
area.sum <- area.sum%>%filter(Scientific_name%in%species.list$species)
area.sum <- area.sum%>%select(Scientific_name,area.current, paste0('area.2050.rcp45.cl.',gcm), area.2050.rcp45.lc, paste0('area.2050.rcp45.both.', gcm),paste0('area.2050.rcp45.add.', gcm))
colnames(area.sum) <- c('Scientific_name','area.current', 'area.2050.cl', 'area.2050.lc', 'area.2050.both', 'area.2050.add')
area.sum <- area.sum%>%mutate(interaction = 0)
#two negative and negative neutral
area.sum <- area.sum%>%mutate(interaction = replace(interaction, area.2050.cl<= area.current & area.2050.lc<=area.current & area.2050.cl+area.2050.lc!=area.current &
area.2050.both < area.2050.add,1))
area.sum <- area.sum%>%mutate(interaction = replace(interaction, area.2050.cl<= area.current & area.2050.lc<=area.current & area.2050.cl+area.2050.lc!=area.current &
area.2050.both == area.2050.add,3))
area.sum <- area.sum%>%mutate(interaction = replace(interaction, area.2050.cl<= area.current & area.2050.lc<=area.current & area.2050.cl+area.2050.lc!=area.current &
area.2050.both > area.2050.add & area.2050.both <= area.current,4))
area.sum <- area.sum%>%mutate(interaction = replace(interaction,area.2050.cl<= area.current & area.2050.lc<=area.current & area.2050.cl+area.2050.lc!=area.current &
area.2050.both > area.current,5))
#two positive and positive neutral
area.sum <- area.sum%>%mutate(interaction = replace(interaction, area.2050.cl>=area.current & area.2050.lc>=area.current & area.2050.cl+area.2050.lc!=2*area.current&
area.2050.both < area.current,1))
area.sum <- area.sum%>%mutate(interaction = replace(interaction, area.2050.cl>=area.current & area.2050.lc>=area.current & area.2050.cl+area.2050.lc!=2*area.current&
area.2050.both >= area.current& area.2050.both<area.2050.add,2))
area.sum <- area.sum%>%mutate(interaction = replace(interaction, area.2050.cl>=area.current & area.2050.lc>=area.current & area.2050.cl+area.2050.lc!=2*area.current&
area.2050.both == area.2050.add,3))
area.sum <- area.sum%>%mutate(interaction = replace(interaction, area.2050.cl>=area.current & area.2050.lc>=area.current & area.2050.cl+area.2050.lc!=2*area.current&
area.2050.both > area.2050.add,5))
#opposite
area.sum <- area.sum%>%mutate(interaction = replace(interaction, (area.2050.cl -area.current)*(area.2050.lc-area.current)< 0 &
area.2050.both < min(area.2050.cl, area.2050.lc),1))
area.sum <- area.sum%>%mutate(interaction = replace(interaction, (area.2050.cl -area.current)*(area.2050.lc-area.current)< 0 &
area.2050.both >= min(area.2050.cl, area.2050.lc)&area.2050.both < area.2050.add,2))
area.sum <- area.sum%>%mutate(interaction = replace(interaction, (area.2050.cl -area.current)*(area.2050.lc-area.current)< 0 &
area.2050.both ==area.2050.add,3))
area.sum <- area.sum%>%mutate(interaction = replace(interaction, (area.2050.cl -area.current)*(area.2050.lc-area.current)< 0 &
area.2050.both >area.2050.add & area.2050.both<= max(area.2050.cl, area.2050.lc),4))
area.sum <- area.sum%>%mutate(interaction = replace(interaction, (area.2050.cl -area.current)*(area.2050.lc-area.current)< 0 &
area.2050.both > max(area.2050.cl, area.2050.lc),5))
interaction.sp <- c(area.sum$interaction)
assign(paste0('interaction.',gcm), interaction.sp)
# area.sum <- area.sum%>%mutate(paste0('interaction.',gcm) == interaction)
pro.range.interaction <- c(nrow(area.sum%>%filter(interaction == 1))/nrow(area.sum)*100,
nrow(area.sum%>%filter(interaction == 2))/nrow(area.sum)*100,
nrow(area.sum%>%filter(interaction == 3))/nrow(area.sum)*100,
nrow(area.sum%>%filter(interaction == 4))/nrow(area.sum)*100,
nrow(area.sum%>%filter(interaction == 5))/nrow(area.sum)*100)
assign(paste0('pro.range.interaction.', gcm), pro.range.interaction)
print(gcm)
}
pro.range.interaction.all <- data.frame(pro.range.interaction.ac,pro.range.interaction.bc,pro.range.interaction.ca,pro.range.interaction.cm,pro.range.interaction.cn,
pro.range.interaction.cs,pro.range.interaction.gf,pro.range.interaction.gi,pro.range.interaction.ip,pro.range.interaction.mi)
pro.range.interaction.median <- apply(pro.range.interaction.all,1,median)
pro.range.interaction.min <- apply(pro.range.interaction.all,1,min)
pro.range.interaction.max <- apply(pro.range.interaction.all,1,max)
class <- c('-S','+A','AD','-A','+S')
sum.range.interaction <- data.frame(class,pro.range.interaction.median,pro.range.interaction.min, pro.range.interaction.max)
sum.range.interaction$class <- factor(sum.range.interaction$class, levels = c('-S','+A','AD','-A','+S'))
figure.both <- sum.both%>%ggplot(aes(x=factor(class, levels = c('< -30',' -30~0','0~30','>30')),y=pro.median.1.4.,fill=class)) +
geom_bar(stat = 'identity')+
scale_fill_manual('',values = c('>30'='blue','0~30'='lightblue',' -30~0'='orange','< -30'='red'))+
scale_x_discrete(limits=c('< -30',' -30~0','0~30','>30'))+ theme_classic()+ ylim(0,100)+
labs(x='', y='', title = '')+
geom_errorbar(aes(ymin=pro.min[1:4], ymax=pro.max[1:4]), width=.2,position=position_dodge(.9))+
theme(text = element_text(size = 14),axis.text = element_text(size = 14),
plot.title = element_text(hjust = 0),legend.position = 'none')
figure.cl <- sum.cl%>%ggplot(aes(x=factor(class, levels = c('< -30',' -30~0','0~30','>30')),y=pro.median.5.8.,fill=class)) +
geom_bar(stat = 'identity')+
scale_fill_manual('',values = c('>30'='blue','0~30'='lightblue',' -30~0'='orange','< -30'='red'))+
scale_x_discrete(limits=c('< -30',' -30~0','0~30','>30'))+ theme_classic()+ ylim(0,100)+
labs(x='', y='', title = '')+
geom_errorbar(aes(ymin=pro.min[5:8], ymax=pro.max[5:8]), width=.2,position=position_dodge(.9))+
theme(text = element_text(size = 14), axis.text = element_text(size = 14),
plot.title = element_text(hjust = 0),legend.position = 'none')
figure.lc <- sum.lc%>%ggplot(aes(x=factor(class, levels = c('< -30',' -30~0','0~30','>30')),
y=pro.median.9.12.,fill=class)) +
geom_bar(stat = 'identity')+
scale_fill_manual('',values = c('>30'='blue','0~30'='lightblue',' -30~0'='orange','< -30'='red'))+
scale_x_discrete(limits=c('< -30',' -30~0','0~30','>30'))+ theme_classic()+ ylim(0,100)+
labs(x='', y='', title = '')+
theme(text = element_text(size = 14),axis.text = element_text(size = 14),
plot.title = element_text(hjust = 0),legend.position = 'none')
figure.interaction <- sum.range.interaction%>%ggplot(aes(x=factor(class,levels = c('-S','+A','AD','-A','+S')),y=pro.range.interaction.median,fill=class))+
geom_bar(stat = 'identity')+ theme_classic()+
scale_fill_manual('',values = c('-S'='purple4','+A'='purple','AD'='grey70', '-A'='aquamarine','+S'='aquamarine4'))+
xlab('')+ylab('')+labs(title = '')+ ylim(0,100)+
geom_errorbar(aes(ymin=pro.range.interaction.min, ymax=pro.range.interaction.max), width=.2,position=position_dodge(.9))+
theme(text = element_text(size = 14), legend.position = 'none', axis.text = element_text(size = 14))
figure <- ggarrange(figure.both, figure.cl, figure.lc,figure.interaction,nrow = 1)
ggsave(figure, filename = 'F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/figures/rangesize_change_interaction_rcp45_highauc.tiff',
units = 'cm', width = 28, height = 8, dpi = 300)
#test the significant on the change of distribution range size
species.list <- read_excel('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/model performance_block_LQH.xlsx')
species.list <- species.list%>%filter(auc.m1.5 > 0.7)
area.sum <- read.xlsx("F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/area sum rcp45.xlsx", sheetName = 'Sheet1')
area.sum <- area.sum%>%filter(Scientific_name%in%species.list$species)
area.sum <- area.sum%>%mutate(area.2050.both.median = 0)
area.sum <- area.sum%>%mutate(area.2050.cl.median = 0)
for(i in 1:length(area.sum$Scientific_name)){
area.sum[,'area.2050.both.median'][i] <- median(area.sum$area.2050.rcp45.both.ac[i], area.sum$area.2050.rcp45.both.bc[i], area.sum$area.2050.rcp45.both.ca[i],
area.sum$area.2050.rcp45.both.cm[i], area.sum$area.2050.rcp45.both.cn[i], area.sum$area.2050.rcp45.both.cs[i],
area.sum$area.2050.rcp45.both.gf[i], area.sum$area.2050.rcp45.both.gi[i], area.sum$area.2050.rcp45.both.ip[i],
area.sum$area.2050.rcp45.both.mi[i])
area.sum[,'area.2050.cl.median'][i] <- median(area.sum$area.2050.rcp45.cl.ac[i], area.sum$area.2050.rcp45.cl.bc[i], area.sum$area.2050.rcp45.cl.ca[i],
area.sum$area.2050.rcp45.cl.cm[i], area.sum$area.2050.rcp45.cl.cn[i], area.sum$area.2050.rcp45.cl.cs[i],
area.sum$area.2050.rcp45.cl.gf[i], area.sum$area.2050.rcp45.cl.gi[i], area.sum$area.2050.rcp45.cl.ip[i],
area.sum$area.2050.rcp45.cl.mi[i])
}
area.sum <- area.sum%>%mutate('area.change.both.median' = (area.2050.both.median-area.current)/area.current*100)
area.sum <- area.sum%>%mutate('area.change.cl.median' = (area.2050.cl.median-area.current)/area.current*100)
area.sum <- area.sum%>%mutate('area.change.lc' = (area.2050.rcp45.lc-area.current)/area.current*100)
species.list <- read.xlsx("F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/vnbats_habitat_traits.xlsx", sheetName = 'Sheet1')
species.list <- species.list%>%select(Scientific_name,Forest,Shrubland,Grassland,Wetlands,Caves,Artificial,Diet.Plant,Diet.Invertebrate)
area.sum <- merge(area.sum, species.list, by='Scientific_name',bt.x=T)
#check species associate with forest only and others
area.sum$forest.only <- ifelse(area.sum$Artificial==FALSE&area.sum$Shrubland==FALSE&area.sum$Grassland==FALSE,'Forest specialist','Habitat generalist')
figure.both <- area.sum%>%ggplot(aes(x= factor(forest.only, levels = c('Forest specialist', 'Habitat generalist')), y=area.change.both.median))+
stat_summary(geom = "boxplot",
fun.data = function(x) setNames(quantile(x, c(0.0, 0.25, 0.5, 0.75, 1)), c("ymin", "lower", "middle", "upper", "ymax")),
position = "dodge")+ylim(-100,200)+
theme_classic()+
labs(x='',y='Percent change in range size', title = '')+
theme(text = element_text(size = 12), axis.text.x = element_text(size = 12), axis.title.y = element_text(size = 14))+
stat_compare_means(aes(label = ..p.signif..), method = 'wilcox.test',label.x = 1.5, label.y = 180,size = 10)#add Wincolson test
figure.cl <- area.sum%>%ggplot(aes(x= factor(forest.only, levels = c('Forest specialist', 'Habitat generalist')), y=area.change.cl.median))+
stat_summary(geom = "boxplot",
fun.data = function(x) setNames(quantile(x, c(0.0, 0.25, 0.5, 0.75, 1)), c("ymin", "lower", "middle", "upper", "ymax")),
position = "dodge")+ylim(-100,200)+
theme_classic()+
labs(x='',y='', title = '')+
theme(text = element_text(size = 12), axis.text.x = element_text(size = 12))+
stat_compare_means(aes(label = ..p.signif..), method = 'wilcox.test',label.x = 1.5, label.y = 180,size=10)#add Wincolson test
figure.lc <- area.sum%>%ggplot(aes(x= factor(forest.only, levels = c('Forest specialist', 'Habitat generalist')), y=area.change.lc))+
stat_summary(geom = "boxplot",
fun.data = function(x) setNames(quantile(x, c(0.0, 0.25, 0.5, 0.75, 1)), c("ymin", "lower", "middle", "upper", "ymax")),
position = "dodge")+
theme_classic()+
labs(x='',y='', title = '')+
theme(text = element_text(size = 12), axis.text.x = element_text(size = 12))+
stat_compare_means(aes(label = ..p.signif..), method = 'wilcox.test',label.x = 1.5, label.y = 50,size=10)#add Wincolson test
figure <- ggarrange(figure.both, figure.cl, figure.lc, nrow = 1)
ggsave(figure, filename = 'F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/figures/area change_habitat_rcp45_highauc.tiff',
width = 28, height = 12, units = 'cm', dpi = 300)
# #Compare impacts on distribution range size based on dietary
species.list <- read_excel('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/model performance_block_LQH.xlsx')
species.list <- species.list%>%filter(auc.m1.5 > 0.7)
area.sum <- read.xlsx("F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/area sum rcp45.xlsx", sheetName = 'Sheet1')
area.sum <- area.sum%>%filter(Scientific_name%in%species.list$species)
area.sum <- area.sum%>%mutate(area.2050.both.median = 0)
area.sum <- area.sum%>%mutate(area.2050.cl.median = 0)
for(i in 1:length(area.sum$Scientific_name)){
area.sum[,'area.2050.both.median'][i] <- median(area.sum$area.2050.rcp45.both.ac[i], area.sum$area.2050.rcp45.both.bc[i], area.sum$area.2050.rcp45.both.ca[i],
area.sum$area.2050.rcp45.both.cm[i], area.sum$area.2050.rcp45.both.cn[i], area.sum$area.2050.rcp45.both.cs[i],
area.sum$area.2050.rcp45.both.gf[i], area.sum$area.2050.rcp45.both.gi[i], area.sum$area.2050.rcp45.both.ip[i],
area.sum$area.2050.rcp45.both.mi[i])
area.sum[,'area.2050.cl.median'][i] <- median(area.sum$area.2050.rcp45.cl.ac[i], area.sum$area.2050.rcp45.cl.bc[i], area.sum$area.2050.rcp45.cl.ca[i],
area.sum$area.2050.rcp45.cl.cm[i], area.sum$area.2050.rcp45.cl.cn[i], area.sum$area.2050.rcp45.cl.cs[i],
area.sum$area.2050.rcp45.cl.gf[i], area.sum$area.2050.rcp45.cl.gi[i], area.sum$area.2050.rcp45.cl.ip[i],
area.sum$area.2050.rcp45.cl.mi[i])
}
bats.habitat <- read.xlsx("F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/vnbats_habitat_traits.xlsx", sheetName = 'Sheet1')
bats.habitat <- bats.habitat%>%select(Scientific_name,Forest,Shrubland,Grassland,Wetlands,Caves,Artificial,Diet.Plant,Diet.Invertebrate)
area.sum <- merge(area.sum, bats.habitat, by.x='Scientific_name', by.y='Scientific_name', all.x=T)
area.sum <- area.sum%>%dplyr::mutate('area.change.both'= (area.2050.both.median-area.current)/area.current*100)
area.sum <- area.sum%>%dplyr::mutate('area.change.cl'= (area.2050.cl.median-area.current)/area.current*100)
area.sum <- area.sum%>%dplyr::mutate('area.change.lc'= (area.2050.rcp45.lc-area.current)/area.current*100)
#check species associate with dietary
area.sum$dietary <- ifelse(area.sum$familyName=='PTEROPODIDAE','Frugivorous','Insectivourous')
figure.both <- area.sum%>%ggplot(aes(x= factor(dietary, levels = c('Insectivourous', 'Frugivorous')), y=area.change.both))+
stat_summary(geom = "boxplot",
fun.data = function(x) setNames(quantile(x, c(0.0, 0.25, 0.5, 0.75, 1)), c("ymin", "lower", "middle", "upper", "ymax")),
position = "dodge")+ylim(-100,200)+
theme_classic()+
labs(x='',y='Percent change in range size', title = '(a)')+
theme(text = element_text(size = 12), axis.text.x = element_text(size = 12), axis.title.y = element_text(size = 14))+
stat_compare_means(aes(label = ..p.signif..), method = 'wilcox.test',label.x = 1.5, label.y = 190,size = 10)#add Wincolson test
figure.cl <- area.sum%>%ggplot(aes(x= factor(dietary, levels = c('Insectivourous', 'Frugivorous')), y=area.change.cl))+
stat_summary(geom = "boxplot",
fun.data = function(x) setNames(quantile(x, c(0.0, 0.25, 0.5, 0.75, 1)), c("ymin", "lower", "middle", "upper", "ymax")),
position = "dodge")+ylim(-100,200)+
theme_classic()+
labs(x='',y='', title = '(b)')+
theme(text = element_text(size = 12), axis.text.x = element_text(size = 12))+
stat_compare_means(aes(label = ..p.signif..), method = 'wilcox.test',label.x = 1.5, label.y = 190,size=10)#add Wincolson test
figure.lc <- area.sum%>%ggplot(aes(x= factor(dietary, levels = c('Insectivourous', 'Frugivorous')), y=area.change.lc))+
stat_summary(geom = "boxplot",
fun.data = function(x) setNames(quantile(x, c(0.0, 0.25, 0.5, 0.75, 1)), c("ymin", "lower", "middle", "upper", "ymax")),
position = "dodge")+
theme_classic()+
labs(x='',y='', title = '(c)')+
theme(text = element_text(size = 12), axis.text.x = element_text(size = 12))+
stat_compare_means(aes(label = ..p.signif..), method = 'wilcox.test',label.x = 1.5, label.y = 50,size=10)#add Wincolson test
figure <- ggarrange(figure.both, figure.cl, figure.lc, nrow = 1)
ggsave(figure, filename = 'F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/figures/area change_dietary_rcp45_highauc.tiff',
width = 24, height = 10, units = 'cm', dpi = 300)
#test the significant on the change of distribution range size based on roosting
species.list <- read_excel('F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/model performance_block_LQH.xlsx')
species.list <- species.list%>%filter(auc.m1.5 > 0.7)
area.sum <- read.xlsx("F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/area sum rcp45.xlsx", sheetName = 'Sheet1')
area.sum <- area.sum%>%filter(Scientific_name%in%species.list$species)
area.sum <- area.sum%>%mutate(area.2050.both.median = 0)
area.sum <- area.sum%>%mutate(area.2050.cl.median = 0)
for(i in 1:length(area.sum$Scientific_name)){
area.sum[,'area.2050.both.median'][i] <- median(area.sum$area.2050.rcp45.both.ac[i], area.sum$area.2050.rcp45.both.bc[i], area.sum$area.2050.rcp45.both.ca[i],
area.sum$area.2050.rcp45.both.cm[i], area.sum$area.2050.rcp45.both.cn[i], area.sum$area.2050.rcp45.both.cs[i],
area.sum$area.2050.rcp45.both.gf[i], area.sum$area.2050.rcp45.both.gi[i], area.sum$area.2050.rcp45.both.ip[i],
area.sum$area.2050.rcp45.both.mi[i])
area.sum[,'area.2050.cl.median'][i] <- median(area.sum$area.2050.rcp45.cl.ac[i], area.sum$area.2050.rcp45.cl.bc[i], area.sum$area.2050.rcp45.cl.ca[i],
area.sum$area.2050.rcp45.cl.cm[i], area.sum$area.2050.rcp45.cl.cn[i], area.sum$area.2050.rcp45.cl.cs[i],
area.sum$area.2050.rcp45.cl.gf[i], area.sum$area.2050.rcp45.cl.gi[i], area.sum$area.2050.rcp45.cl.ip[i],
area.sum$area.2050.rcp45.cl.mi[i])
}
bats.habitat <- read.xlsx("F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/vnbats_habitat_traits.xlsx", sheetName = 'Sheet1')
bats.habitat <- bats.habitat%>%select(Scientific_name,Forest,Shrubland,Grassland,Wetlands,Caves,Artificial,Diet.Plant,Diet.Invertebrate)
area.sum <- merge(area.sum, bats.habitat, by.x='Scientific_name', by.y='Scientific_name', all.x=T)
area.sum <- area.sum%>%dplyr::mutate('area.change.both'= (area.2050.both.median-area.current)/area.current*100)
area.sum <- area.sum%>%dplyr::mutate('area.change.cl'= (area.2050.cl.median-area.current)/area.current*100)
area.sum <- area.sum%>%dplyr::mutate('area.change.lc'= (area.2050.rcp45.lc-area.current)/area.current*100)
area.sum$roosting <- ifelse(area.sum$Caves=='TRUE','Cave roosting','Others')
figure.both <- area.sum%>%ggplot(aes(x= factor(roosting, levels = c('Cave roosting','Others')), y=area.change.both))+
stat_summary(geom = "boxplot",
fun.data = function(x) setNames(quantile(x, c(0.0, 0.25, 0.5, 0.75, 1)), c("ymin", "lower", "middle", "upper", "ymax")),
position = "dodge")+ylim(-100,200)+
theme_classic()+
labs(x='',y='Percent change in range size', title = '(a)')+
theme(text = element_text(size = 12), axis.text.x = element_text(size = 12), axis.title.y = element_text(size = 14))+
stat_compare_means(aes(label = ..p.signif..), method = 'wilcox.test',label.x = 1.5, label.y = 190,size = 10)#add Wincolson test
figure.cl <- area.sum%>%ggplot(aes(x= factor(roosting, levels = c('Cave roosting','Others')), y=area.change.cl))+
stat_summary(geom = "boxplot",
fun.data = function(x) setNames(quantile(x, c(0.0, 0.25, 0.5, 0.75, 1)), c("ymin", "lower", "middle", "upper", "ymax")),
position = "dodge")+ylim(-100,200)+
theme_classic()+
labs(x='',y='', title = '(b)')+
theme(text = element_text(size = 12), axis.text.x = element_text(size = 12))+
stat_compare_means(aes(label = ..p.signif..), method = 'wilcox.test',label.x = 1.5, label.y = 190,size=10)#add Wincolson test
figure.lc <- area.sum%>%ggplot(aes(x= factor(roosting, levels = c('Cave roosting','Others')), y=area.change.lc))+
stat_summary(geom = "boxplot",
fun.data = function(x) setNames(quantile(x, c(0.0, 0.25, 0.5, 0.75, 1)), c("ymin", "lower", "middle", "upper", "ymax")),
position = "dodge")+
theme_classic()+
labs(x='',y='', title = '(c)')+
theme(text = element_text(size = 12), axis.text.x = element_text(size = 12))+
stat_compare_means(aes(label = ..p.signif..), method = 'wilcox.test',label.x = 1.5, label.y = 55,size=10)#add Wincolson test
figure <- ggarrange(figure.both, figure.cl, figure.lc, nrow = 1)
ggsave(figure, filename = 'F:/Working/2018/PhD_research/SDM output R/2_6_23_BC_revise/interactive_effects/figures/area change_roosting_rcp45_highauc.tiff',
width = 24, height = 10, units = 'cm', dpi = 300)