-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppS1_March2024.Rmd
1286 lines (973 loc) · 50.8 KB
/
AppS1_March2024.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
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
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "AppS1_17Nov2023"
author: "Madison McCaig"
date: "`r Sys.Date()`"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
- the main manuscript rmd (SBWD Manuscript_March2024.Rmd) needs to be run before this one.
# Fig S2 and S3: Rarefaction Curves
- can be found in the QA/QC files (QAQC_SBWD_16S_2022_07_12 and QAQC_SBWD_ITS_2022_10_26)
# Fig S4: Stream Habitat Correlations (Full Season)
```{r Correlations with Cumulative Defoliation, fig.height=12}
#join defo and waterchem means
cumulative_defo_waterchem <- waterchem_means_wide %>%
inner_join(HAIFLO, by = c("site", "year"))
cumulative_defo_waterchem <- cumulative_defo_waterchem %>%
dplyr::select(-3)
#add the DOM data and flow data and temp data
cumulative_defo_waterchem <- cumulative_defo_waterchem %>%
inner_join(DOM_data_summary, by = c("site", "year"))
cumulative_defo_waterchem <- cumulative_defo_waterchem %>%
inner_join(flow_fullseason_means, by = c("site", "year"))
cumulative_defo_waterchem <- cumulative_defo_waterchem %>%
inner_join(temp_levellogger_summary, by = c("site", "year"))
cumulative_defo_waterchem$site <- as.factor(cumulative_defo_waterchem$site)
cumulative_defo_waterchem$year <- as.factor(cumulative_defo_waterchem$year)
# then restrict to only the ones we predicted to change
cdefo_stream <- cumulative_defo_waterchem %>%
dplyr::select(-3, -4, -5, -6, -7, -8, -9, -12, -13, -14, -15, -17, -18, -19, -21, -23, -24, -31)
#rename everything
cdefo_stream <- cdefo_stream %>%
dplyr::rename(SUVA254 = mean_SUVA, flow.m3s = flow.m3s_mean, temp.C = temp_mean, NO2NO3 = NO2.NO3.mgL)
#now need to run correlations of each waterchem parameter and each year separate
cdefo_stream_2019 <- cdefo_stream %>%
filter(year == "2019") %>%
pivot_longer(cols= -c("site", "cdefo","year"), names_to="parameter", values_to="param_val")
cdefo_stream_2020 <- cdefo_stream %>%
filter(year == "2020") %>%
pivot_longer(cols= -c("site", "cdefo","year"), names_to="parameter", values_to="param_val")
cdefo_stream_2021 <- cdefo_stream %>%
filter(year == "2021") %>%
pivot_longer(cols= -c("site", "cdefo","year"), names_to="parameter", values_to="param_val")
library(ggpubr)
p1 <- cdefo_stream_2019 %>%
ggscatter(x = 'cdefo', y = 'param_val',
add = 'reg.line',
conf.int = TRUE,
cor.coef = TRUE,
cor.method = 'pearson',
xlab = "Cumulative Defoliation Index value (0-15)",
ylab = "Value of stream habitat parameter") +
facet_wrap(~parameter, scales = "free_y") +
theme_bw()
p2 <- cdefo_stream_2020 %>%
ggscatter(x = 'cdefo', y = 'param_val',
add = 'reg.line',
conf.int = TRUE,
cor.coef = TRUE,
cor.method = 'pearson',
xlab = "Cumulative Defoliation Index value (0-15)",
ylab = "Value of stream habitat parameter") +
facet_wrap(~parameter, scales = "free_y") +
theme_bw()
p3 <- cdefo_stream_2021 %>%
ggscatter(x = 'cdefo', y = 'param_val',
add = 'reg.line',
conf.int = TRUE,
cor.coef = TRUE,
cor.method = 'pearson',
xlab = "Cumulative Defoliation Index value (0-15)",
ylab = "Value of stream habitat parameter") +
facet_wrap(~parameter, scales = "free_y") +
theme_bw()
#try everything together and facet by year
cdefo_stream_test <- cdefo_stream %>%
pivot_longer(cols= -c("site", "cdefo","year"), names_to="parameter", values_to="param_val")
cdefo_stream_test %>%
ggscatter(x = 'cdefo', y = 'param_val',
add = 'reg.line',
conf.int = TRUE,
cor.coef = TRUE,
cor.coef.size = 5,
cor.method = 'pearson',
xlab = "Cumulative Defoliation Index value (0-15)",
ylab = "Value of stream habitat parameter") +
facet_grid(parameter~year, scales = "free_y") +
theme_bw(base_size = 18)
```
# Fig S5: Cumulative Precipiation
- data from the New Richmond Est Environment Canada Weather Station https://climate.weather.gc.ca/historical_data/search_historic_data_e.html
- graph showing cumulative precipitation from Nov 1 of the previous year to Oct 31 of that year
- i.e. 2019 is Nov 1 2018 to Oct 31 2019
- this is to account of snow accumulation/spring melt in the streams
```{r}
library(readr)
weather_2018 <- read_csv("~/GitHub/SpruceBudworm_StreamMicrobiome/data/weather_data/en_climate_daily_QC_7055440_2018_P1D.csv")
weather_2018 <- weather_2018 %>%
dplyr::select(5:8, 10,12,14,16,18, 24,26)
colnames(weather_2018)[10] ="Precip_mm"
weather_2019 <- read_csv("~/GitHub/SpruceBudworm_StreamMicrobiome/data/weather_data/en_climate_daily_QC_7055440_2019_P1D.csv")
weather_2019 <- weather_2019 %>%
dplyr::select(5:8, 10,12,14,16,18, 24,26)
colnames(weather_2019)[10] ="Precip_mm"
weather_2020 <- read_csv("~/GitHub/SpruceBudworm_StreamMicrobiome/data/weather_data/en_climate_daily_QC_7055440_2020_P1D.csv")
weather_2020 <- weather_2020 %>%
dplyr::select(5:8, 10,12,14,16,18, 24,26)
colnames(weather_2020)[10] ="Precip_mm"
weather_2021 <- read_csv("~/GitHub/SpruceBudworm_StreamMicrobiome/data/weather_data/en_climate_daily_QC_7055440_2021_P1D.csv")
weather_2021 <- weather_2021 %>%
dplyr::select(5:8, 10,12,14,16,18, 24,26)
colnames(weather_2021)[10] ="Precip_mm"
precip2019 <- rbind(weather_2018[305:365,], weather_2019[1:304,])
precip2019$Precip_mm[is.na(precip2019$Precip_mm)] <- 0
precip2020 <- rbind(weather_2019[305:365,], weather_2020[1:305,])
precip2020$Precip_mm[is.na(precip2020$Precip_mm)] <- 0
precip2021 <- rbind(weather_2020[306:366,], weather_2021[1:304,])
precip2021$Precip_mm[is.na(precip2021$Precip_mm)] <- 0
precip2019$precip_cumulative <- cumsum(precip2019$Precip_mm)
precip2020$precip_cumulative <- cumsum(precip2020$Precip_mm)
precip2021$precip_cumulative <- cumsum(precip2021$Precip_mm)
precip2019$Year <- "2019"
precip2020$Year <- "2020"
precip2021$Year <- "2021"
library(tibble)
precip2019 <- tibble::rownames_to_column(precip2019, "DayNumber")
precip2019$DayNumber <- as.numeric(precip2019$DayNumber)
precip2020 <- tibble::rownames_to_column(precip2020, "DayNumber")
precip2020$DayNumber <- as.numeric(precip2020$DayNumber)
precip2021 <- tibble::rownames_to_column(precip2021, "DayNumber")
precip2021$DayNumber <- as.numeric(precip2021$DayNumber)
precip_final <- rbind(precip2019, precip2020, precip2021)
precip_final$Year <- as.factor(precip_final$Year)
library(scales)
p <- ggplot(precip_final, aes(x = as.Date(DayNumber, "1970-11-01"), y = precip_cumulative, color = Year)) +
geom_line(size=2) +
scale_x_date(date_breaks="months", date_labels="%b") +
labs(x="Month",colour="") +
theme_bw(base_size =16) + ylab("Cumulative Precipitation (mm)")
p + theme(legend.position = "bottom")
```
# Fig S6 Stream Flow Models
```{r flow data}
defo_flow <- flow_fullseason_means %>%
inner_join(HAIFLO, by = c("site", "year"))
#add a column for Region (lower, central, upper)
defo_flow <- defo_flow %>%
mutate(Region = case_when(
startsWith(site, "L") ~ "Lower",
startsWith(site, "C") ~ "Central",
startsWith(site, "U") ~ "Upper"
))
p1 <- defo_flow %>%
ggscatter(x = "cdefo", y = "flow.m3s_mean", color = "year", shape = "Region",
size = 5, add = "reg.line", conf.int = TRUE,
show.legend.text = FALSE) + stat_cor(p.accuracy = 0.01, r.accuracy = 0.01, aes(size =6, label = paste(..r.label.., ..p.label.., sep = "~`,`~")), show.legend = FALSE, size = 6) + scale_color_brewer(palette = "Dark2") + scale_fill_brewer(palette = "Dark2", guide = "none") + facet_wrap(~year) +xlab("Cumulative Defoliation") + ylab(bquote('Stream Flow ('*m^3/s*')')) + theme_bw(base_size = 22) + theme(legend.position = "bottom", panel.grid.major = element_blank(),
panel.grid.minor = element_blank()) + theme(legend.box.background=element_rect(color = "black", size = 1))
mydata <- defo_flow %>%
dplyr::rename(flow = flow.m3s_mean)
#install.packages("readxl")
library(readxl)
watersheds <- read_excel(path="~/GitHub/SpruceBudworm_StreamMicrobiome/data/watersheds.xlsx" ,
sheet="watersheds",
col_names= TRUE)
AnnualHydro <- AnnualHydro %>%
rename(site = Site) %>%
rename(year = Year)
AnnualHydro$year <- as.factor(AnnualHydro$year)
mydata <- mydata %>%
inner_join(AnnualHydro, by = c("site", "year"))
watersheds <- watersheds %>%
rename(site = Site)
mydata <- mydata %>%
inner_join(watersheds, by = c("site"))
watersheds_mortality_statistics <- readRDS("~/GitHub/SpruceBudworm_StreamMicrobiome/data/watersheds_mortality_statistics.RDS")
mortality <- watersheds_mortality_statistics %>%
filter(hydroweighting == "HAiFLO") %>%
dplyr::select(1,3,6) %>%
dplyr::rename(Mortality = value)
mydata <- mydata %>%
left_join(mortality, by = c("site", "year"))
#change NAs to 0
mydata <- mydata %>%
replace_na(list(Mortality = 0))
mydata19 <- mydata %>%
filter(year=="2019")
mydata20 <- mydata %>%
filter(year=="2020")
mydata21 <- mydata %>%
filter(year=="2021")
```
```{r flow HP models, results = 'hide', fig.width=12, fig.height=14}
#elevation, slope, defo, spfir, catchment area
HPmod_land19 <- rdacca.hp(mydata19$flow, mydata19[,c("Mean_Elevation", "cdefo", "Catchment_Area_km2", "SpFir_Percent", "Mean_slope_degrees")], var.part = TRUE)
#plot(HPmod_land19, plot.perc = TRUE)
HPmod_land19
HPmod_land20 <- rdacca.hp(mydata20$flow, mydata20[,c("Mean_Elevation", "cdefo", "Catchment_Area_km2", "SpFir_Percent", "Mean_slope_degrees")], var.part = TRUE)
#plot(HPmod_land20, plot.perc = TRUE)
HPmod_land20
HPmod_land21<- rdacca.hp(mydata21$flow, mydata21[,c("Mean_Elevation", "cdefo", "Catchment_Area_km2", "SpFir_Percent", "Mean_slope_degrees")], var.part = TRUE)
#plot(HPmod_land21, plot.perc = TRUE)
HPmod_land21
#plot total and then put unique and shared into a table
HP_vals_c21 <- (as.data.frame(HPmod_land21[[4]]))
HP_vals_c21$parameter <- row.names(HP_vals_c21)
HP_vals_c21 <- HP_vals_c21 %>%
dplyr::select(4,5)
HP_vals_c21_long <- HP_vals_c21
# %>% pivot_longer(
# cols = 1:2,
# names_to = c("condition"),
# values_to = "value")
HP_vals_c21_long$year <- "2021"
#2019
HP_vals_c19 <- (as.data.frame(HPmod_land19[[4]]))
HP_vals_c19$parameter <- row.names(HP_vals_c19)
HP_vals_c19 <- HP_vals_c19 %>%
dplyr::select(4,5)
HP_vals_c19_long <- HP_vals_c19
#%>%
#pivot_longer(
# cols = 1:2,
# names_to = c("condition"),
# values_to = "value")
HP_vals_c19_long$year <- "2019"
#2020
HP_vals_c20 <- (as.data.frame(HPmod_land20[[4]]))
HP_vals_c20$parameter <- row.names(HP_vals_c20)
HP_vals_c20 <- HP_vals_c20 %>%
dplyr::select(4,5)
HP_vals_c20_long <- HP_vals_c20
#%>%
# pivot_longer(
# cols = 1:2,
# names_to = c("condition"),
# values_to = "value")
HP_vals_c20_long$year <- "2020"
#join years together
HP_vals_long <- rbind(HP_vals_c19_long, HP_vals_c20_long, HP_vals_c21_long)
#HP_vals_long <- HP_vals_long %>%
#dplyr::rename(Condition = condition)
HP_vals_long <- HP_vals_long %>%
dplyr::rename(Indiv.perc = "I.perc(%)")
#HP_vals_long$Condition <- as.factor(HP_vals_long$Condition)
#need to change order of the factors
HP_vals_long$parameter <- HP_vals_long$parameter %>%
factor(levels = c("Mean_Elevation", "cdefo", "SpFir_Percent", "Mean_slope_degrees", "Catchment_Area_km2"))
p2 <- ggplot(HP_vals_long, aes(y=Indiv.perc, x=parameter, fill = parameter)) +
geom_bar(stat="identity") + facet_wrap(~year) +
scale_x_discrete(labels=c("Elevation", "Cumulative Defoliation","% Spruce-Fir", "Slope", "Catchment Area")) +
theme_bw(base_size = 22) +
xlab("Landscape Metric") + ylab(bquote('% Individual Contribution to '*R^2*'')) +
#scale_fill_discrete(labels=c('Total Variance', 'Unique Variance')) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), panel.border = element_rect(color="black", fill=NA), axis.text.x = element_text(angle = 45, hjust = 1, vjust=1), legend.position = "none") + scale_fill_brewer(palette="Dark2")
#1000 by 1400
library(ggpubr)
ggarrange(p1, p2,
widths = 7,
labels = c("a", "b"),
font.label=list(size = 22, color = "black", face = "bold"),
ncol = 1, nrow = 2)
```
# Fig S7 Stream Temperature (Yearly Models)
## Temperature - Incubation period
```{r temp incubation, results = 'hide', fig.width=12, fig.height=14}
lp_temps <- readRDS("GitHub/SpruceBudworm_StreamMicrobiome/data/lp_temps.RDS")
library(timetk)
lp_temps$temp.C <- as.numeric(lp_temps$temp.C)
dailytemp <- lp_temps %>%
group_by(site, year) %>%
summarise_by_time(
.date_var = date.time,
.by = "day",
value = mean(temp.C)
)
dailytemp <- dailytemp %>%
# drop_na(value) %>% #if there are NAs do this step
rename(mean_daily_temp = value)
dailytemp$year <- as.factor(dailytemp$year)
dailytemp$site <- as.factor(dailytemp$site)
dailytemp$date.time <- format(dailytemp$date.time, format = "%m-%d")
dailytemp2 <- subset(dailytemp, !(date.time %in% c("09-26", "09-27", "09-28", "09-29", "09-30", "10-01", "10-02", "10-03", "10-04", "10-05", "10-06","10-07", "10-08", "10-09", "10-10", "10-11", "10-12", "10-13","10-14", "10-15", "10-16", "10-17", "10-18", "10-19", "10-20", "10-21", "10-22", "10-23", "10-24", "10-25", "10-26", "10-27", "10-28", "10-29","10-30","10-31", "11-01", "11-02", "11-03","11-04","11-05")))
dailytemp3 <- dailytemp2[-c(336:371), ]
dailytemp4 <- subset(dailytemp3, !(mean_daily_temp > 15))
#remove remaining outliers that are from before/after installation (visually determined from plotting dailytemp4)
dailytemp5 <- dailytemp4[-c(148, 190, 229, 261, 331, 332, 333, 334, 441, 556, 557, 628, 670, 744, 784, 855, 856, 968, 1039, 1079, 1153, 1235, 1347), ]
dailytemp5 %>%
ggplot(aes(x=date.time, y=mean_daily_temp, color=year)) + geom_point() + facet_wrap(~site, nrow = 6, dir = "v", scales = "free_y") + scale_x_discrete(breaks=c("08-11","08-30","09-25"))
#average temperature per site per year
dailytemp_summary <- dailytemp5 %>%
group_by(site, year) %>%
summarize(mean=mean(mean_daily_temp))
#does cdefo correlate to temp?
defo_temp <- dailytemp_summary %>%
inner_join(HAIFLO, by = c("site", "year"))
#add a column for Region (lower, central, upper)
defo_temp <- defo_temp %>%
mutate(Region = case_when(
startsWith(site, "L") ~ "Lower",
startsWith(site, "C") ~ "Central",
startsWith(site, "U") ~ "Upper"
))
defo_temp <- defo_temp %>%
dplyr::rename(temp_mean = mean)
#plot by year
library(ragg)
p1 <- defo_temp %>%
ggscatter(x = "cdefo", y = "temp_mean", color = "year", shape = "Region",
size = 5, add = "reg.line", conf.int = TRUE,
show.legend.text = FALSE, show.legend = FALSE) + stat_cor(p.accuracy = 0.01, r.accuracy = 0.01, aes(size =5, label = paste(..r.label.., ..p.label.., sep = "~`,`~")), show.legend = FALSE, size = 5) + scale_color_brewer(palette = "Dark2") + scale_fill_brewer(palette = "Dark2", guide = "none") + facet_wrap(~year) +xlab("Cumulative Defoliation") + ylab(bquote(paste("Stream Temperature", " (", "\u00B0", "C", ")", sep = ""))) + theme_bw(base_size = 16) + theme(legend.position = "bottom", panel.grid.major = element_blank(),panel.grid.minor = element_blank(), #legend.margin=margin(-3, 0, 0, 0),
legend.spacing.y = unit(0.05, 'cm'), legend.key.size = unit(0.2, 'cm')) +
#legend.box.background = element_rect(color="black", size=0.5))
#legend.box.margin = margin(116, 6, 6, 6))
scale_shape_discrete(breaks=c('Lower', 'Central', 'Upper'), guide = guide_legend(byrow = TRUE)) + labs(shape = "Watershed Cluster")
mydata <- defo_temp
AnnualHydro <- readRDS("~/GitHub/SpruceBudworm_StreamMicrobiome/data/AnnualDischarge_Aug2022.RDS")
#install.packages("readxl")
library(readxl)
watersheds <- read_excel(path="~/GitHub/SpruceBudworm_StreamMicrobiome/watersheds.xlsx" ,
sheet="watersheds",
col_names= TRUE)
AnnualHydro <- AnnualHydro %>%
rename(site = Site) %>%
rename(year = Year)
AnnualHydro$year <- as.factor(AnnualHydro$year)
mydata <- mydata %>%
inner_join(AnnualHydro, by = c("site", "year"))
watersheds <- watersheds %>%
rename(site = Site)
mydata <- mydata %>%
inner_join(watersheds, by = c("site"))
watersheds_mortality_statistics <- readRDS("~/GitHub/SpruceBudworm_StreamMicrobiome/data/watersheds_mortality_statistics.RDS")
mortality <- watersheds_mortality_statistics %>%
filter(hydroweighting == "HAiFLO") %>%
dplyr::select(1,3,6) %>%
dplyr::rename(Mortality = value)
mydata <- mydata %>%
left_join(mortality, by = c("site", "year"))
#change NAs to 0
mydata <- mydata %>%
replace_na(list(Mortality = 0))
mydata19 <- mydata %>%
filter(year=="2019")
mydata20 <- mydata %>%
filter(year=="2020")
mydata21 <- mydata %>%
filter(year=="2021")
#elevation, defo, spfir, aspect, wet cover
HPmod_land19 <- rdacca.hp(mydata19$temp_mean, mydata19[,c("Mean_Elevation", "cdefo", "SpFir_Percent", "Mean_aspect_degrees", "Wetland_PercentCover")], var.part = TRUE)
#plot(HPmod_land19, plot.perc = TRUE)
HPmod_land19
HPmod_land20 <- rdacca.hp(mydata20$temp_mean, mydata20[,c("Mean_Elevation", "cdefo", "SpFir_Percent", "Mean_aspect_degrees", "Wetland_PercentCover")], var.part = TRUE)
#plot(HPmod_land20, plot.perc = TRUE)
HPmod_land20
HPmod_land21<- rdacca.hp(mydata21$temp_mean, mydata21[,c("Mean_Elevation", "cdefo", "SpFir_Percent", "Mean_aspect_degrees", "Wetland_PercentCover")], var.part = TRUE)
#plot(HPmod_land21, plot.perc = TRUE)
HPmod_land21
#plot total and then put unique and shared into a table
HP_vals_c21 <- (as.data.frame(HPmod_land21[[4]]))
HP_vals_c21$parameter <- row.names(HP_vals_c21)
HP_vals_c21 <- HP_vals_c21 %>%
dplyr::select(4,5)
HP_vals_c21_long <- HP_vals_c21
# %>% pivot_longer(
# cols = 1:2,
# names_to = c("condition"),
# values_to = "value")
HP_vals_c21_long$year <- "2021"
#2019
HP_vals_c19 <- (as.data.frame(HPmod_land19[[4]]))
HP_vals_c19$parameter <- row.names(HP_vals_c19)
HP_vals_c19 <- HP_vals_c19 %>%
dplyr::select(4,5)
HP_vals_c19_long <- HP_vals_c19
#%>%
#pivot_longer(
# cols = 1:2,
# names_to = c("condition"),
# values_to = "value")
HP_vals_c19_long$year <- "2019"
#2020
HP_vals_c20 <- (as.data.frame(HPmod_land20[[4]]))
HP_vals_c20$parameter <- row.names(HP_vals_c20)
HP_vals_c20 <- HP_vals_c20 %>%
dplyr::select(4,5)
HP_vals_c20_long <- HP_vals_c20
#%>%
# pivot_longer(
# cols = 1:2,
# names_to = c("condition"),
# values_to = "value")
HP_vals_c20_long$year <- "2020"
#join years together
HP_vals_long <- rbind(HP_vals_c19_long, HP_vals_c20_long, HP_vals_c21_long)
#HP_vals_long <- HP_vals_long %>%
#dplyr::rename(Condition = condition)
HP_vals_long <- HP_vals_long %>%
dplyr::rename(Indiv.perc = "I.perc(%)")
#HP_vals_long$Condition <- as.factor(HP_vals_long$Condition)
#need to change order of the factors
HP_vals_long$parameter <- HP_vals_long$parameter %>%
factor(levels = c("SpFir_Percent","cdefo", "Mean_Elevation","Wetland_PercentCover","Mean_aspect_degrees"))
p2 <- ggplot(HP_vals_long, aes(y=Indiv.perc, x=parameter, fill = parameter)) +
geom_bar(stat="identity") + facet_wrap(~year) +
scale_x_discrete(labels=c("% Spruce-Fir", "Cumulative Defoliation", "Elevation", "% Wetland", "Aspect")) +
theme_bw(base_size = 16) +
xlab("Landscape Metric") + ylab(expression(atop("% Individual Contribution",paste("to Temperature R " ^2)))) +
#scale_fill_discrete(labels=c('Total Variance', 'Unique Variance')) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), panel.border = element_rect(color="black", fill=NA), axis.text.x = element_text(angle = 65, hjust = 1, vjust=1), legend.position = "none") + scale_fill_brewer(palette="Dark2")
ann_text <- data.frame(parameter = "SpFir_Percent",Indiv.perc = 40 ,lab = c("R^2==0.67","R^2==0.54", "R^2==0.77"),
year= c("2019","2020","2021"))
p3 <- p2 + geom_text(data = ann_text, size = 5, nudge_x = 2, aes(x = parameter, y = Indiv.perc, label = lab), parse = TRUE)
library(ggpubr)
fig7 <- ggarrange(p1, p3,
labels = c("a", "b"),
font.label=list(size = 22, color = "black", face = "bold"),
ncol = 1, nrow = 2)
ggsave(
filename = "fig7_temp.png",
plot = fig7,
path = NULL,
width = 8.5,
height = 12,
units = "cm",
dpi = 300,
scaling = 0.38
)
```
# Fig S8 Stream Temperature (Regional Models)
```{r}
#plot by region only
p3 <- defo_temp %>%
ggscatter(x = "cdefo", y = "temp_mean", color = "year",
size = 5, conf.int = FALSE,
show.legend.text = FALSE) + stat_cor(p.accuracy = 0.01, r.accuracy = 0.01, aes(size =6, label = paste(..r.label.., ..p.label.., sep = "~`,`~")), show.legend = FALSE, size = 6) + scale_color_brewer(palette = "Dark2") + scale_fill_brewer(palette = "Dark2", guide = "none") + facet_grid(~Region) +xlab("Cumulative Defoliation") + ylab(bquote(paste("Stream Temperature", " (", "\u00B0", "C", ")", sep = ""))) + theme_bw(base_size = 22) + theme(legend.position = "bottom", panel.grid.major = element_blank(),
panel.grid.minor = element_blank()) + theme(legend.box.background=element_rect(color = "black", size = 1))
p4 <- p3 + geom_smooth(method = "lm", color = "black")
ggsave(
filename = "fig8_temp.png",
plot = p4,
path = NULL,
width = 10,
height = 8,
units = "cm",
dpi = 300,
scaling = 0.38
)
```
# Fig S9 Alpha Diversity
```{r alpha diversity, fig.width=12, fig.height=12}
#start with 16s data
#use lp_16s that was pulled in in the main manuscript file
#need data in the proper format with sites as rows and species as columns and one file per year
#removing the columns for the other years
lp_16s_2019 <- dplyr::select(lp_16s, -ends_with(c("2020", "2021")))
lp_16s_2020 <- dplyr::select(lp_16s, -ends_with(c("2019", "2021")))
lp_16s_2021 <- dplyr::select(lp_16s, -ends_with(c("2020", "2019")))
#create 2019 matrix
lp_16s_2019_matrix <- dplyr::select(lp_16s_2019, -c(2:21))
#remember the names
n <- lp_16s_2019_matrix$ESV
# transpose all but the first column (name)
lp_16s_2019_matrix_t <- as.data.frame(t(lp_16s_2019_matrix[,-1]))
colnames(lp_16s_2019_matrix_t) <- n
#rename to shorten it
lp_16s_2019 <- lp_16s_2019_matrix_t
#save the sites into their own rds so you have them for later
sites_16s_2019 <- lp_16s_2019
sites_16s_2019 <- tibble::rownames_to_column(sites_16s_2019, "sites")
sites_16s_2019 <- dplyr::select(sites_16s_2019, 1)
#repeat for 2020
lp_16s_2020_matrix <- dplyr::select(lp_16s_2020, -c(2:21))
# first remember the names
n <- lp_16s_2020_matrix$ESV
# transpose all but the first column (name)
lp_16s_2020_matrix_t <- as.data.frame(t(lp_16s_2020_matrix[,-1]))
colnames(lp_16s_2020_matrix_t) <- n
lp_16s_2020 <- lp_16s_2020_matrix_t
sites_16s_2020 <- lp_16s_2020
sites_16s_2020 <- tibble::rownames_to_column(sites_16s_2020, "sites")
sites_16s_2020 <- dplyr::select(sites_16s_2020, 1)
#repeat for 2021
lp_16s_2021_matrix <- dplyr::select(lp_16s_2021, -c(2:21))
# first remember the names
n <- lp_16s_2021_matrix$ESV
# transpose all but the first column (name)
lp_16s_2021_matrix_t <- as.data.frame(t(lp_16s_2021_matrix[,-1]))
colnames(lp_16s_2021_matrix_t) <- n
lp_16s_2021 <- lp_16s_2021_matrix_t
sites_16s_2021 <- lp_16s_2021
sites_16s_2021 <- tibble::rownames_to_column(sites_16s_2021, "sites")
sites_16s_2021 <- dplyr::select(sites_16s_2021, 1)
#after subsetting, need to remove all ESVs with 0 (i.e. if not present in any sites in that year)
lp_16s_2019 <- lp_16s_2019[, colSums(lp_16s_2019 != 0) > 0]
colSums(lp_16s_2019) %>% min()
lp_16s_2020 <- lp_16s_2020[, colSums(lp_16s_2020 != 0) > 0]
colSums(lp_16s_2020) %>% min()
lp_16s_2021 <- lp_16s_2021[, colSums(lp_16s_2021 != 0) > 0]
colSums(lp_16s_2021) %>% min()
##Create a data frame with the alpha diversity metrics of interest
#2019 16S
diversity_16s_2019 <- data.frame(sites_16s_2019, Shannon = diversity(lp_16s_2019, index="shannon"),
InverseSimpson = diversity(lp_16s_2019, index="invsimpson"),
richness = specnumber(lp_16s_2019)) %>%
mutate(Evenness = InverseSimpson/richness) %>% pivot_longer(cols=c("Shannon", "InverseSimpson", "richness", "Evenness"), names_to = "diversity_metric", values_to = "diversity")
diversity_16s_2019 <- separate(diversity_16s_2019, col=sites, into=c('site', 'rep', 'year'), sep='_')
#reorder low to high defoliation
diversity_16s_2019$site <- diversity_16s_2019$site %>%
factor(levels = c("L09", "L10", "L12", "L08", "L11", "U03", "C07", "C06", "U01", "C04", "C05", "U02"))
## 2020 16S
diversity_16s_2020 <- data.frame(sites_16s_2020, Shannon = diversity(lp_16s_2020, index="shannon"),
InverseSimpson = diversity(lp_16s_2020, index="invsimpson"),
richness = specnumber(lp_16s_2020)) %>%
mutate(Evenness = InverseSimpson/richness) %>% pivot_longer(cols=c("Shannon", "InverseSimpson", "richness", "Evenness"), names_to = "diversity_metric", values_to = "diversity")
diversity_16s_2020 <- separate(diversity_16s_2020, col=sites, into=c('site', 'rep', 'year'), sep='_')
diversity_16s_2020$site <- diversity_16s_2020$site %>%
factor(levels = c("L10", "L08", "L09", "L12", "L11", "C06", "C07", "C05", "U03", "C04", "U01", "U02"))
## 2021 16S
diversity_16s_2021 <- data.frame(sites_16s_2021, Shannon = diversity(lp_16s_2021, index="shannon"),
InverseSimpson = diversity(lp_16s_2021, index="invsimpson"),
richness = specnumber(lp_16s_2021)) %>%
mutate(Evenness = InverseSimpson/richness) %>% pivot_longer(cols=c("Shannon", "InverseSimpson", "richness", "Evenness"), names_to = "diversity_metric", values_to = "diversity")
diversity_16s_2021 <- separate(diversity_16s_2021, col=sites, into=c('site', 'rep', 'year'), sep='_')
diversity_16s_2021$site <- diversity_16s_2021$site %>%
factor(levels = c("U02", "L10", "L08", "L12", "U03", "L09", "C06", "L11", "C04", "C05", "C07", "U01"))
#combine all years together so it's easier for plotting
diversity_16s <- rbind(diversity_16s_2019, diversity_16s_2020, diversity_16s_2021)
##correlation between mean richness and mean cumulative defoliation
diversity_16s_wide <- diversity_16s %>%
pivot_wider(names_from = diversity_metric, values_from = diversity)
diversity_16s_summary <- diversity_16s_wide %>%
group_by(site, year) %>%
summarize(Shannon_mean=mean(Shannon), InverseSimpson_mean =mean(InverseSimpson), richness_mean=mean(richness), Evenness_mean=mean(Evenness))
#need mean richness per site
richness_16s <- diversity_16s %>%
filter(diversity_metric == "richness") %>%
dplyr::select(-4 )%>%
dplyr::rename(richness = diversity)
mean_richness_16s <- richness_16s %>%
group_by(site, year) %>%
summarise(mean_richness = mean(richness))
richness_16S_cumul_HAiFLO <- mean_richness_16s %>%
inner_join(HAIFLO, by = c("site", "year"))
#shannon and cumulative
diversity_16S_cdefo <- diversity_16s_summary %>%
inner_join(HAIFLO, by = c("site", "year"))
#all the correlations in one plot
diversity_16S_cdefo <- diversity_16S_cdefo %>%
dplyr::rename("Shannon Diversity" = Shannon_mean, "Richness" = richness_mean, "Evenness" = Evenness_mean)
diversity_defo_long <- diversity_16S_cdefo %>%
pivot_longer(cols = 3:6,
names_to = c("diversity_metric"),
values_to = "diversity")
p5 <- diversity_defo_long %>%
filter(diversity_metric != "InverseSimpson_mean") %>%
# filter(diversity_metric %in% c("Richness", "Shannon Diversity")) %>%
ggscatter(x = "cdefo", y = "diversity", color = "year", size = 5,
#add = "reg.line", conf.int = TRUE,
cor.coef = FALSE, cor.coef.size = 6, cor.method = "pearson",
xlab = "Cumulative Defoliation", ylab = "Bacteria Diversity") + stat_cor(p.accuracy = 0.01, r.accuracy = 0.01, aes(size = 6, label = paste(..r.label.., ..p.label.., sep = "~`,`~")), show.legend = FALSE, size = 6) + scale_color_brewer(palette = "Dark2", guide = "none") + scale_fill_brewer(palette = "Dark2", guide = "none") +
facet_grid(diversity_metric~year, scales = "free_y") + theme_bw(base_size = 20) + scale_x_continuous(labels = seq(0,15,5), breaks = seq(0,15,5))+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),panel.background = element_blank(), axis.line = element_line(colour = "black"))
#ITS
#need mean richness per site
#use the lp_its file pulled in in main manuscript rmd
#need data in the proper format with sites as rows and species as columns and one file per year
#removing the columns for the other years
lp_its_2019 <- dplyr::select(lp_its, -ends_with(c("2020", "2021")))
lp_its_2020 <- dplyr::select(lp_its, -ends_with(c("2019", "2021")))
lp_its_2021 <- dplyr::select(lp_its, -ends_with(c("2020", "2019")))
#create 2019 matrix
lp_its_2019_matrix <- dplyr::select(lp_its_2019, -c(2:26))
#remember the names
n <- lp_its_2019_matrix$ESV
# transpose all but the first column (name)
lp_its_2019_matrix_t <- as.data.frame(t(lp_its_2019_matrix[,-1]))
colnames(lp_its_2019_matrix_t) <- n
#rename to shorten it
lp_its_2019 <- lp_its_2019_matrix_t
#save the sites into their own rds so you have them for later
sites_its_2019 <- lp_its_2019
sites_its_2019 <- tibble::rownames_to_column(sites_its_2019, "sites")
sites_its_2019 <- dplyr::select(sites_its_2019, 1)
#repeat for 2020
lp_its_2020_matrix <- dplyr::select(lp_its_2020, -c(2:26))
# first remember the names
n <- lp_its_2020_matrix$ESV
# transpose all but the first column (name)
lp_its_2020_matrix_t <- as.data.frame(t(lp_its_2020_matrix[,-1]))
colnames(lp_its_2020_matrix_t) <- n
lp_its_2020 <- lp_its_2020_matrix_t
sites_its_2020 <- lp_its_2020
sites_its_2020 <- tibble::rownames_to_column(sites_its_2020, "sites")
sites_its_2020 <- dplyr::select(sites_its_2020, 1)
#repeat for 2021
lp_its_2021_matrix <- dplyr::select(lp_its_2021, -c(2:26))
# first remember the names
n <- lp_its_2021_matrix$ESV
# transpose all but the first column (name)
lp_its_2021_matrix_t <- as.data.frame(t(lp_its_2021_matrix[,-1]))
colnames(lp_its_2021_matrix_t) <- n
lp_its_2021 <- lp_its_2021_matrix_t
sites_its_2021 <- lp_its_2021
sites_its_2021 <- tibble::rownames_to_column(sites_its_2021, "sites")
sites_its_2021 <- dplyr::select(sites_its_2021, 1)
#now remove any ESVs with zeros
lp_its_2019 <- lp_its_2019[, colSums(lp_its_2019 != 0) > 0]
colSums(lp_its_2019) %>% min()
lp_its_2020 <- lp_its_2020[, colSums(lp_its_2020 != 0) > 0]
colSums(lp_its_2020) %>% min()
lp_its_2021 <- lp_its_2021[, colSums(lp_its_2021 != 0) > 0]
colSums(lp_its_2021) %>% min()
##Create a data frame with the alpha diversity metrics of interest
#2019 ITS
diversity_its_2019 <- data.frame(sites_its_2019, Shannon = diversity(lp_its_2019, index="shannon"),
InverseSimpson = diversity(lp_its_2019, index="invsimpson"),
richness = specnumber(lp_its_2019)) %>%
mutate(Evenness = InverseSimpson/richness) %>% pivot_longer(cols=c("Shannon", "InverseSimpson", "richness", "Evenness"), names_to = "diversity_metric", values_to = "diversity")
diversity_its_2019 <- separate(diversity_its_2019, col=sites, into=c('site', 'rep', 'year'), sep='_')
#reorder low to high defoliation
diversity_its_2019$site <- diversity_its_2019$site %>%
factor(levels = c("L09", "L10", "L12", "L08", "L11", "U03", "C07", "C06", "U01", "C04", "C05", "U02"))
## 2020 its
diversity_its_2020 <- data.frame(sites_its_2020, Shannon = diversity(lp_its_2020, index="shannon"),
InverseSimpson = diversity(lp_its_2020, index="invsimpson"),
richness = specnumber(lp_its_2020)) %>%
mutate(Evenness = InverseSimpson/richness) %>% pivot_longer(cols=c("Shannon", "InverseSimpson", "richness", "Evenness"), names_to = "diversity_metric", values_to = "diversity")
diversity_its_2020 <- separate(diversity_its_2020, col=sites, into=c('site', 'rep', 'year'), sep='_')
diversity_its_2020$site <- diversity_its_2020$site %>%
factor(levels = c("L10", "L08", "L09", "L12", "L11", "C06", "C07", "C05", "U03", "C04", "U01", "U02"))
## 2021 its
diversity_its_2021 <- data.frame(sites_its_2021, Shannon = diversity(lp_its_2021, index="shannon"),
InverseSimpson = diversity(lp_its_2021, index="invsimpson"),
richness = specnumber(lp_its_2021)) %>%
mutate(Evenness = InverseSimpson/richness) %>% pivot_longer(cols=c("Shannon", "InverseSimpson", "richness", "Evenness"), names_to = "diversity_metric", values_to = "diversity")
diversity_its_2021 <- separate(diversity_its_2021, col=sites, into=c('site', 'rep', 'year'), sep='_')
diversity_its_2021$site <- diversity_its_2021$site %>%
factor(levels = c("U02", "L10", "L08", "L12", "U03", "L09", "C06", "L11", "C04", "C05", "C07", "U01"))
#combine all years together so it's easier for plotting
diversity_its <- rbind(diversity_its_2019, diversity_its_2020, diversity_its_2021)
richness_its <- diversity_its %>%
filter(diversity_metric == "richness") %>%
dplyr::select(-4) %>%
dplyr::rename(richness = diversity)
mean_richness_its <- richness_its %>%
group_by(site, year) %>%
summarise(mean_richness = mean(richness))
mean_richness_its_years <- richness_its %>%
group_by(year) %>%
summarise(mean_richness = mean(richness))
richness_its_cumul_HAiFLO <- mean_richness_its %>%
inner_join(HAIFLO, by = c("site", "year"))
##ITS Plot
##correlation between mean richness and mean defoliation
p6 <- richness_its_cumul_HAiFLO %>%
ggscatter(x = "cdefo", y = "mean_richness", color = "year", size = 5,
#add = "reg.line", conf.int = TRUE,
cor.coef = FALSE, cor.coef.size = 6, cor.method = "pearson",
xlab = "Cumulative Defoliation", ylab = "Fungi Richness") + stat_cor(label.y = 450, p.accuracy = 0.01, r.accuracy = 0.01, aes(size = 6, label = paste(..r.label.., ..p.label.., sep = "~`,`~")), show.legend = FALSE, size = 6) + scale_color_brewer(palette = "Dark2") + scale_fill_brewer(palette = "Dark2") + facet_wrap(~year) + theme_bw(base_size = 20) + theme(legend.position = "bottom") + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),panel.background = element_blank(), axis.line = element_line(colour = "black"))
library(ggpubr)
ggarrange(p5, p6,
heights = c(6,3),
labels = c("A", "B"),
font.label=list(size = 22, color = "black", face = "bold"),
ncol = 1, nrow = 2)
```
# Fig 10 Algal Biomass
```{r}
#plot just the 3 types of algae for SI
pp <- defo_algae_long %>%
dplyr::filter(algal_parameter != "Total Algae") %>%
ggscatter(x = "cdefo", y = "algal_biomass", color = "Year", shape = "Region",
size = 5, add = "reg.line", conf.int = TRUE,
show.legend.text = FALSE) + stat_cor(label.y.npc=1, p.accuracy = 0.01, r.accuracy = 0.01, aes(size =5, label = paste(..r.label.., ..p.label.., sep = "~`,`~")), show.legend = FALSE, size = 5) + scale_color_manual(values = c("#1b9e77", "#7570b3")) + scale_fill_manual(values = c("#1b9e77", "#7570b3")) + facet_grid(algal_parameter~Year, scales = "free_y") +xlab("Cumulative Defoliation") +ylab("Algal Biomass (ug/cm2)") + theme_bw(base_size = 16) + theme(legend.position = "bottom") + theme(legend.position = "bottom", panel.grid.major = element_blank(),
panel.grid.minor = element_blank()) + theme(legend.box.background=element_rect(color = "black", size = 1))
pp
```
# Fig S11 Extracellular Enzyme Assays
```{r}
#SI
p1 <- enzymes_corrected_summary %>%
filter(enzyme %in% c("XY", "NAG")) %>%
ggscatter(x = "cdefo", y = "mean_activity_corrected", color = "enzyme",
conf.int = FALSE, size = 4, font.label = c(14, "plain"),
cor.coef = TRUE, cor.method = "pearson",cor.coef.size = 5,
xlab = "Cumulative Defoliation", ylab = "Mean Enzyme Activity (Weight Corrected)") +
facet_grid(enzyme~year, scales = "free_y")
p1 + theme_bw(base_size = 22) + theme(legend.position = "bottom", panel.grid.major = element_blank(),
panel.grid.minor = element_blank()) + theme(legend.box.background=element_rect(color = "black", size = 1)) + scale_fill_brewer(palette = "Dark2", guide = "none") + scale_color_brewer(palette = "Dark2", guide = "none")
```
# Fig S12 Leaf Litter Decomposition
```{r}
leafpacks <- readRDS("~/GitHub/SBWD_master/data/leafpacks.RDS")
#select only columns needed for decomposition analyses
lp_decomp <- leafpacks %>%
filter(year %in% c("2019", "2020", "2021")) %>%
dplyr::select(site, year, rep, inc_days, mass.loss.g, percent.loss)
#remove the one leafpack that was destroyed
lp_decomp <- lp_decomp[-216, ]
lp_decomp$site <- lp_decomp$site %>%
factor(levels = c("U01", "U02", "U03", "C04", "C05", "C06", "C07", "L08", "L09", "L10", "L11", "L12"))
lp_decomp$year <- as.factor(lp_decomp$year)
#boxplot
p1 <- lp_decomp %>%
ggplot(aes(x = site, y = percent.loss, fill = year)) +
facet_wrap(~year) +
geom_boxplot() +
labs(title = "Leafpack Decomposition (% Mass Loss)") + theme_bw(base_size = 14) + theme(legend.position="bottom")
#scatterplot against incubation time
p2<- lp_decomp %>%
ggplot(aes(x = inc_days, y = percent.loss, color = year)) +
geom_point(size=4)+
labs(title = "Leafpack Decomposition (% Mass Loss) vs Incubation Time", x = "Incubation Time (days)", y = "Mass loss (%)") + theme_bw(base_size = 14)
#need to do mass loss per day
lp_decomp$inc_days <- as.numeric(lp_decomp$inc_days)
lp_decomp$percent.loss.day <- lp_decomp$percent.loss/lp_decomp$inc_days
lp_decomp %>%
ggplot(aes(x = site, y = percent.loss.day, fill = year)) +
facet_wrap(~year) +
geom_boxplot() +
labs(title = "Leafpack Decomposition (% Mass Loss per day)", y = "Percent Mass Loss per day") + theme_bw(base_size = 14) + theme(legend.position="bottom")
#group by site to see if any differnces between years
p3 <- lp_decomp %>%
ggplot(aes(x = year, y = percent.loss.day, fill = year)) +
facet_grid (~site, switch = 'x') +
geom_boxplot() +
labs(title = "Leafpack Decomposition (% Mass Loss per day)", y = "Percent Mass Loss per day", x = "site") + theme(axis.text.x=element_blank(), axis.ticks.x=element_blank(), text = element_text(size = 14))
#need average decomp per site per year
decomp_summary <- lp_decomp %>%
group_by(site, year) %>%
summarize(mean_percent_loss =mean(percent.loss), N=length(percent.loss), sd=sd(percent.loss), se = sd/sqrt(N))
decomp_summary2 <- lp_decomp %>%
group_by(site, year) %>%
summarize(mean_percent_loss_day =mean(percent.loss.day))
#cumulative defo
decomp_cdefo2 <- decomp_summary2 %>%
inner_join(HAIFLO, by = c("site", "year"))
#plot correlations
p2 <- decomp_cdefo2 %>%
ggscatter(x = "cdefo", y = "mean_percent_loss_day", color = "year",
conf.int = FALSE, size = 4,
cor.coef = FALSE, cor.method = "pearson") +
xlab("Cumulative Defoliation") + ylab("% Mass Loss per Day") +
facet_wrap(~year) + stat_cor(p.accuracy = 0.01, r.accuracy = 0.01, aes(size =5, label = paste(..r.label.., ..p.label.., sep = "~`,`~")), show.legend = FALSE, size = 5) + scale_color_brewer(palette = "Dark2") + scale_fill_brewer(palette = "Dark2", guide = "none")
p2 + theme_bw(base_size = 18) + theme(legend.position = "bottom", panel.grid.major = element_blank(),
panel.grid.minor = element_blank())
```
# Fig S13 PiCRust Functional Groups
```{r}
#SI plot
pathway_defo_all4 %>%
filter(pathway_type %in% c("Alcohol-Degradation", "Aminoacyl-tRNAs-Charging")) %>%
ggscatter(x = "cdefo", y = "sum_types", color = "year",
add = "reg.line", conf.int = TRUE, cor.coef.size = 5) +
stat_cor(p.accuracy = 0.01, r.accuracy = 0.01,
aes(size = 5, label = paste(..r.label.., ..p.label.., sep = "~`,`~")), show.legend = FALSE, size = 5) + xlab("Cumulative Defoliation") + ylab("Relative Abundance") + facet_grid(pathway_type~year, scales = "free_y") + theme_bw(base_size = 18) + theme(legend.position = "bottom", panel.grid.major = element_blank(),
panel.grid.minor = element_blank()) + scale_fill_brewer(palette="Dark2") + scale_color_brewer(palette="Dark2")
```