-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02_Exploratory_graphs.R
1966 lines (1710 loc) · 69.3 KB
/
02_Exploratory_graphs.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
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
# Code for plotting out data for exploratory purposes
library(dplyr)
library(tidyr)
library(ggplot2)
theme_set(theme_classic())
library(gganimate)
library(mice)
library(janitor)
library(patchwork)
# atmospheric data plots ####
# Sdep maps
str(Sdep_avg)
Sdep_avg_long <- melt(Sdep_avg, id.vars = c("x","y"))
Sdep_avg_long$year <- substring(Sdep_avg_long$variable, 9,12)
ggplot(Sdep_avg_long, aes(x = x, y = y, fill = value)) +
geom_tile() +
scale_fill_viridis_c(name = "") +
coord_fixed() +
facet_wrap(~year, nrow = 5) +
labs(x = "",y = "", title = "Sdep grid average kgS / ha") +
theme(axis.text = element_blank(), axis.ticks = element_blank())
ggsave("Sdep grid average maps.png", path = "Outputs/Graphs/",
width = 28, height = 28, units = "cm")
# animated version
Sdep_avg_long %>%
mutate(year = as.integer(year)) %>%
ggplot(aes(x = x, y = y, fill = value)) +
geom_tile() +
scale_fill_viridis_c(name = "Sdep (kgS/ha)") +
coord_fixed() +
theme(axis.text = element_blank(), axis.ticks = element_blank()) +
labs(title = 'Year: {frame_time}', x = '', y = '') +
transition_time(year) +
ease_aes('linear')
str(Sdep_for)
Sdep_for_long <- melt(Sdep_for, id.vars = c("x","y"))
Sdep_for_long$year <- substring(Sdep_for_long$variable, 8,11)
ggplot(Sdep_for_long, aes(x = x, y = y, fill = value)) +
geom_tile() +
scale_fill_viridis_c(name = "") +
coord_fixed() +
facet_wrap(~year, nrow = 5) +
labs(x = "",y = "", title = "Sdep forest kgS / ha") +
theme(axis.text = element_blank(), axis.ticks = element_blank())
ggsave("Sdep forest maps.png", path = "Outputs/Graphs/",
width = 28, height = 28, units = "cm")
str(Sdep_moo)
Sdep_moo_long <- melt(Sdep_moo, id.vars = c("x","y"))
Sdep_moo_long$year <- substring(Sdep_moo_long$variable, 6,9)
ggplot(Sdep_moo_long, aes(x = x, y = y, fill = value)) +
geom_tile() +
scale_fill_viridis_c(name = "") +
coord_fixed() +
facet_wrap(~year, nrow = 5) +
labs(x = "",y = "", title = "Sdep moorland kgS / ha") +
theme(axis.text = element_blank(), axis.ticks = element_blank())
ggsave("Sdep moorland maps.png", path = "Outputs/Graphs/",
width = 28, height = 28, units = "cm")
# Ndep maps
str(Ndep_avg)
Ndep_avg_long <- melt(Ndep_avg, id.vars = c("x","y"))
Ndep_avg_long$year <- substring(Ndep_avg_long$variable, 9,12)
ggplot(Ndep_avg_long, aes(x = x, y = y, fill = value)) +
geom_tile() +
scale_fill_viridis_c(name = "") +
coord_fixed() +
facet_wrap(~year, nrow = 5) +
labs(x = "",y = "", title = "Ndep grid average kgN / ha") +
theme(axis.text = element_blank(), axis.ticks = element_blank())
ggsave("Ndep grid average maps.png", path = "Outputs/Graphs/",
width = 28, height = 28, units = "cm")
str(Ndep_for)
Ndep_for_long <- melt(Ndep_for, id.vars = c("x","y"))
Ndep_for_long$year <- substring(Ndep_for_long$variable, 8,11)
ggplot(Ndep_for_long, aes(x = x, y = y, fill = value)) +
geom_tile() +
scale_fill_viridis_c(name = "") +
coord_fixed() +
facet_wrap(~year, nrow = 5) +
labs(x = "",y = "", title = "Ndep forest kgN / ha") +
theme(axis.text = element_blank(), axis.ticks = element_blank())
ggsave("Ndep forest maps.png", path = "Outputs/Graphs/",
width = 28, height = 28, units = "cm")
str(Ndep_moo)
Ndep_moo_long <- melt(Ndep_moo, id.vars = c("x","y"))
Ndep_moo_long$year <- substring(Ndep_moo_long$variable, 6,9)
ggplot(Ndep_moo_long, aes(x = x, y = y, fill = value)) +
geom_tile() +
scale_fill_viridis_c(name = "") +
coord_fixed() +
facet_wrap(~year, nrow = 5) +
labs(x = "",y = "", title = "Ndep moorland kgN / ha") +
theme(axis.text = element_blank(), axis.ticks = element_blank())
ggsave("Ndep moorland maps.png", path = "Outputs/Graphs/",
width = 28, height = 28, units = "cm")
# Plot Sdep and Ndep against each other
colnames(Sdep_avg_long) <- c("x","y","variable","Sdep","year")
colnames(Ndep_avg_long) <- c("x","y","variable","Ndep","year")
AtDep_avg <- merge(Sdep_avg_long, Ndep_avg_long, by = c("x","y","variable","year"))
str(AtDep_avg)
AtDep_avg$year <- as.integer(AtDep_avg$year)
AtDep_avg <- na.omit(AtDep_avg)
AtDep_avg$square <- paste(AtDep_avg$x, AtDep_avg$y, sep = "_")
ggplot(AtDep_avg, aes(x = Sdep, y = Ndep)) +
geom_point(aes(group = square)) +
labs(title = 'Year: {frame_time}', x = 'Sdep (kgS/ha)', y = 'Ndep (kgN/ha)') +
transition_time(year) +
ease_aes('linear')
AtDep_avg %>%
pivot_longer(Sdep:Ndep, names_to = "Element",
values_to = "measure") %>%
mutate(Element = ifelse(Element == "Sdep", "Sdep (kgS/ha)", "Ndep (kgN/ha)")) %>%
ggplot(aes(x = x, y = y, fill = measure)) +
geom_tile() +
scale_fill_viridis_c(name = "", na.value = "white") +
coord_fixed() +
facet_wrap(~Element) +
theme(axis.text = element_blank(), axis.ticks = element_blank(),
axis.line = element_blank()) +
labs(title = 'Year: {frame_time}', x = '', y = '') +
transition_time(year) +
ease_aes('linear')
# forest
colnames(Sdep_for_long) <- c("x","y","variable","Sdep","year")
colnames(Ndep_for_long) <- c("x","y","variable","Ndep","year")
AtDep_for <- merge(Sdep_for_long, Ndep_for_long, by = c("x","y","variable","year"))
str(AtDep_for)
AtDep_for$year <- as.integer(AtDep_for$year)
AtDep_for <- na.omit(AtDep_for)
AtDep_for$square <- paste(AtDep_for$x, AtDep_for$y, sep = "_")
ggplot(AtDep_for, aes(x = Sdep, y = Ndep)) +
geom_point(aes(group = square)) +
labs(title = 'Year: {frame_time}', x = 'Sdep (kgS/ha)', y = 'Ndep (kgN/ha)') +
transition_time(year) +
ease_aes('linear')
AtDep_for %>%
pivot_longer(Sdep:Ndep, names_to = "Element",
values_to = "measure") %>%
mutate(Element = ifelse(Element == "Sdep", "Sdep (kgS/ha)", "Ndep (kgN/ha)")) %>%
ggplot(aes(x = x, y = y, fill = measure)) +
geom_tile() +
scale_fill_viridis_c(name = "", na.value = "white") +
coord_fixed() +
facet_wrap(~Element) +
theme(axis.text = element_blank(), axis.ticks = element_blank(),
axis.line = element_blank()) +
labs(title = 'Year: {frame_time}', x = '', y = '') +
transition_time(year) +
ease_aes('linear')
# moorland
colnames(Sdep_moo_long) <- c("x","y","variable","Sdep","year")
colnames(Ndep_moo_long) <- c("x","y","variable","Ndep","year")
AtDep_moo <- merge(Sdep_moo_long, Ndep_moo_long, by = c("x","y","variable","year"))
str(AtDep_moo)
AtDep_moo$year <- as.integer(AtDep_moo$year)
AtDep_moo <- na.omit(AtDep_moo)
AtDep_moo$square <- paste(AtDep_moo$x, AtDep_moo$y, sep = "_")
ggplot(AtDep_moo, aes(x = Sdep, y = Ndep)) +
geom_point(alpha = 0.2, aes(group = square)) +
labs(title = 'Year: {frame_time}', x = 'Sdep (kgS/ha)', y = 'Ndep (kgN/ha)') +
transition_time(year) +
ease_aes('linear')
AtDep_moo %>%
pivot_longer(Sdep:Ndep, names_to = "Element",
values_to = "measure") %>%
mutate(Element = ifelse(Element == "Sdep", "Sdep (kgS/ha)", "Ndep (kgN/ha)")) %>%
ggplot(aes(x = x, y = y, fill = measure)) +
geom_tile() +
scale_fill_viridis_c(name = "", na.value = "white") +
coord_fixed() +
facet_wrap(~Element) +
theme(axis.text = element_blank(), axis.ticks = element_blank(),
axis.line = element_blank()) +
labs(title = 'Year: {frame_time}', x = '', y = '') +
transition_time(year) +
ease_aes('linear')
# Cumulative deposition per square ####
AtDepavg_cumdep_sq <- AtDep_avg %>%
mutate(year_cat = ifelse(year %in% 1970:1978, "70_78",
ifelse(year %in% 1979:1998, "79_98",
ifelse(year %in% 1999:2007, "99_07",
ifelse(year %in% 2008:2018, "08_18",NA))))) %>%
group_by(x,y,square, year_cat) %>%
summarise(Sdep = sum(Sdep),
Ndep = sum(Ndep)) %>%
ungroup() %>%
pivot_wider(names_from = year_cat,
values_from = c(Sdep, Ndep))
psych::pairs.panels(select(AtDepavg_cumdep_sq,-x,-y,-square))
# merge with CS plots
dep_x <- AtDepavg_cumdep_sq$x
dep_y <- AtDepavg_cumdep_sq$y
CS_m <- CS07_PLOTS %>% select(plot_x = POINT_X,
plot_y = POINT_Y, REP_ID)
for(i in 1:nrow(CS_m)) {
CS_m[i,"x"] <- dep_x[which.min(abs(dep_x - CS_m$plot_x[i]))]
CS_m[i,"y"] <- dep_y[which.min(abs(dep_y - CS_m$plot_y[i]))]
}
CS_Atdep <- left_join(CS_m, AtDepavg_cumdep_sq)
summary(CS_Atdep)
psych::multi.hist(select_if(CS_Atdep, is.numeric))
AtDepfor_cumdep_sq <- AtDep_for %>%
mutate(year_cat = ifelse(year %in% 1970:1978, "70_78",
ifelse(year %in% 1979:1998, "79_98",
ifelse(year %in% 1999:2007, "99_07",
ifelse(year %in% 2008:2018, "08_18",NA))))) %>%
group_by(x,y,square, year_cat) %>%
summarise(Sdep = sum(Sdep),
Ndep = sum(Ndep)) %>%
ungroup() %>%
pivot_wider(names_from = year_cat,
values_from = c(Sdep, Ndep))
# difference since 1970
AtDepavg_diff_sq <- AtDep_avg %>%
mutate(year_cat = ifelse(year %in% 1970:1978, "70_78",
ifelse(year %in% 1979:1998, "79_98",
ifelse(year %in% 1999:2007, "99_07",
ifelse(year %in% 2008:2018, "08_18",NA))))) %>%
group_by(x,y,square, year_cat) %>%
summarise(Sdep = sum(Sdep),
Ndep = sum(Ndep)) %>%
ungroup() %>%
pivot_wider(names_from = year_cat,
values_from = c(Sdep, Ndep))
psych::pairs.panels(select(AtDepavg_cumdep_sq,-x,-y,-square))
# merge with CS plots
dep_x <- AtDepavg_cumdep_sq$x
dep_y <- AtDepavg_cumdep_sq$y
# Soil pH data ####
# data manipulation
str(CS78_PH)
str(CS98_PH)
str(CS07_PH)
str(CS16_PH)
str(UK19_PH)
CS78_PH$REP_ID <- paste(CS78_PH$SQUARE_NUM,CS78_PH$REP_NUM, sep = "X")
CS98_PH$REP_ID <- paste(CS98_PH$SQUARE_NUM,CS98_PH$REP_NUM, sep = "X")
CS07_PH$REP_ID <- paste(CS07_PH$SQUARE_NUM,CS07_PH$REP_NUM, sep = "X")
CS16_PH$REP_ID <- paste(CS16_PH$SQUARE_NUM,CS16_PH$REP_NUM, sep = "X")
UK19_PH$REP_ID <- paste(UK19_PH$SQUARE_NUM,UK19_PH$REP_NUM, sep = "X")
PH <- full_join(select(CS78_PH, REP_ID, PH1978),
select(CS98_PH, REP_ID, PH2000 = PHF2000)) %>%
full_join(select(CS07_PH, REP_ID, PH2007 = PH2007_IN_WATER)) %>%
full_join(select(CS16_PH, REP_ID, PH2016 = PH_DIW)) %>%
full_join(select(UK19_PH, REP_ID, PH2019 = PH_DIW))
str(PH)
summary(PH)
mice::md.pattern(PH)
# histograms
PH_long <- pivot_longer(PH, starts_with("PH"),
values_to = "pH",
values_drop_na = TRUE)
ggplot(PH_long, aes(x = pH)) +
geom_histogram() +
facet_wrap(~name, scales = "free_y")
PH_long$year <- as.integer(substring(PH_long$name, 3,6))
ggplot(PH_long, aes(x = year, y = pH, group = REP_ID)) +
geom_line(alpha = 0.2, col = "dodgerblue2")+
geom_jitter(alpha = 0.2, width = 1, height = 0, shape = 16)
# calculate differences between survey years
PH <- PH %>%
mutate(diff7898 = PH2000 - PH1978,
diff7807 = PH2007 - PH1978,
diff7816 = PH2016 - PH1978,
diff7819 = PH2019 - PH1978,
diff9807 = PH2007 - PH2000,
diff9816 = PH2016 - PH2000,
diff9819 = PH2019 - PH2000,
diff0716 = PH2016 - PH2007,
diff0719 = PH2019 - PH2007) %>%
mutate(diff0718 = ifelse(!is.na(diff0719), diff0719,
ifelse(!is.na(diff0716), diff0716, NA)),
diff7818 = ifelse(!is.na(diff7819), diff7819,
ifelse(!is.na(diff7816), diff7816, NA)),
diff9818 = ifelse(!is.na(diff9819), diff9819,
ifelse(!is.na(diff9816), diff9816, NA)))
summary(PH)
PH_diff_long <- PH %>%
select(REP_ID, starts_with("diff")) %>%
pivot_longer(starts_with("diff"),
values_to = "pH",
values_drop_na = TRUE) %>%
mutate(name = as.factor(name)) %>%
mutate(name = forcats::fct_inorder(name))
ggplot(PH_diff_long, aes(x = pH)) +
geom_histogram() +
facet_wrap(~name, scales = "free_y") +
geom_vline(xintercept = 0)
# select only most recent change and convert into wide format for plotting
PH_Diff_wide <- select(PH, REP_ID, diff0718) %>%
na.omit() %>%
left_join(select(CS07_PLOTS, REP_ID, POINT_X, POINT_Y))
summary(PH_Diff_wide)
ggplot(PH_Diff_wide, aes(x = POINT_X, y = POINT_Y, colour = diff0718)) +
geom_jitter(width = 5000, height = 5000) +
coord_fixed() +
scale_colour_distiller(palette = "RdBu", direction = 1,
limits = c(-1,1)*max(abs(PH_Diff_wide$diff0718)),
name = "pH change", na.value = "white") +
theme_dark()
# ** pH maps ####
library(sf)
library(leaflet)
# convert to sf object
CS_PH_loc <- PH_Diff_wide %>%
select(POINT_X, POINT_Y) %>%
as.matrix() %>%
st_multipoint(dim="XY") %>%
st_sfc(crs = 27700) %>%
st_transform(crs = 4326) %>%
st_cast("POINT")
CS_PH_loc <- st_sf(cbind(select(PH_Diff_wide, REP_ID, pH_change = diff0718),CS_PH_loc))
# Create variable for colouring of points. first cut the continuous variable
# into bins - these bins are now factors
CS_PH_loc$pH_lev <- cut(CS_PH_loc$pH_change,
c(-3,-1.5,-1,-0.5,0,0.5,1,1.5,3))
pHCol <- colorFactor(palette = 'RdBu', CS_PH_loc$pH_lev)
# add random jitter to points so not overplotting
CS_PH_loc_jitter <- st_jitter(CS_PH_loc, factor = 0.005)
# read in UK boundary shapefile
UK_boundary <- st_read("../../../GBR_adm/GBR_adm0.shp")
# plot interactively
leaflet() %>%
addPolygons(data = UK_boundary, stroke = FALSE,
color = "black") %>%
addCircleMarkers(data = CS_PH_loc_jitter, radius = 5,
label = CS_PH_loc$REP_ID,
color = ~pHCol(CS_PH_loc$pH_lev),
fillOpacity = 1, stroke = FALSE) %>%
addLegend('topright', pal = pHCol, values = CS_PH_loc$pH_lev,
title = 'pH change',
opacity = 1)
# plot histograms of difference between survey years wrapping together 16 and 19
PH_diff_long %>% filter(name %in%
c("diff7807","diff9807","diff7898",
"diff7818","diff9818","diff0718")) %>%
ggplot(aes(x = pH)) +
geom_histogram() +
facet_wrap(~name) +
geom_vline(xintercept = 0)
ggsave("pH change histograms facet by survey comparison.png",
path = "Outputs/Graphs/",
width = 20, height = 12, units = "cm")
# remove 18 variables for consistency later in script
PH_diff_long <- filter(PH_diff_long,
names %in% c("diff7898",
"diff7807",
"diff7816",
"diff7819",
"diff9807",
"diff9816",
"diff9819",
"diff0716",
"diff0719"))
# ** breakdown by AVC data ####
# AVC data manipulation
hab07 <- select(CS07_IBD, REP_ID = REP_ID07, AVC07) %>%
unique()
hab98 <- select(CS98_IBD, REP_ID = REP_ID98, AVC98) %>%
unique()
hab78 <- select(CS78_IBD, REP_ID = REP_ID78, AVC78) %>%
unique()
# create combined AVC variable, if 07 has AVC use that otherwise use 98 then 78.
# There are only 3 sites with no AVC data and I can't see how to get theirs as
# they don't appear in 2016/19.
hab <- full_join(hab07, hab98) %>% full_join(hab78) %>%
mutate_if(is.factor, as.character) %>%
mutate(AVC = ifelse(!is.na(AVC07), AVC07,
ifelse(!is.na(AVC98), AVC98,
ifelse(!is.na(AVC78), AVC78, NA)))) %>%
mutate(AVC_desc = recode(AVC,
`1` = "Crops/Weeds",
`2` = "Tall herb/grass",
`3` = "Fertile grassland",
`4` = "Infertile grassland",
`5` = "Lowland wooded",
`6` = "Upland wooded",
`7` = "Moorland grass/mosaic",
`8` = "Heath/bog"))
# calculate total change in pH over survey years
PH$change_dir <- rowSums(select(PH, diff7898, diff9807, diff0719), na.rm = TRUE)
summary(PH$change_dir)
filter(PH,change_dir == 0) %>% select(starts_with("diff")) %>%
summary()
PH$change_dir <- ifelse(PH$change_dir == 0 & !is.na(PH$diff7807), PH$diff7807, PH$change_dir)
PH$change_dir <- ifelse(PH$change_dir == 0 & !is.na(PH$diff7819), PH$diff7819, PH$change_dir)
# Combine pH and AVC data and convert to long format
PH_long_hab <- left_join(PH, select(BH_IMP, REP_ID, Management)) %>%
droplevels() %>%
select(-starts_with("diff")) %>%
pivot_longer(starts_with("PH"),
names_to = c("Variable","year"),
names_sep = "_",
values_to = "pH",
values_drop_na = TRUE) %>%
filter(!is.na(Management )) %>%
mutate(year = as.numeric(year))
# plots of pH change over time
PH_long_hab %>%
ggplot(aes(x = year, y = pH, group = REP_ID)) +
geom_line(alpha = 0.5, aes(colour = change_dir) )+
geom_jitter(size = 0.2, width = 1, height = 0, shape = 16, alpha = 0.8,
aes(colour = change_dir)) +
facet_wrap(~Management, nrow = 2) +
scale_colour_distiller(palette = "RdBu", direction = 1,
limits = c(-1,1)*max(abs(PH_long_hab$change_dir)),
name = "pH change", na.value = "white") +
theme_dark()
ggsave("pH change over time facetted by Management.png", path = "Outputs/Graphs/",
width = 12, height = 12, units = "cm")
PH_long_hab %>%
ggplot(aes(x = year, y = pH)) +
geom_line(alpha = 0.5, aes(colour = change_dir, group = REP_ID))+
geom_jitter(size = 0.2, width = 1, height = 0,
shape = 16, alpha = 0.1,
colour = "grey50") +
geom_boxplot(fill= NA, aes(group = year), outlier.shape = NA) +
facet_wrap(~Management, nrow = 2) +
# geom_smooth(formula = y ~ poly(x,3)) +
scale_colour_distiller(palette = "RdBu", direction = 1,
limits = c(-1,1)*max(abs(PH_long_hab$change_dir)),
name = "pH change", na.value = "white") +
# theme_dark() +
NULL
ggsave("pH change over time boxplots facetted by management.png", path = "Outputs/Graphs/",
width = 12, height = 15, units = "cm")
# combine ph difference and AVC data
PH_diff_long <- left_join(PH_diff_long,
select(hab, REP_ID, AVC = AVC_desc)) %>%
droplevels()
table(PH_diff_long$AVC)
get_dupes(PH_diff_long, REP_ID, name)
PH_diff_long %>%
filter(!is.na(AVC)) %>%
filter(name %in% c("diff7807","diff7898","diff9807","diff7818","diff9818","diff0718")) %>%
ggplot(aes(x = pH)) +
geom_histogram() +
geom_vline(xintercept = 0) +
facet_grid(AVC ~ name, scales = "free_y")
ggsave("pH difference histograms facetted by AVC and year.png",
path = "Outputs/Graphs/", width = 28, height = 24, units = "cm")
# ** Soil pH in CaCl2 ####
# Only have pH in CaCl2 data for 2007 onwards
str(CS78_PH)
str(CS98_PH)
str(CS07_PH)
str(CS16_PH)
str(UK19_PH)
# data manipulation
PHC <- full_join(select(CS07_PH, REP_ID, PHC2007 = PH2007_IN_CACL2),
select(CS16_PH, REP_ID, PHC2016 = PH_CACL2)) %>%
full_join(select(UK19_PH, REP_ID, PHC2019 = PH_CACL)) %>%
mutate(pH_change = ifelse(!is.na(PHC2019), PHC2019 - PHC2007,
ifelse(!is.na(PHC2016), PHC2016 - PHC2007, NA))) %>%
left_join(unique(select(hab, REP_ID, AVC = AVC_desc)))
str(PHC)
summary(PHC)
md.pattern(PHC)
# histograms of pH CaCl2 change
PHC %>% filter(!is.na(AVC)) %>%
ggplot(aes(x = pH_change)) + geom_histogram() +
geom_vline(xintercept = 0) +
facet_wrap(~AVC, nrow = 2)
ggsave("pH CaCl2 change 07 to 1619 facet by AVC.png", path = "Outputs/Graphs/",
width = 28, height = 12, units = "cm")
p1 <-PHC %>%
ggplot(aes(x = pH_change)) + geom_histogram() +
geom_vline(xintercept = 0)+
labs(x = "pH change", title = bquote("pH (CaCl"[2]*")")) +
scale_x_continuous(limits = c(-3,3))+
scale_y_continuous(limits = c(0,110), expand = c(0,0))
p2 <- PH_diff_long %>% filter(name %in% c("diff0716","diff0719")) %>%
ggplot(aes(x = pH)) + geom_histogram() +
geom_vline(xintercept = 0) +
labs(x = "", title = "pH (DIW)")+
scale_x_continuous(limits = c(-3,3))+
scale_y_continuous(limits = c(0,110), expand = c(0,0))
p2/p1
ggsave("pH change 07 to 1619 DIW and CaCl2.png", path = "Outputs/Graphs/",
width = 15, height = 18, units = "cm")
# data manipulation into long format
PHC_long <- PHC %>%
pivot_longer(starts_with("PHC"), names_to = "year",
names_prefix = "PHC", values_to = "pH_CaCl2",
values_drop_na = TRUE)
str(PHC_long)
# boxplot/line/scatter plot of pH CaCl2 change over time
PHC_long %>% mutate(year = as.numeric(year)) %>%
filter(!is.na(AVC)) %>%
ggplot(aes(x = year, y = pH_CaCl2)) +
geom_jitter(shape = 16, size = 0.5, alpha = 0.5,
width = 1, height = 0) +
geom_boxplot(aes(group = year), fill = NA) +
geom_line(aes(group = REP_ID, colour = pH_change), alpha = 0.5) +
facet_wrap(~AVC, nrow = 2) +
scale_colour_distiller(palette = "RdBu", direction = 1,
limits = c(-1,1)*abs(max(PHC_long$pH_change)))
ggsave("pH CaCl2 over time boxplots facet by AVC.png",
path = "Outputs/Graphs/",
width =28, height = 15, units = "cm")
# combine pH in CaCl2 and DIW and plot against each other
phc_wide_diff <- PH %>%
mutate(pH_diw_change = ifelse(!is.na(diff0719),diff0719,
ifelse(!is.na(diff0716), diff0716, NA))) %>%
select(REP_ID, PH2007, PH2016, PH2019, pH_diw_change) %>%
full_join(PHC)
ggplot(phc_wide_diff, aes(x = pH_diw_change, y = pH_change)) +
geom_abline(intercept = 0,slope = 1, colour = "grey") +
geom_vline(xintercept = 0, colour = "grey") +
geom_hline(yintercept = 0, colour = "grey") +
geom_point() +
# geom_smooth(method = "lm") +
labs(x = "pH (DIW) change", y = bquote("pH (CaCl"[2]*") change"))
ggsave("pH change over time DIW vs CaCl2 scatterplot.png",
path = "Outputs/Graphs/",
width = 15, height = 15, units = "cm")
# there is one sample with a NA for AVC so removing
phc_wide_diff %>% filter(!is.na(AVC)) %>%
ggplot(aes(x = pH_diw_change, y = pH_change)) +
geom_abline(intercept = 0,slope = 1, colour = "grey") +
geom_vline(xintercept = 0, colour = "grey") +
geom_hline(yintercept = 0, colour = "grey") +
facet_wrap(~AVC, nrow = 2) +
geom_point() +
# geom_smooth(method = "lm") +
labs(x = "pH (DIW) change", y = bquote("pH (CaCl"[2]*") change"))
ggsave("pH change over time DIW vs CaCl2 scatterplots facet by AVC.png",
path = "Outputs/Graphs/",
width = 28, height = 15, units = "cm")
PH %>%
select(REP_ID, PHC_2007, PH_2007, PH_2019, PHC_2019) %>%
pivot_longer(starts_with("PH"),
names_to = c("Variable","Year"),
names_sep = "_") %>%
na.omit() %>%
pivot_wider(names_from = "Variable",
values_from = "value") %>%
ggplot(aes(x = PH, y = PHC, colour = Year)) +
geom_point() +
geom_abline(slope = 1, intercept = 0) +
coord_fixed() +
facet_wrap(~Year) +
labs(x = "pH (DIW)", y = bquote("pH CaCl"[2]))
# Plant Ellenberg scores ####
str(CS19_SP)
table(CS19_SP$PLOT_TYPE)
unique(CS19_SP[CS19_SP$PLOT_TYPE=="XX","REP_ID"])
table(CS19_SP[CS19_SP$PLOT_TYPE=="X","PLOTYEAR"])
str(SPECIES_LIB_TRAITS)
filter(SPECIES_LIB_CODES, COLUMN_NAME == "GROWTH_FORM")
CS18_ELL <- filter(CS19_SP, PLOT_TYPE %in% c("X","XX")) %>%
mutate(REP_ID = paste0(SQUARE,PLOT_TYPE,PLOT_NUMBER)) %>%
mutate(REP_ID = gsub("XX","X",REP_ID)) %>%
left_join(select(SPECIES_LIB_TRAITS, BRC_NUMBER,
starts_with("EBER"),
GROWTH_FORM)) %>%
filter(GROWTH_FORM %in% c("f","fe","g","m","s","ss","w")) %>% # filter to vascular plants
mutate(across(starts_with("EBER"), na_if, y = 0)) %>% # set 0 values to NA
group_by(REP_ID) %>%
summarise(across(starts_with("EBER"), mean, na.rm = TRUE,
.names = "{col}18")) %>%
rename_with(~gsub("EBERG","",.x))
summary(CS18_ELL)
test <- full_join(CS18_ELL, GM16_IBD, by = c("REP_ID" = "REP_ID16"))
plot(N18 ~ N16, test);abline(0,1)
CS98_ELL <- CS98_SP %>%
select(REP_ID, BRC_NUMBER, TOTAL_COVER) %>%
unique() %>%
filter(TOTAL_COVER > 0) %>%
left_join(select(SPECIES_LIB_TRAITS, BRC_NUMBER,
starts_with("EBER"),
GROWTH_FORM)) %>%
# filter(GROWTH_FORM %in% c("f","fe","g","m","s","ss","w")) %>% # filter to vascular plants
mutate(across(starts_with("EBER"), na_if, y = 0)) %>% # set 0 values to NA
group_by(REP_ID) %>%
summarise(across(starts_with("EBER"), function(x) sum(x, na.rm=TRUE)/length(na.omit(EBERGN)),
.names = "{col}98_new")) %>%
rename_with(~gsub("EBERG","",.x))
test <- full_join(CS98_ELL, CS98_IBD, by = c("REP_ID" = "REP_ID98"))
#par(mfrow=c(2,2))
plot(R98_new ~ R98, test);abline(0,1)
plot(N98_new ~ N98, test);abline(0,1)
plot(W98_new ~ F98, test);abline(0,1)
plot(L98_new ~ L98, test);abline(0,1)
par(mfrow=c(1,1))
summary(CS18_ELL)
X_Ell_comp <- full_join(X_Ell_inner, X_Ell_whole) %>%
left_join(hab) %>%
mutate(R_diff = SM_R - WH_R,
N_diff = SM_N - WH_N,
W_diff = SM_W - WH_W,
L_diff = SM_L - WH_L)
p1 <- ggplot(X_Ell_comp, aes(x = WH_R, y = SM_R)) +
geom_point(size=0.5) +
geom_abline(intercept = 0, slope = 1) +
facet_wrap(~AVC_desc) +
labs(x = bquote("Ellenberg R 400m"^2~"plot"),
y = bquote("Ellenberg R 4m"^2~"plot"))
ggplot(X_Ell_comp, aes(x = WH_N, y = SM_N)) +
geom_point() +
geom_abline(intercept = 0, slope = 1) +
facet_wrap(~AVC_desc)
ggplot(X_Ell_comp, aes(x = R_diff)) +
geom_histogram() +
geom_vline(xintercept = 0) +
facet_wrap(~AVC_desc)
ggplot(X_Ell_comp, aes(x = WH_R, y = SM_R)) +
geom_point() +
geom_abline(intercept = 0, slope = 1) +
facet_grid(Year~AVC_desc) +
theme_bw()
ggplot(X_Ell_comp, aes(x = N_diff)) +
geom_histogram() +
geom_vline(xintercept = 0) +
facet_wrap(~AVC_desc)
X_Ell_comp %>%
select(Year, REP_ID, ends_with("diff"), AVC_desc) %>%
pivot_longer(ends_with("diff"), names_to = "Ellenberg") %>%
ggplot(aes(x = value)) +
geom_histogram() +
geom_vline(xintercept = 0) +
scale_x_continuous(limits = c(-2.5,2.5)) +
facet_grid(Ellenberg~AVC_desc)
# weighted Ellenberg comparison
X_wEll_comp <- full_join(X_wEll_inner, X_wEll_whole) %>%
left_join(hab) %>%
mutate(R_diff = SM_R - WH_R,
N_diff = SM_N - WH_N,
W_diff = SM_W - WH_W,
L_diff = SM_L - WH_L)
p2 <- ggplot(filter(X_wEll_comp, Year != 1978), aes(x = WH_R, y = SM_R)) +
geom_point(size=0.5) +
geom_abline(intercept = 0, slope = 1) +
facet_wrap(~AVC_desc) +
labs(x = bquote("Ellenberg R 400m"^2~"plot"),
y = bquote("Ellenberg R 4m"^2~"plot"))
ggplot(filter(X_wEll_comp, Year != 1978), aes(x = R_diff)) +
geom_histogram() +
geom_vline(xintercept = 0) +
facet_wrap(~AVC_desc)
X_wEll_comp %>%
select(Year, REP_ID, ends_with("diff"), AVC_desc) %>%
pivot_longer(ends_with("diff"), names_to = "Ellenberg") %>%
ggplot(aes(x = value)) +
geom_histogram() +
geom_vline(xintercept = 0) +
scale_x_continuous(limits = c(-2.5,2.5)) +
facet_grid(Ellenberg~AVC_desc)
t.test(X_wEll_comp$SM_R,X_wEll_comp$WH_R)
# t = -0.47853, df = 18816, p-value = 0.6323
t.test(X_Ell_comp$SM_R,X_Ell_comp$WH_R)
# t = -3.3001, df = 19015, p-value = 0.0009682
x <- na.omit(unique(X_wEll_comp$AVC_desc))
for(i in 1:length(x)){
dat <- filter(X_wEll_comp, AVC_desc == x[i])
print(paste(x[i],"p =",round(t.test(dat$SM_R,dat$WH_R)$p.value,5)))
}
# [1] "Tall herb/grass p = 0.85153"
# [1] "Crops/Weeds p = 0.04266"
# [1] "Fertile grassland p = 0.92217"
# [1] "Heath/bog p = 2e-05"
# [1] "Moorland grass/mosaic p = 0.12709"
# [1] "Upland wooded p = 0.74556"
# [1] "Infertile grassland p = 0.92811"
# [1] "Lowland wooded p = 0.39651"
x <- na.omit(unique(X_Ell_comp$AVC_desc))
for(i in 1:length(x)){
dat <- filter(X_Ell_comp, AVC_desc == x[i])
print(paste(x[i],"p =",round(t.test(dat$SM_R,dat$WH_R)$p.value,5)))
}
# [1] "Tall herb/grass p = 0.91431"
# [1] "Crops/Weeds p = 0.06944"
# [1] "Fertile grassland p = 0.05292"
# [1] "Heath/bog p = 0"
# [1] "Moorland grass/mosaic p = 0"
# [1] "Upland wooded p = 0.00329"
# [1] "Infertile grassland p = 0.06137"
# [1] "Lowland wooded p = 0.96831"
p1 + ggtitle("Unweighted") + p2 + ggtitle("Cover weighted")
ggsave("Ellenberg R plot size comparison.png", path = "Outputs/Graphs/",
width = 24, height = 12, units = "cm")
p1 <- ggplot(filter(X_Ell_comp, Year != 1978), aes(x = WH_N, y = SM_N)) +
geom_point(size=0.5) +
geom_abline(intercept = 0, slope = 1) +
facet_wrap(~AVC_desc) +
labs(x = bquote("Ellenberg N 400m"^2~"plot"),
y = bquote("Ellenberg N 4m"^2~"plot")) +
ggtitle("Unweighted")
p2 <- ggplot(filter(X_wEll_comp, Year != 1978), aes(x = WH_N, y = SM_N)) +
geom_point(size=0.5) +
geom_abline(intercept = 0, slope = 1) +
facet_wrap(~AVC_desc) +
labs(x = bquote("Ellenberg N 400m"^2~"plot"),
y = bquote("Ellenberg N 4m"^2~"plot")) +
ggtitle("Cover weighted")
p1 + p2
ggsave("Ellenberg N plot size comparison.png", path = "Outputs/Graphs/",
width = 24, height = 12, units = "cm")
t.test(X_wEll_comp$SM_N,X_wEll_comp$WH_N)
# t = -0.12149, df = 18823, p-value = 0.9033
t.test(X_Ell_comp$SM_N,X_Ell_comp$WH_N)
# t = -1.621, df = 19043, p-value = 0.105
# correlations
x <- na.omit(unique(X_wEll_comp$AVC_desc))
for(i in 1:length(x)){
dat <- filter(X_wEll_comp, AVC_desc == x[i])
print(paste(x[i],"p =",round(t.test(dat$SM_N,dat$WH_N)$p.value,5)))
}
# [1] "Tall herb/grass p = 0.8639"
# [1] "Crops/Weeds p = 0.04501"
# [1] "Fertile grassland p = 0.83626"
# [1] "Heath/bog p = 0.03957"
# [1] "Moorland grass/mosaic p = 0.07602"
# [1] "Upland wooded p = 0.63365"
# [1] "Infertile grassland p = 0.38431"
# [1] "Lowland wooded p = 0.31157"
x <- na.omit(unique(X_Ell_comp$AVC_desc))
for(i in 1:length(x)){
dat <- filter(X_Ell_comp, AVC_desc == x[i])
print(paste(x[i],"p =",round(t.test(dat$SM_N,dat$WH_N)$p.value,5)))
}
# [1] "Tall herb/grass p = 0.91795"
# [1] "Crops/Weeds p = 0.05538"
# [1] "Fertile grassland p = 0.38703"
# [1] "Heath/bog p = 0"
# [1] "Moorland grass/mosaic p = 0"
# [1] "Upland wooded p = 0.01399"
# [1] "Infertile grassland p = 0.41287"
# [1] "Lowland wooded p = 0.62069"
# Data manipulation
str(CS07_IBD)
str(CS98_IBD)
str(CS78_IBD)
str(GM16_IBD)
str(CS18_ELL)
# get GMEP data to have CS REP_ID
GMEP_CS_match <- CS16_PH %>%
select(SQUARE_NUM, GMEP_NUM, PLOT_TYPE, REP_NUM) %>%
filter(!is.na(GMEP_NUM)) %>%
mutate(CS_REP_ID = paste0(SQUARE_NUM, PLOT_TYPE, REP_NUM),
GMEP_REP_ID = paste0(GMEP_NUM, PLOT_TYPE, REP_NUM)) %>%
select(CS_REP_ID, GMEP_REP_ID)
# Get GMEP data into similar format to CS data
GM16_IBD <- GM16_IBD %>%
right_join(GMEP_CS_match, by = c("REP_ID" = "GMEP_REP_ID")) %>%
select(REP_ID16 = CS_REP_ID, R16 = PH, N16 = FERT, L16 = LIGHT, F16 = WET)
# Combine IBD files for the different years
IBD_comb <- full_join(CS07_IBD, CS98_IBD, by = c("REP_ID07" = "REP_ID98")) %>%
full_join(CS78_IBD, by = c("REP_ID07" = "REP_ID78")) %>%
full_join(GM16_IBD, by = c("REP_ID07" = "REP_ID16")) %>%
full_join(CS18_ELL, by = c("REP_ID07" = "REP_ID"))
# Use AVC data from 2007 if it is there, otherwise 98 or 78
IBD_comb$AVC <- ifelse(!is.na(IBD_comb$AVC07), IBD_comb$AVC07,
ifelse(!is.na(IBD_comb$AVC98), IBD_comb$AVC98,
IBD_comb$AVC78))
summary(IBD_comb$AVC)
# get plot type from REP_ID
IBD_comb$PLOT_TYPE <- gsub("[^a-zA-Z]", "", IBD_comb$REP_ID07)
summary(as.factor(IBD_comb$PLOT_TYPE))
# Calculate difference in Ell R over the years
ELL <- X_Ell %>%
select(Year, REP_ID, contains("_R_")) %>%
pivot_longer(contains("_R_"), names_to = "Ellenberg") %>%
mutate(Year = as.character(Year)) %>%
pivot_wider(names_from = Year,
names_prefix = "R") %>%
mutate(diff7890 = R1990 - R1978,
diff9098 = R1998 - R1990,
diff9807 = R2007 - R1998,
diff0719 = R2019 - R2007
)
# Calculate overall Ell R change
ELL$Rchange <- rowSums(select(ELL, diff7890, diff9098,
diff9807, diff0719), na.rm = TRUE)
summary(ELL$Rchange)
filter(ELL, Rchange == 0) %>% select(starts_with("diff")) %>%
summary()
# Convert Ell R change into long format
ELL_diff_long <- ELL %>%
select(REP_ID, starts_with("diff")) %>%
droplevels %>%
pivot_longer(starts_with("diff"), values_to = "Ell_R") %>%
filter(!is.na(Ell_R))
ELL_diff_long %>%
filter(!is.na(AVC)) %>%
ggplot(aes(x = Ell_R)) +
geom_histogram() +
geom_vline(xintercept = 0) +
facet_grid(name ~ AVC, scales = "free_y")
ggsave("Ellenberg R change histograms all plots facetted AVC year.png",
path = "Outputs/Graphs/", width = 28, height = 20, units ="cm")
# Convert Ellenberg R scores file to long format
ELL_R_LONG <- ELL %>% select(REP_ID = REP_ID07,
PLOT_TYPE = PLOT_TYPE.x,
AVC = AVC_desc, R07, R98, R78, R16, Rchange) %>%
filter(PLOT_TYPE == "X") %>%
droplevels() %>%
select(-PLOT_TYPE) %>%
pivot_longer(cols = c(R07,R98,R78,R16), names_to = "year",
names_prefix = "R") %>%
mutate(year = ifelse(year == "07", 2007,
ifelse(year == "98", 1998,
ifelse(year == "78", 1978,
ifelse(year == "16", 2016, NA)))))
str(ELL_R_LONG)
summary(ELL_R_LONG$AVC)
# Ellenberg R score change over time boxplot/scatter/line graph
ELL %>%
select(-starts_with("diff")) %>%
pivot_longer(R1978:R2019,
names_to = "year",
names_prefix = "R",
names_transform = list(year = as.integer)) %>%
left_join(BH_IMP) %>%
filter(!is.na(Management)) %>%
mutate(Management = recode(Management,
"High" = "High intensity",
"Low" = "Low intensity"),
Ellenberg = recode(Ellenberg,
"SM_R_UW" = "Small unweighted",
"SM_R_W" = "Small weighted",
"WH_R_UW" = "Full unweighted",
"WH_R_W"= "Full weighted")) %>%
ggplot(aes(x = year, y = value)) +
geom_line(alpha = 0.5, aes(group = REP_ID, colour = Rchange))+
geom_jitter(size = 0.2, width = 1, height = 0,
shape = 16, alpha = 0.1,
colour = "grey50") +
geom_boxplot(fill= NA, aes(group = year), outlier.shape = NA, width = 3) +
facet_grid(Ellenberg~Management) +
labs(y = "Ellenberg R") +
# geom_smooth(formula = y ~ poly(x,3)) +
scale_colour_distiller(palette = "RdBu", direction = 1,
limits = c(-1,1)*max(abs(ELL$Rchange)),
name = "Ell R change", na.value = "white") +
# theme_dark() +
NULL
ggsave("Ellenberg R change over time X plots boxplots facetted by Management.png",
path = "Outputs/Graphs/", width = 15, height = 20, units = "cm")
str(X_Ell)
str(BH_IMP)
plot_dat <- left_join(X_Ell, BH_IMP) %>%
filter(!is.na(Management)) %>%
select(REP_ID, Year, contains("_R_"), Management) %>%
pivot_longer(contains("_R_"),
names_to = c("PlotSize","Score","Weighting"),
names_sep = "_") %>%
mutate(PlotSize = recode(PlotSize,
"SM" = "Small",
"WH" = "Full"),
Weighting = recode(Weighting,
"UW" = "Unweighted",
"W" = "Weighted"),
Management = recode(Management,
"High" = "High intensity management",
"Low" = "Low intensity management")) %>%
pivot_wider(names_from = PlotSize,
values_from = value)
ggplot(plot_dat, aes(x = Full, y = Small)) +
geom_point(alpha = 0.25, colour = "dodgerblue3") +
geom_abline(slope = 1, intercept = 0) +
coord_fixed() +
facet_grid(Management~Weighting) +
labs(x = "Full size plot", y = "Smaller size plot")
ggsave("Ellenberg R plot size comparison by weighting and management.png",
path = "Outputs/Graphs/", width = 12, height = 12, units ="cm")
# Combined pH and ellenberg R ####
# change graphs - combine difference stats
ph_ell_comb <- ELL_diff_long %>%
select(-AVC) %>%
filter(grepl("X", REP_ID)) %>%
full_join(filter(PH_diff_long, name %in% unique(ELL_diff_long$name)))
str(ph_ell_comb)
md.pattern(ph_ell_comb)
# scatter plot of pH change against Ellenberg R change facetted by survey year
# comparison and AVC
ph_ell_comb %>%
filter(!is.na(AVC)) %>%
ggplot(aes(x = pH, y = Ell_R)) +
geom_point() +
facet_grid(name~AVC) +
geom_smooth(method = "lm")
ggsave("Ellenberg R vs pH change by AVC and survey.png",