-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFIS_TimedSwim_DataAnalysis_Plots.R
2916 lines (2505 loc) · 126 KB
/
FIS_TimedSwim_DataAnalysis_Plots.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
##---------------------------------------------------------------------------##
# clear console
rm(list = ls())
## 1. Load libraries ####
suppressPackageStartupMessages({
library(dplyr)
library(ggplot2)
library(scales)
library(tidyr)
library(gdata)
library(openxlsx)
library(lubridate)
library(reshape)
library(gridExtra)
library(ggpubr)
library(readxl)
library(tibble)
library(data.table)
library(janitor)
library(anytime)
library(stringr)
library(broom)
library(purrr)
library(sf)
library(ggspatial)
library(tmap)
library(sf)
library(sp)
library(RColorBrewer)
library(viridis)
library(ggpmisc)
library(arsenal)
library(fuzzyjoin)
library(tidytext)
})
source("C:/GitCode/AbResearch/getLegend.r")
source("C:/GitCode/AbResearch/StandardError_Functions.r")
##---------------------------------------------------------------------------##
## 2. Set sample year and file paths ####
# identify sampling year of interest
samp.year <- 2024
samp.year.folder <- file.path(paste(sprintf('C:/Users/%s/Dropbox (UTAS Research)/DiveFisheries/Abalone/FISdata',
Sys.info()[["user"]])), paste('FIS_TimedSwimSurveys', samp.year, sep = ''))
ts.plots.folder <- file.path(paste(sprintf('C:/Users/%s/Dropbox (UTAS Research)/DiveFisheries/Abalone/Assessment/Figures/FIS',
Sys.info()[["user"]])), paste('FIS_TimedSwimSurveys', samp.year, '_Plots', sep = ''))
##---------------------------------------------------------------------------##
# 3. Load data ####
# Import final dataframes
time.swim.dat.final <-
readRDS(paste(samp.year.folder, '/time.swim.dat.final.RDS', sep = ''))
time.swim.dat.df.final <-
readRDS(paste(samp.year.folder, '/time.swim.dat.df.final.RDS', sep = ''))
# Import metadata frame
time.swim.meta.dat.final <- readRDS(paste(samp.year.folder, '/time.swim.meta.dat.final.RDS', sep = ''))
##---------------------------------------------------------------------------##
# 4. Summaries ####
# Summarise total count for blockno x site x sampyear x legal.size
ts.count.sum <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C')) %>%
group_by(blockno, site, sampyear, legal.size) %>%
summarise(ab.n = sum(sizeclass_freq_10)) %>%
group_by(blockno, site, sampyear, legal.size) %>%
group_by(site)
ts.av.count <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C')) %>%
group_by(blockno, site, diver, sampyear, legal.size) %>%
summarise(ab.n = sum(sizeclass_freq_10)) %>%
group_by(blockno, sampyear, legal.size) %>%
summarise(av.count = mean(ab.n),
sites = n_distinct(site)) %>%
pivot_wider(id_cols = c(blockno),
names_from = c(legal.size, sampyear),
values_from = c('av.count', 'sites'))
ts_block_mean <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C')) %>%
group_by(blockno, site, diver, sampyear, legal.size) %>%
summarise(ab.n = sum(sizeclass_freq_10)) %>%
group_by(blockno, sampyear, legal.size) %>%
summarise(av.count = mean(ab.n),
sites = n_distinct(site))
time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C')) %>%
group_by(blockno, sampyear) %>%
summarise(n = n_distinct(sampdate),
sites = n_distinct(site)) %>%
pivot_wider(id_cols = c(blockno),
names_from = c(sampyear),
values_from = c('n', 'sites')) %>%
adorn_totals()
##---------------------------------------------------------------------------##
## TABLE 1: Site Abundance % Change ####
# Summary table of sites surveyed in sample year and percentage change in abundance
# of legal and sub-legal abalone between sample year and previous year.
# Determine mean abalone abundance for block x sampyear x size class
ten.min.mean.year <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C') &
!blockno %in% c('13', '14', '29', '30') &
!is.na(sizeclass_freq_10)) %>%
group_by(blockno, site, diver, sampyear, time.elapsed, legal.size) %>%
summarise(ab.n = sum(sizeclass_freq_10)) %>%
group_by(blockno, sampyear, legal.size) %>%
summarise(mean.ab.n = mean(ab.n),
median.ab.n = median(ab.n))
# Determine percentage change in abundance between current and previous year
perc_change <- ten.min.mean.year %>%
select(-median.ab.n) %>%
spread(sampyear, mean.ab.n) %>%
dplyr::rename(FY2020 = '2020',
FY2021 = '2021',
FY2022 = '2022',
FY2023 = '2023',
FY2024 = '2024') %>%
mutate(perc.change = round((1 - (FY2023 / FY2024)), 3) * 100) %>%
spread(legal.size, perc.change) %>%
select(-c('FY2020', 'FY2021', 'FY2022', 'FY2023', 'FY2024')) %>%
mutate(`>140 mm2` = ifelse(is.na(`>140 mm`), lag(`>140 mm`), `>140 mm`)) %>%
select(-`>140 mm`) %>%
filter(!is.na(`<140 mm`)) %>%
dplyr::rename(`>140 mm` = `>140 mm2`,
'BlockNo' = 'blockno')
# Determine number of sites surveyed in sample year
sites_year <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C') &
!blockno %in% c('13', '14', '29', '30') &
!is.na(sizeclass_freq_10) &
sampyear == samp.year) %>%
group_by(blockno) %>%
summarise(Sites = n_distinct(site))
# Join percentage changes and number of sites surveyed dataframes
year_tab <- left_join(sites_year, perc_change, by = c('blockno' = 'BlockNo')) %>%
dplyr::rename('BlockNo' = 'blockno')
# Create formatted summary table
year_tab_format <- year_tab %>%
ggpubr::ggtexttable(rows = NULL, theme = ggpubr::ttheme('mOrange'))+
theme(plot.margin=grid::unit(c(0,0,0,0), "mm"))
# Save summary tables
setwd(ts.plots.folder)
write.xlsx(year_tab, paste('TimedSwimSurvey_', samp.year-1, 'vs', samp.year, '_PercentChange.xlsx'), sheetName = "Sheet1",
col.names = TRUE, row.names = TRUE, append = FALSE)
ggsave(filename = paste('TimedSwimSurvey_', samp.year-1, 'vs', samp.year, '_PercentChange', '.pdf', sep = ''),
plot = year_tab_format, units = 'mm', width = 190, height = 120)
ggsave(filename = paste('TimedSwimSurvey_', samp.year-1, 'vs', samp.year, '_PercentChange', '.png', sep = ''),
plot = year_tab_format, units = 'mm', width = 190, height = 120)
rm('perc_change', 'sites_year', 'year_tab', 'year_tab_format')
##---------------------------------------------------------------------------##
## TABLE 2: Repeat Site % Change ####
# Summary table of sites surveyed in sample year and percentage change in abundance
# of legal and sub-legal abalone between sample year and previous year.
# Determine mean abalone abundance for block x sampyear x size class
ten.min.mean.year <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C') &
!blockno %in% c('13', '14', '21', '29', '30') &
!is.na(sizeclass_freq_10) &
ref_site == 1) %>%
group_by(blockno, site, diver, sampyear, time.elapsed, legal.size) %>%
summarise(ab.n = sum(sizeclass_freq_10)) %>%
group_by(blockno, sampyear, legal.size) %>%
summarise(mean.ab.n = mean(ab.n),
median.ab.n = median(ab.n))
# Determine percentage change in abundance between current and previous year
perc_change <- ten.min.mean.year %>%
select(-mean.ab.n) %>%
spread(sampyear, median.ab.n) %>%
dplyr::rename(FY2020 = '2020',
FY2021 = '2021',
FY2022 = '2022',
FY2023 = '2023',
FY2024 = '2024') %>%
mutate(perc.change = round((1 - (FY2023 / FY2024)), 3) * 100) %>%
spread(legal.size, perc.change) %>%
select(-c('FY2020', 'FY2021', 'FY2022', 'FY2023', 'FY2024')) %>%
mutate(`>140 mm2` = ifelse(is.na(`>140 mm`), lag(`>140 mm`), `>140 mm`)) %>%
select(-`>140 mm`) %>%
filter(!is.na(`<140 mm`)) %>%
dplyr::rename(`>140 mm` = `>140 mm2`,
'BlockNo' = 'blockno')
# Determine number of sites surveyed in sample year
sites_year <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C') &
!blockno %in% c('13', '14', '29', '30') &
!is.na(sizeclass_freq_10) &
sampyear == samp.year &
ref_site == 1) %>%
group_by(blockno) %>%
summarise(Sites = n_distinct(site))
# Join percentage changes and number of sites surveyed dataframes
year_tab <- left_join(sites_year, perc_change, by = c('blockno' = 'BlockNo')) %>%
dplyr::rename('BlockNo' = 'blockno')
# Create formatted summary table
year_tab_format <- year_tab %>%
ggpubr::ggtexttable(rows = NULL, theme = ggpubr::ttheme('mOrange'))
# Save summary tables
setwd(ts.plots.folder)
write.xlsx(year_tab, paste('TimedSwimSurvey_', samp.year-1, 'vs', samp.year, '_PercentChange_RepeatSites.xlsx'), sheetName = "Sheet1",
col.names = TRUE, row.names = TRUE, append = FALSE)
ggsave(filename = paste('TimedSwimSurvey_', samp.year-1, 'vs', samp.year, '_PercentChange_RepeatSites', '.pdf', sep = ''),
plot = year_tab_format, units = 'mm', width = 190, height = 120)
ggsave(filename = paste('TimedSwimSurvey_', samp.year-1, 'vs', samp.year, '_PercentChange_RepeatSites', '.png', sep = ''),
plot = year_tab_format, units = 'mm', width = 190, height = 120)
rm('perc_change', 'sites_year', 'year_tab', 'year_tab_format')
##---------------------------------------------------------------------------##
## TABLE 3: Site Abundance ####
## summary table of counts and CPUE by size class and block
## (NOTE: run script for CPUE above)
# Arrange size classes in order
sizeclasses <- c("0-20", "20-40", "40-60", "60-80", "80-100", "100-120", "120-140", "140-160", "160-180", "180-200", "200-220")
# Create summary table
time.swim.count.blockno <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C'),
sampyear == samp.year &
!blockno %in% c('13', '14', '29', '30')) %>%
group_by(blockno, site, diver, sampyear, legal.size, time.elapsed) %>%
summarise(ab.n = sum(sizeclass_freq)) %>%
group_by(blockno, legal.size) %>%
summarise(sites = n_distinct(site),
ab.min = round(mean(ab.n), digits = 1)) %>%
spread(legal.size, ab.min) %>%
as.data.frame() %>%
dplyr::rename('Blockno' = blockno,
'Sites' = sites,
'Average\ncount\n<140mm' = '<140 mm',
'Average\ncount\n>140mm' = '>140 mm') %>%
adorn_totals(fill = '',,,, contains('Sites'))
# Create formatted summary table
time.swim.summary.tab <- time.swim.count.blockno %>%
ggpubr::ggtexttable(rows = NULL, theme = ggpubr::ttheme('mOrange'))
# Save summary tables
setwd(ts.plots.folder)
write.xlsx(time.swim.count.blockno, paste('TimedSwimSurvey_', samp.year, '_SummaryTable.xlsx'), sheetName = "Sheet1",
col.names = TRUE, row.names = TRUE, append = FALSE)
ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_SummaryTable', '.pdf', sep = ''),
plot = time.swim.summary.tab, units = 'mm', width = 190, height = 120)
ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_SummaryTable', '.png', sep = ''),
plot = time.swim.summary.tab, units = 'mm', width = 190, height = 120)
##---------------------------------------------------------------------------##
# TABLE 4: Sites Completed ####
ts.tab <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C'),
sampyear == samp.year &
!blockno %in% c('13', '14', '29', '30')) %>%
group_by(sampyear, blockno) %>%
summarise(sites = n_distinct(site),
field.days = n_distinct(sampdate),
site.day = round(sites / field.days, digits = 1)) %>%
as.data.frame() %>%
dplyr::rename('Blockno' = blockno,
'Sites' = sites,
'Days' = field.days,
'Sites.Day' = site.day) %>%
add_row(Blockno = 'Total', Sites = sum(.$Sites), Days = sum(.$Days),
Sites.Day = round(mean(.$Sites.Day), digits = 1)) %>%
select(-sampyear)
# Create formatted summary table
ts.tab.format <- ts.tab %>%
ggpubr::ggtexttable(rows = NULL, theme = ggpubr::ttheme('mOrange'))
# Save summary tables
setwd(ts.plots.folder)
write.xlsx(ts.tab, paste('TimedSwimSurvey_', samp.year, '_SiteSummaryTable.xlsx'), sheetName = "Sheet1",
col.names = TRUE, row.names = TRUE, append = FALSE)
ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_SiteSummaryTable', '.pdf', sep = ''),
plot = ts.tab.format, units = 'mm', width = 190, height = 120)
ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_SiteSummaryTable', '.png', sep = ''),
plot = ts.tab.format, units = 'mm', width = 190, height = 120)
##---------------------------------------------------------------------------##
# Colour palette for plots
col_light <- c('#77AADD', '#99DDFF', '#44BB99', '#BBCC33',
'#AAAA00', '#EEDD88', '#EE8866', '#FFAABB',
'#DDDDDD')
##---------------------------------------------------------------------------##
## PLOT 1: Abundance Boxplot ####
# Average count of all legal and sub-legal abalone per 10 min by year for each
# site within each block (i.e. the average count between paired divers for each site).
# Determine mean abalone abundance in each block, year and size class
ten.min.mean.year <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C') &
!blockno %in% c('13', '14', '21', '29', '30') &
!is.na(sizeclass_freq_10) &
sampyear <= samp.year) %>%
group_by(blockno, site, diver, sampyear, time.elapsed, legal.size) %>%
summarise(ab.n = sum(sizeclass_freq_10)) %>%
group_by(blockno, sampyear, legal.size) %>%
summarise(mean.ab.n = mean(ab.n),
median.ab.n = median(ab.n))
# mutate(sampyear = factor(sampyear))
# Determine number of sites surveyed in each block, year and size class
time.swim.dat.n <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C') &
!blockno %in% c('13', '14', '21', '29', '30') &
sampyear <= samp.year) %>%
group_by(sampyear, blockno, legal.size) %>%
summarise(n = n_distinct(site))
# Plot for sub-legal abundance
sub.legal.plot <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C'),
legal.size == '<140 mm' &
!blockno %in% c('13', '14', '21', '29', '30') &
sampyear <= samp.year) %>%
# filter(midsize < 150) %>%
group_by(blockno, site, diver, sampyear) %>%
summarise(ab.n = sum(sizeclass_freq_10)) %>%
group_by(blockno, site, sampyear) %>%
summarise(mean.ab.n = mean(ab.n)) %>%
mutate(sampyear = factor(sampyear, levels = c('2020', '2021', '2022', '2023', '2024'))) %>%
ggplot(aes(x = blockno, y = mean.ab.n))+
geom_boxplot(aes(fill = sampyear), position = position_dodge2(1, preserve = 'single'),
outlier.colour = '#EE8866') +
scale_fill_manual(values = c("#77AADD", "#BBCC33", "#DDDDDD", '#44BB99', '#EE8866'))+
geom_point(data = ten.min.mean.year %>% filter(legal.size == '<140 mm'), aes(group = factor(sampyear, levels = c('2020', '2021', '2022', '2023', '2024'))), shape = 19,
size = 2, colour = 'red', fill = 'red', position = position_dodge2(0.8, preserve = 'single'))+
theme_bw()+
ylab(bquote('Average count (abalone.10'*~min^-1*')'))+
xlab('Blockno')+
coord_cartesian(ylim = c(0, 150))+
geom_text(data = time.swim.dat.n %>% filter(legal.size == '<140 mm'), aes(y = 150, label = n, colour = factor(sampyear, levels = c('2020', '2021', '2022', '2023', '2024'))), size = 3,
position = position_dodge2(0.8))+
scale_colour_manual(values = c("#77AADD", "#BBCC33", "#DDDDDD", '#44BB99', '#EE8866'))+
guides(size = 'legend', colour = 'none',
fill = guide_legend(title = 'Year'))+
ggtitle('Sub-legal <140 mm')+
theme(plot.title = element_text(vjust = 0, hjust = 0))+
theme(legend.position = 'none')
# Plot for legal abundance
legal.plot <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C'),
legal.size == '>140 mm' &
!blockno %in% c('13', '14', '21', '29', '30') &
sampyear <= samp.year) %>%
# filter(midsize < 150) %>%
group_by(blockno, site, diver, sampyear) %>%
summarise(ab.n = sum(sizeclass_freq_10)) %>%
group_by(blockno, site, sampyear) %>%
summarise(mean.ab.n = mean(ab.n)) %>%
mutate(sampyear = factor(sampyear, levels = c('2020', '2021', '2022', '2023', '2024'))) %>%
ggplot(aes(x = blockno, y = mean.ab.n))+
geom_boxplot(aes(fill = sampyear), position = position_dodge2(1, preserve = 'single'),
outlier.colour = '#EE8866') +
scale_fill_manual(values = c("#77AADD", "#BBCC33", "#DDDDDD", '#44BB99', '#EE8866'))+
geom_point(data = ten.min.mean.year %>% filter(legal.size == '>140 mm'), aes(group = factor(sampyear, levels = c('2020', '2021', '2022', '2023', '2024'))), shape = 19,
size = 2, colour = 'red', fill = 'red', position = position_dodge2(0.8, preserve = 'single'))+
theme_bw()+
ylab(bquote('Average count (abalone.10'*~min^-1*')'))+
xlab('Blockno')+
coord_cartesian(ylim = c(0, 150))+
guides(size = 'legend', colour = 'none',
fill = guide_legend(title = 'Year'))+
ggtitle('Legal >140 mm')+
theme(plot.title = element_text(vjust = 0, hjust = 0))+
theme(legend.title = element_blank(),
legend.position = c(0.9, 0.7))
# Join plots
count.plot.sizeclass <- grid.arrange(sub.legal.plot, legal.plot, nrow = 2)
# Save plots
setwd(ts.plots.folder)
ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_TenMinuteCount_LegalSubLegal', '.pdf', sep = ''),
plot = count.plot.sizeclass, units = 'mm', width = 190, height = 200)
ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_TenMinuteCount_LegalSubLegal', '.png', sep = ''),
plot = count.plot.sizeclass, units = 'mm', width = 190, height = 200)
rm('count.plot.sizeclass', 'legal.plot', 'sub.legal.plot', 'time.swim.dat.n',
'ten.min.mean.year')
##---------------------------------------------------------------------------##
## PLOT 2: Abundance Lineplot ####
act_dat <- time.swim.dat.final %>%
mutate(samp_period = ifelse(between(sampdate, as.Date('2021-01-01'), as.Date('2021-03-31'))|
between(sampdate, as.Date('2023-01-01'), as.Date('2023-03-31')), 'Pre',
ifelse(between(sampdate, as.Date('2023-04-01'), as.Date('2023-12-31')), 'Mid', 'Post')))
# Determine mean abalone abundance in each block, year and size class
ten.min.mean.year <- act_dat %>%
filter((!subblockno %in% c('28B', '28C') &
!blockno %in% c('13', '14', '21', '29', '30') &
!is.na(sizeclass_freq_10) &
sampyear <= samp.year) |
(sampyear == 2021 & blockno == '13') |
(sampyear == 2023 & blockno == '13' & samp_period == 'Mid')) %>%
group_by(blockno, site, diver, sampyear, time.elapsed, legal.size) %>%
summarise(ab.n = sum(sizeclass_freq_10)) %>%
group_by(blockno, sampyear, legal.size) %>%
summarise(mean.ab.n = mean(ab.n),
median.ab.n = median(ab.n),
std_err = sd(ab.n)/sqrt(n()))
# mutate(sampyear = factor(sampyear))
# Determine number of sites surveyed in each block, year and size class
time.swim.dat.n <- act_dat %>%
filter((!subblockno %in% c('28B', '28C') &
!blockno %in% c('13', '14', '21', '29', '30') &
!is.na(sizeclass_freq_10) &
sampyear <= samp.year) |
(sampyear == 2021 & blockno == '13') |
(sampyear == 2023 & blockno == '13' & samp_period == 'Mid')) %>%
group_by(sampyear, blockno, legal.size) %>%
summarise(n = n_distinct(site))
abundance_plot <- ten.min.mean.year %>%
filter(blockno != 13) %>%
ggplot(aes(x = sampyear, y = mean.ab.n, group = legal.size, colour = legal.size))+
geom_point(position = position_dodge(0.05))+
geom_line()+
geom_errorbar(aes(ymin = mean.ab.n - std_err, ymax = mean.ab.n + std_err), width = 0.2,
position = position_dodge(0.05))+
scale_colour_manual(values = c('red', 'blue'))+
theme_bw()+
ylab(bquote('Average count (abalone.10'*~min^-1*')'))+
xlab('Survey Year')+
ylim(0, 60)+
theme(legend.position = 'bottom',
legend.background = element_rect(fill = "white", colour = NA))+
guides(colour = guide_legend(title = "Size Class"))+
facet_wrap(. ~ blockno, ncol = 3)
abundance_trend_plot <- ten.min.mean.year %>%
# filter(legal.size == '>140 mm') %>%
filter(blockno != 13) %>%
ggplot(aes(x = sampyear, y = mean.ab.n, group = legal.size, colour = legal.size))+
geom_point(position = position_dodge(0.05))+
geom_smooth(method = 'lm', formula = y~x, se = T)+
stat_poly_eq(formula = y~x, aes(label = paste(..rr.label.., p.value.label, sep = "~~~")),
parse = TRUE, label.y = 0.95) +
scale_colour_manual(values = c('red', 'blue'))+
theme_bw()+
ylab(bquote('Average count (abalone.10'*~min^-1*')'))+
xlab('Survey Year')+
theme(legend.position = c(0.85, 0.35)
,legend.background = element_rect(fill = "white", colour = NA))+
guides(colour = guide_legend(title = "Size Class"))+
facet_wrap(. ~ blockno, ncol = 3)
setwd(ts.plots.folder)
ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_TenMinuteCount_LegalSubLegal_MeanLinePlot', '.pdf', sep = ''),
plot = abundance_plot, units = 'mm', width = 190, height = 200)
ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_TenMinuteCount_LegalSubLegal_MeanLinePlot', '.png', sep = ''),
plot = abundance_plot, units = 'mm', width = 190, height = 200)
# ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_TenMinuteCount_Legal_MeanTendPlot', '.pdf', sep = ''),
# plot = abundance_trend_plot, units = 'mm', width = 190, height = 200)
# ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_TenMinuteCount_Legal_MeanTendPlot', '.png', sep = ''),
# plot = abundance_trend_plot, units = 'mm', width = 190, height = 200)
##---------------------------------------------------------------------------##
## PLOT 3: Relative-Absolute Abundance ####
# Relative abundance to 2020 baselines and hypothetical percentage change.
# Determine mean abalone abundance in each block, year and size class
ten.min.mean.year <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C') &
!blockno %in% c('13', '14', '21', '29', '30') &
!is.na(sizeclass_freq_10)) %>%
group_by(blockno, site, diver, sampyear, time.elapsed, legal.size) %>%
summarise(ab.n = sum(sizeclass_freq_10)) %>%
group_by(blockno, sampyear, legal.size) %>%
summarise(mean.ab.n = mean(ab.n),
median.ab.n = median(ab.n),
std_err = sd(ab.n)/sqrt(n()))
# Extract basline abudance 2020 values
base_dat_2020 <- ten.min.mean.year %>%
filter(sampyear == 2020) %>%
dplyr::rename(mean_ab_n_2020 = 'mean.ab.n') %>%
ungroup() %>%
select(blockno, legal.size, mean_ab_n_2020)
# Re-join baseline data to all data
dat_base_year <- left_join(ten.min.mean.year, base_dat_2020)
# Relative and absolute difference
dat_diff <- dat_base_year %>%
mutate(rel_diff = (mean.ab.n - mean_ab_n_2020) / mean_ab_n_2020,
abs_diff = mean.ab.n - mean_ab_n_2020)
# Create dataframe of hypothetical relative change scenarios
dat_hypo_rel <- data.frame(sampyear = c(2020, 2021, 2022, 2023, 2024),
hypo_05 = format(c(0, 0.05, 0.05 * 1.05, 0.05 * 1.05^2, 0.05 * 1.05^3), scientific = F),
hypo_10 = format(c(0, 0.10, 0.10 * 1.10, 0.10 * 1.10^2, 0.10 * 1.10^3), scientific = F),
hypo_15 = format(c(0, 0.15, 0.15 * 1.15, 0.15 * 1.15^2, 0.15 * 1.15^3), scientific = F),
hypo_20 = format(c(0, 0.20, 0.20 * 1.20, 0.20 * 1.20^2, 0.20 * 1.20^3), scientific = F),
hypo_25 = format(c(0, 0.25, 0.25 * 1.25, 0.25 * 1.25^2, 0.25 * 1.25^3), scientific = F)) %>%
pivot_longer(cols = starts_with('hypo_'),
names_to = c('hypo', 'rate'),
names_sep = '_',
values_to = 'hypo_val',
values_drop_na = T) %>%
select(sampyear, rate, hypo_val)
# Create dataframe of absolute change hypothetical scenarios.
dat_hypo_abs <- dat_base_year %>%
filter(sampyear == 2020) %>%
mutate(hypo_05_2020 = 0,
hypo_05_2021 = (mean_ab_n_2020 * 1.05) - mean_ab_n_2020,
hypo_05_2022 = (mean_ab_n_2020 * 1.05^2) - mean_ab_n_2020,
hypo_05_2023 = (mean_ab_n_2020 * 1.05^3) - mean_ab_n_2020,
hypo_05_2024 = (mean_ab_n_2020 * 1.05^4) - mean_ab_n_2020,
hypo_10_2020 = 0,
hypo_10_2021 = (mean_ab_n_2020 * 1.10) - mean_ab_n_2020,
hypo_10_2022 = (mean_ab_n_2020 * 1.10^2) - mean_ab_n_2020,
hypo_10_2023 = (mean_ab_n_2020 * 1.10^3) - mean_ab_n_2020,
hypo_10_2024 = (mean_ab_n_2020 * 1.10^4) - mean_ab_n_2020,
hypo_15_2020 = 0,
hypo_15_2021 = (mean_ab_n_2020 * 1.15) - mean_ab_n_2020,
hypo_15_2022 = (mean_ab_n_2020 * 1.15^2) - mean_ab_n_2020,
hypo_15_2023 = (mean_ab_n_2020 * 1.15^3) - mean_ab_n_2020,
hypo_15_2024 = (mean_ab_n_2020 * 1.15^4) - mean_ab_n_2020,
hypo_20_2020 = 0,
hypo_20_2021 = (mean_ab_n_2020 * 1.20) - mean_ab_n_2020,
hypo_20_2022 = (mean_ab_n_2020 * 1.20^2) - mean_ab_n_2020,
hypo_20_2023 = (mean_ab_n_2020 * 1.20^3) - mean_ab_n_2020,
hypo_20_2024 = (mean_ab_n_2020 * 1.20^4) - mean_ab_n_2020,
hypo_25_2020 = 0,
hypo_25_2021 = (mean_ab_n_2020 * 1.25) - mean_ab_n_2020,
hypo_25_2022 = (mean_ab_n_2020 * 1.25^2) - mean_ab_n_2020,
hypo_25_2023 = (mean_ab_n_2020 * 1.25^3) - mean_ab_n_2020,
hypo_25_2024 = (mean_ab_n_2020 * 1.25^4) - mean_ab_n_2020) %>%
pivot_longer(cols = starts_with('hypo_'),
names_to = c('hypo', 'rate', 'yr'),
names_sep = '_',
values_to = 'hypo_val',
values_drop_na = T) %>%
select(hypo, legal.size, rate, yr, hypo_val)
#Relative change plot
rel_change_plot <- dat_diff %>%
ggplot()+
geom_point(aes(x = sampyear, y = rel_diff, group = legal.size, colour = legal.size), position = position_dodge(0.05))+
geom_line(aes(x = sampyear, y = rel_diff, group = legal.size, colour = legal.size))+
geom_hline(yintercept = 0, linetype = 'dotted', colour = 'red', size = 0.3)+
geom_line(data = dat_hypo_rel %>% filter(rate == '05'), aes(x = as.numeric(sampyear), y = as.numeric(hypo_val), colour = rate), linetype = 'dashed', size = 0.3)+
geom_line(data = dat_hypo_rel %>% filter(rate == '10'), aes(x = as.numeric(sampyear), y = as.numeric(hypo_val), colour = rate), linetype = 'dashed', size = 0.3)+
geom_line(data = dat_hypo_rel %>% filter(rate == '15'), aes(x = as.numeric(sampyear), y = as.numeric(hypo_val), colour = rate), linetype = 'dashed', size = 0.3)+
geom_line(data = dat_hypo_rel %>% filter(rate == '20'), aes(x = as.numeric(sampyear), y = as.numeric(hypo_val), colour = rate), linetype = 'dashed', size = 0.3)+
scale_colour_manual(values = c('red', 'blue', "#00AFBB", "#E7B800", "#FC4E07", "#52854C"),
labels = c('<140 mm', '>140 mm', '5%', '10%', '15%', '20%'),
name = '')+
theme_bw()+
ylab(bquote('Relative change in abundance'))+
xlab('Survey Year')+
theme(legend.position = 'bottom')+
# theme(legend.position = c(0.9, 0.3)
# ,legend.background = element_rect(fill = NA, colour = NA))+
guides(colour = guide_legend(nrow =1))+
# ylim(-1, 1)+
facet_wrap(. ~ blockno, ncol = 3)
#Absolute change plot
abs_change_plot <- dat_diff %>%
ggplot()+
geom_point(aes(x = sampyear, y = abs_diff, group = legal.size, colour = legal.size), position = position_dodge(0.05))+
geom_line(aes(x = sampyear, y = abs_diff, group = legal.size, colour = legal.size))+
geom_hline(yintercept = 0, linetype = 'dotted', colour = 'red', size = 0.3)+
geom_line(data = dat_hypo_abs %>% filter(rate == '05' & legal.size == '<140 mm'), aes(x = as.numeric(yr), y = hypo_val, colour = rate), linetype = 'dashed', size = 0.3)+
geom_line(data = dat_hypo_abs %>% filter(rate == '10' & legal.size == '<140 mm'), aes(x = as.numeric(yr), y = hypo_val, colour = rate), linetype = 'dashed', size = 0.3)+
geom_line(data = dat_hypo_abs %>% filter(rate == '15' & legal.size == '<140 mm'), aes(x = as.numeric(yr), y = hypo_val, colour = rate), linetype = 'dashed', size = 0.3)+
geom_line(data = dat_hypo_abs %>% filter(rate == '20' & legal.size == '<140 mm'), aes(x = as.numeric(yr), y = hypo_val, colour = rate), linetype = 'dashed', size = 0.3)+
scale_colour_manual(values = c('red', 'blue', "#00AFBB", "#E7B800", "#FC4E07", "#52854C"),
labels = c('<140 mm', '>140 mm', '5%', '10%', '15%', '20%'),
name = '')+
# scale_colour_manual(values = c('red', 'blue'),
# labels = c('<140 mm', '>140 mm'),
# name = 'Size Class')+
theme_bw()+
ylab(bquote('Absolute change in abundance'))+
xlab('Survey Year')+
theme(legend.position = 'bottom')+
# theme(legend.position = c(0.9, 0.3)
# ,legend.background = element_rect(fill = NA, colour = NA))+
guides(colour = guide_legend(nrow =1))+
# ylim(-30, 100)+
facet_wrap(. ~ blockno, ncol = 3)
setwd(ts.plots.folder)
ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_TenMinuteCount_RelativeChangePlot', '.pdf', sep = ''),
plot = rel_change_plot, units = 'mm', width = 190, height = 200)
ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_TenMinuteCount_RelativeChangePlot', '.png', sep = ''),
plot = rel_change_plot, units = 'mm', width = 190, height = 200)
ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_TenMinuteCount_AbsoluteChangePlot', '.pdf', sep = ''),
plot = abs_change_plot, units = 'mm', width = 190, height = 200)
ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_TenMinuteCount_AbsoluteChangePlot', '.png', sep = ''),
plot = abs_change_plot, units = 'mm', width = 190, height = 200)
##---------------------------------------------------------------------------##
## PLOT 4: Reference Abundance ####
# Reference site relative abundance to 2020 baselines
# Determine mean abalone abundance in each block, year and size class
ten.min.mean.year <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C') &
!blockno %in% c('13', '14', '21', '29', '30') &
!is.na(sizeclass_freq_10) &
ref_site == 1) %>%
group_by(blockno, site, diver, sampyear, time.elapsed, legal.size) %>%
summarise(ab.n = sum(sizeclass_freq_10)) %>%
group_by(blockno, sampyear, legal.size) %>%
summarise(mean.ab.n = mean(ab.n),
median.ab.n = median(ab.n),
std_err = sd(ab.n)/sqrt(n()))
abundance_plot <- ten.min.mean.year %>%
filter(blockno != 13) %>%
ggplot(aes(x = sampyear, y = mean.ab.n, group = legal.size, colour = legal.size))+
geom_point(position = position_dodge(0.05))+
geom_line()+
geom_errorbar(aes(ymin = mean.ab.n - std_err, ymax = mean.ab.n + std_err), width = 0.2,
position = position_dodge(0.05))+
scale_colour_manual(values = c('red', 'blue'))+
theme_bw()+
ylab(bquote('Average count (abalone.10'*~min^-1*')'))+
xlab('Survey Year')+
ylim(0, 60)+
theme(legend.position = 'bottom',
legend.background = element_rect(fill = "white", colour = NA))+
guides(colour = guide_legend(title = "Size Class"))+
facet_wrap(. ~ blockno, ncol = 3)
# Extract basline 2020 values
base_dat_2020 <- ten.min.mean.year %>%
filter(sampyear == 2020) %>%
dplyr::rename(mean_ab_n_2020 = 'mean.ab.n') %>%
ungroup() %>%
select(blockno, legal.size, mean_ab_n_2020)
# Re-join baseline data to all data
dat_base_year <- left_join(ten.min.mean.year, base_dat_2020)
# Relative difference
dat_diff <- dat_base_year %>%
mutate(rel_diff = (mean.ab.n - mean_ab_n_2020) / mean_ab_n_2020,
abs_diff = abs(mean.ab.n - mean_ab_n_2020))
#Relative plot
rel_change_plot <- dat_diff %>%
ggplot(aes(x = sampyear, y = rel_diff, group = legal.size, colour = legal.size))+
geom_point(position = position_dodge(0.05))+
geom_line()+
scale_colour_manual(values = c('red', 'blue'))+
geom_hline(yintercept = 0, linetype = 'dashed', colour = 'red', size = 0.3)+
theme_bw()+
ylab(bquote('Relative change in abundance'))+
xlab('Survey Year')+
theme(legend.position = 'bottom')+
# theme(legend.position = c(0.9, 0.3)
# ,legend.background = element_rect(fill = NA, colour = NA))+
guides(colour = guide_legend(title = "Size Class"))+
ylim(-1, 4)+
facet_wrap(. ~ blockno, ncol = 3)
setwd(ts.plots.folder)
ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_TenMinuteCount_RelativeChangePlot_ReferenceSites', '.pdf', sep = ''),
plot = rel_change_plot, units = 'mm', width = 190, height = 200)
ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_TenMinuteCount_RelativeChangePlot_ReferenceSites', '.png', sep = ''),
plot = rel_change_plot, units = 'mm', width = 190, height = 200)
ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_TenMinuteCount_LegalSubLegal_MeanLinePlot_ReferenceSites', '.pdf', sep = ''),
plot = abundance_plot, units = 'mm', width = 190, height = 200)
ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_TenMinuteCount_LegalSubLegal_MeanLinePlot_ReferenceSites', '.png', sep = ''),
plot = abundance_plot, units = 'mm', width = 190, height = 200)
##---------------------------------------------------------------------------##
# Reference Sites - ANOVA
# Determine mean abalone abundance in each block, year and size class
ten.min.mean.year <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C') &
!blockno %in% c('13', '14', '21', '29', '30') &
!is.na(sizeclass_freq_10) &
ref_site == 1) %>%
group_by(blockno, site, diver, sampyear, legal.size) %>%
summarise(ab.n = sum(sizeclass_freq_10)) %>%
group_by(blockno, site, sampyear, legal.size) %>%
summarise(mean.ab.n = mean(ab.n),
median.ab.n = median(ab.n),
std_err = sd(ab.n)/sqrt(n())) %>%
filter(legal.size == '<140 mm' & blockno == '23')
mean_aov <- aov(mean.ab.n ~ as.factor(sampyear), data = ten.min.mean.year)
summary(mean_aov)
TukeyHSD(mean_aov)
plot(mean_aov, 1)
car::leveneTest(mean.ab.n ~ as.factor(sampyear), data = ten.min.mean.year)
kruskal.test(mean.ab.n ~ as.factor(sampyear), data = ten.min.mean.year)
##---------------------------------------------------------------------------##
## PLOT 5: Reference Abundance Criteria ####
# Relative change in abundance at referenc sites between 2020 and proceeding years
# including a colour coding trend to determine if the majority (75%) of sites are
# showing signs of improvement relative to 2020 (e.g. abundance increasing)
# Criteria include:
# 1. Green = two years of consecutive increases above 2020 baseline (current + previous year)
# 2. Red = two consecutive years of decline (current + previous year)
# = current year decline but previous year increase or no change
# 3. Amber = current year increase or no change but previous year decline
# Determine mean abalone abundance in each block, year and size class
site_mean_ref <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C') &
!blockno %in% c('13', '14', '21', '29', '30') &
!is.na(sizeclass_freq_10) &
ref_site == 1) %>%
group_by(blockno, site, diver, sampyear, time.elapsed, legal.size) %>%
summarise(ab.n = sum(sizeclass_freq_10)) %>%
group_by(blockno, site, sampyear, legal.size) %>%
summarise(mean.ab.n = mean(ab.n))
# Create long dataframe
site_mean_ref_long <- site_mean_ref %>%
spread(key = sampyear, value = mean.ab.n)
# Classify abundance trends
site_mean_dat <- site_mean_ref_long %>%
mutate(rel_2021 = ((`2021` -`2020`)/ `2020`),
rel_2022 = ((`2022` -`2020`)/ `2020`),
rel_2023 = ((`2023` -`2020`)/ `2020`),
rel_2024 = ((`2024` -`2020`)/ `2020`),
plot_col = case_when(rel_2023 < 0 & rel_2024 < 0 ~ 'red',
rel_2023 >= 0 & rel_2024 < 0 ~ 'red',
rel_2023 <= 0 & rel_2024 >= 0 ~ 'orange',
rel_2023 >= 0 & rel_2024 >= 0 ~ 'darkgreen',
is.na(rel_2023) | rel_2023 == 0 & rel_2024 >= 0 ~ 'orange',
is.na(rel_2023) | rel_2023 == 0 & rel_2024 < 0 ~ 'red'))
# Determine overall if 75% of sites within block meet improving criteria (i.e. green)
block_crit_dat <- site_mean_dat %>%
group_by(blockno, legal.size, plot_col) %>%
summarise(n = n()) %>%
ungroup() %>%
complete(blockno, legal.size, plot_col, fill = list(n = 0)) %>%
filter(plot_col == 'darkgreen') %>%
mutate(status_val = n/15,
status_col = case_when(status_val >= 0.75 ~ 'darkgreen',
status_val >= 0.5 & status_val < 0.75 ~ 'orange',
status_val < 0.5 ~ 'red'),
status_condition = case_when(status_val >= 0.75 ~ 'PASS',
status_val >= 0.5 & status_val < 0.75 ~ 'ASSESS',
status_val < 0.5 ~ 'FAIL'),
x = 12, y = -0.8)
ref_rel_plot <- site_mean_dat %>%
filter(legal.size == '>140 mm' &
!is.na(rel_2023) & !is.na(rel_2024) &
!is.na(plot_col)) %>%
ggplot()+
geom_bar(aes(x = site, y = rel_2023, group = blockno, fill = plot_col), stat='identity')+
scale_fill_manual(values = c('red' = 'red',
'orange' = 'orange',
'darkgreen' = 'darkgreen'),
labels = c('2 yr Increase',
'1 yr Increase',
'Decline'))+
# geom_rect(data = df_4 %>% filter(legal.size == '>140 mm'), aes(fill = status_col),xmin = -Inf, xmax = Inf,
# ymin = -Inf, ymax = Inf, alpha = 0.3) +
facet_wrap(~blockno, scales = 'free', drop = F)+
theme_bw()+
coord_cartesian(ylim = c(-1, 1))+
theme(axis.text.x = element_text(angle = 90, vjust = 0.5))+
theme(legend.position = 'bottom',
legend.title = element_blank())+
xlab('Site')+
ylab(bquote('Relative change in abundance'))
# geom_point(data = df_4 %>% filter(legal.size == '>140 mm'), aes(x = x, y = y))+
# geom_text(data = df_4 %>% filter(legal.size == '>140 mm'), aes(x = x, y = y,
# label = status_condition))
setwd(ts.plots.folder)
ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_TenMinuteCount_Legal_RelativeChangePlot_ReferenceSites_2022_2023', '.pdf', sep = ''),
plot = ref_rel_plot, units = 'mm', width = 190, height = 200)
ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_TenMinuteCount_Legal_RelativeChangePlot_ReferenceSites_2022_2023', '.png', sep = ''),
plot = ref_rel_plot, units = 'mm', width = 190, height = 200)
##---------------------------------------------------------------------------##
# PLOT 6: Reference site deviation ####
# Determine mean abalone abundance for each site
ten.min.mean.year <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C') &
!blockno %in% c('13', '14', '21', '29', '30') &
!is.na(sizeclass_freq_10) &
ref_site == 1) %>%
group_by(blockno, site, diver, sampyear, legal.size) %>%
summarise(ab.n = sum(sizeclass_freq_10)) %>%
group_by(blockno, site, sampyear, legal.size) %>%
summarise(mean.ab.n = mean(ab.n))
# Extract basline 2020 site values
base_dat_2020 <- ten.min.mean.year %>%
filter(sampyear == 2020) %>%
dplyr::rename(mean_ab_n_2020 = 'mean.ab.n') %>%
ungroup() %>%
select(blockno, site, legal.size, mean_ab_n_2020)
# Re-join 2020 site baseline to original data
dat_base_year <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C') &
!blockno %in% c('13', '14', '21', '29', '30') &
!is.na(sizeclass_freq_10) &
ref_site == 1) %>%
group_by(blockno, site, diver, sampyear, legal.size) %>%
summarise(ab.n = sum(sizeclass_freq_10)) %>%
left_join(base_dat_2020, .)
# Calculate deviation between 2020 mean site baseline and original site counts
dat_dev <- dat_base_year %>%
mutate(dist_mean = abs(ab.n - mean_ab_n_2020))
# Calculate mean absolute deviation for site
mean_dat_dev <- dat_dev %>%
group_by(blockno, site, sampyear, legal.size) %>%
summarise(mean_dev = mean(dist_mean),
std_err = sd(dist_mean)/sqrt(n()))
# Reference site mean deviation plot by chosen block
block_no <- '22'
mean_dat_dev %>%
filter(blockno == block_no) %>%
ggplot(aes(x = sampyear, y = mean_dev, group = legal.size, colour = legal.size))+
geom_point(position = position_dodge(0.05))+
geom_line()+
geom_errorbar(aes(ymin = mean_dev - std_err, ymax = mean_dev + std_err), width = 0.2,
position = position_dodge(0.05))+
scale_colour_manual(values = c('red', 'blue'))+
theme_bw()+
ylab(bquote('Mean absolute deviation'))+
xlab('Survey Year')+
theme(legend.position = 'bottom')+
# theme(legend.position = c(0.9, 0.3)
# ,legend.background = element_rect(fill = NA, colour = NA))+
guides(colour = guide_legend(title = "Size Class"))+
# ylim(-1, 4)+
facet_wrap(. ~ site)
# setwd(ts.plots.folder)
# ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_TenMinuteCount_Legal_RelativeChangePlot_ReferenceSites', '.pdf', sep = ''),
# plot = rel_change_plot, units = 'mm', width = 190, height = 200)
# ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_TenMinuteCount_Legal_RelativeChangePlot_ReferenceSites', '.png', sep = ''),
# plot = rel_change_plot, units = 'mm', width = 190, height = 200)
##---------------------------------------------------------------------------##
# PLOT 7: Reference block deviation ####
# Determine mean abalone abundance for each site
ten.min.mean.year <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C') &
!blockno %in% c('13', '14', '21', '29', '30') &
!is.na(sizeclass_freq_10) &
ref_site == 1) %>%
group_by(blockno, site, diver, sampyear, legal.size) %>%
summarise(ab.n = sum(sizeclass_freq_10)) %>%
group_by(blockno, site, sampyear, legal.size) %>%
summarise(mean.ab.n = mean(ab.n))
# Extract basline 2020 site values
base_dat_2020 <- ten.min.mean.year %>%
filter(sampyear == 2020) %>%
dplyr::rename(mean_ab_n_2020 = 'mean.ab.n') %>%
ungroup() %>%
select(blockno, site, legal.size, mean_ab_n_2020)
# Re-join 2020 site baseline to original data
dat_base_year <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C') &
!blockno %in% c('13', '14', '21', '29', '30') &
!is.na(sizeclass_freq_10) &
ref_site == 1) %>%
group_by(blockno, site, diver, sampyear, legal.size) %>%
summarise(ab.n = sum(sizeclass_freq_10)) %>%
left_join(base_dat_2020, .)
# Calculate deviation between 2020 mean site baseline and original site counts
dat_dev <- dat_base_year %>%
mutate(dist_mean = abs(ab.n - mean_ab_n_2020))
# Calculate mean absolute deviation for site
mean_dat_dev <- dat_dev %>%
group_by(blockno, sampyear, legal.size) %>%
summarise(mean_dev = mean(dist_mean),
std_err = sd(dist_mean)/sqrt(n()))
# Reference site mean deviation plot by chosen block
mean_dev_block_plot <- mean_dat_dev %>%
ggplot(aes(x = sampyear, y = mean_dev, group = legal.size, colour = legal.size))+
geom_point(position = position_dodge(0.05))+
geom_line()+
geom_errorbar(aes(ymin = mean_dev - std_err, ymax = mean_dev + std_err), width = 0.2,
position = position_dodge(0.05))+
scale_colour_manual(values = c('red', 'blue'))+
theme_bw()+
ylab(bquote('Mean absolute deviation'))+
xlab('Survey Year')+
theme(legend.position = 'bottom')+
# theme(legend.position = c(0.9, 0.3)
# ,legend.background = element_rect(fill = NA, colour = NA))+
guides(colour = guide_legend(title = "Size Class"))+
# ylim(-1, 4)+
facet_wrap(. ~ blockno)
setwd(ts.plots.folder)
ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_TenMinuteCount_DeviationPlot_Block_ReferenceSites', '.pdf', sep = ''),
plot = mean_dev_block_plot, units = 'mm', width = 190, height = 200)
ggsave(filename = paste('TimedSwimSurvey_', samp.year, '_TenMinuteCount_DeviationPlot_Block_ReferenceSites', '.png', sep = ''),
plot = mean_dev_block_plot, units = 'mm', width = 190, height = 200)
##---------------------------------------------------------------------------##
## PLOT Abundance Years: Including mid-season 2023 Actaeons
df_1 <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C') &
!blockno %in% c('13', '14', '21', '29', '30') &
!is.na(sizeclass_freq_10) &
sampyear <= samp.year) %>%
group_by(blockno, site, diver, sampyear, time.elapsed, legal.size) %>%
summarise(ab.n = sum(sizeclass_freq_10)) %>%
group_by(blockno, sampyear, legal.size) %>%
summarise(mean.ab.n = mean(ab.n),
median.ab.n = median(ab.n))
df_2 <- time.swim.dat.final %>%
filter(blockno == '13' &
between(sampdate, as.Date('2023-04-01'), as.Date('2023-12-31')) &
!is.na(sizeclass_freq_10) |
blockno == '13' &
sampdate <= as.Date('2022-01-01') &
!is.na(sizeclass_freq_10)) %>%
group_by(blockno, site, diver, sampyear, time.elapsed, legal.size) %>%
summarise(ab.n = sum(sizeclass_freq_10)) %>%
group_by(blockno, sampyear, legal.size) %>%
summarise(mean.ab.n = mean(ab.n),
median.ab.n = median(ab.n))
df_3 <- bind_rows(df_1, df_2)
# Determine number of sites surveyed in each block, year and size class
df_4 <- time.swim.dat.final %>%
filter(!subblockno %in% c('28B', '28C') &
!blockno %in% c('13', '14', '21', '29', '30') &
sampyear <= samp.year) %>%
group_by(sampyear, blockno, legal.size) %>%
summarise(n = n_distinct(site))
df_5 <- time.swim.dat.final %>%
filter(blockno == '13' &
between(sampdate, as.Date('2023-04-01'), as.Date('2023-12-31')) &
!is.na(sizeclass_freq_10) |
blockno == '13' &
sampdate <= as.Date('2022-01-01') &
!is.na(sizeclass_freq_10)) %>%
group_by(sampyear, blockno, legal.size) %>%
summarise(n = n_distinct(site))