-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFIS.rmd
1265 lines (1028 loc) · 54.2 KB
/
FIS.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: "IMAS Abalone Fishery Independant Survey data"
author: "Jaime McAllister and Craig Mundy"
date: "August 2018"
output:
pdf_document:
fig_caption: yes
keep_tex: yes
number_sections: yes
html_document:
df_print: paged
word_document:
fig_height: 8
fig_width: 8
monofont: Consolas
mathfont: Iwona
mainfont: Verdana
---
```{r setup, include=FALSE}
## load library packages
knitr::opts_chunk$set(echo = TRUE)
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)
## load custom functions
source("C:/GitCode/AbResearch/getSeason.r")
source("C:/GitCode/AbResearch/errorUpper2.r")
source("C:/GitCode/AbResearch/stderr.r")
```
# IMAS Abalone Fishery Independant Surveys
Historically there has been a paucity of fishery independent abundance and population size structure
information collected in the Tasmanian Abalone Fishery. Primarily this has been a consequence of the
geographic scale of the fishery relative to available field resources, along with the challenges of obtaining
representative samples where abundance is patchy on multiple spatial scales from meters to
kilometres. Juvenile abalone below the size at reproductive maturity are entirely cryptic. The size at
emergence from crypsis in Tasmania is around the same size as the LML, and are therefore difficult
to capture using traditional FI survey techniques. These key life history traits have subsequently
created significant challenges in identifying potential changes in stock levels. Monitoring of cryptic
abalone (2+ to 4+ year classes) could provide an early warning of a potential reduction in future fishable
biomass. From the early 2000s effort has been applied to developing suitable survey methods
quantifying abundance for the Tasmanian abalone fishery, with robust sampling methods developed
during FRDC projects (Mundy et al., 2006, 2018). Since 2015 IMAS have conducted a pilot program
to collect fishery independent data for cryptic (ARMs) and emergent abalone (LEGs).
## Monitoring of juvenile abundance with Abalone Recruitment Modules (ARM)
Juvenile abalone are currently monitored using an artificial habitat or abalone recruitment module (ARM) developed by IMAS which consists of a flat plastic disc secured to the reef to create cryptic space underneath. The Tasmanian ARM design provides data on cryptic blacklip abalone in a size range (6 mm - 100 mm). Strings of 20 ARMs per site are currently maintained to account for high local scale variation in recruit abundance. Initial trials suggest this is the minimum number of ARMs required per site to detect a magnitude of 80-100% change in abundance. Paired sites separated by approximately 50 m are established to examine local scale variation in juvenile abundance.
ARMs are deployed at six sites along the east coast of Tasmania (i.e. n = 12);
* The Gardens (GAR)
* Seymour Point (SEY)
* Betsey Island (BET)
* George III Rock (GEO)
* Black Reef boulder (BRB)
* Black Reef slab (BRS)
Where possible sites are surveyed seasonally (Summer, Winter, Spring), and all abalone found under the ARM are measured to the nearest millimetre. Seasonal data have been collected since 2015 and IMAS continue to assess the performance and suitability of ARMs as a stock recruitment indicator. Data presented in the 2018 stock assessment are useful as a secondary indicator only and are therefore not currently used for direct input to the stock assessment.
## Length Evaluation and Growth surveys (LEGS) of emergent abalone
Permanent Length Evaluation and Growth survey (LEGs) sites have also been established at the same locations where each ARM string (n = 12) is deployed to establish a time-series of abalone abundance and size structure as a relative measure of stock performance. Where possible LEG sites have also been established to span the ARM strings to examine stock-recruitment relationships. The design uses a 60 m long baseline transect marked by permanent SS eye bolts, with ten replicate 15 m x 1 m belt transects randomly located along the baseline. Randomised numbers (0 m to 60 m in 2.5 m increments) are used to determine the start position of the transect along the baseline and a randomised binary value (left/right) determines the direction of each 15 m belt transect perpendicular to the baseline. Sampling is non-destructive within the belt, and all abalone observed within the belt are measured to the nearest millimetre. Surveys are normally conducted on the same day as the ARMs are surveyed whenever possible.
LEGS are established at the six ARM sites plus two additional sites on the Tasman Peninsula:
* The Gardens (GAR)
* Seymour Point (SEY)
* Munroes Bite (MUN)
* The Thumbs (THU)
* Betsey Island (BET)
* George III Rock (GEO)
* Black Reef boulder (BRB)
* Black Reef slab (BRS)
# ARM and LEG data
The ARM and LEG data are currently entered seperate Microsoft Excel files for each survey method with seperate sheets for each site. Data have been stored in these files in preparation for transfer to a new database which is being developed and are currentlylocated on the IMAS R:drive.
## LEG data
LEG data is loaded from one Excel file containing seperate sheets for each site.
```{r load leg data, echo=FALSE}
## Load data
xl_data <- 'R:/TAFI/TAFI_MRL_Sections/Abalone/Section Shared/Abalone_databases/Data/Data for Transfer/2018/Ab_pop_bio_Lenght_density_2016.xlsx'
```
### Compile and clean LEG data
LEG data is first compiled into a single dataframe which enables some cleaning of data to occur prior to being seperated into abundance and size structure data for analysis.
```{r compile and clean leg data, warning=FALSE, message=FALSE}
## identify sheets in excel workbook
tab_names <- excel_sheets(path = xl_data)
## create list from seperate sheets
list_all <- lapply(tab_names, function(x) read_excel(path = xl_data, sheet = x))
## create dataframe from seperate sheets
legs.df <- rbindlist(list_all, fill = T)
## convert varible names to lower case and compile data for estimates and comments
## columns, removing additional columns from the Excel import (i.e. each sheet contained
## different column names for these variables)
colnames(legs.df) <- tolower(colnames(legs.df))
names(legs.df) <- gsub('/', '', names(legs.df), fixed = T)
names(legs.df) <- gsub(' ', '', names(legs.df), fixed = T)
names(legs.df) <- gsub('=', '', names(legs.df), fixed = T)
names(legs.df) <- gsub('comments', 'comments.1', names(legs.df), fixed = T)
names(legs.df) <- gsub('...8', 'comments.2', names(legs.df), fixed = T)
names(legs.df) <- gsub('...9', 'comments.3', names(legs.df), fixed = T)
names(legs.df) <- gsub('...10', 'comments.4', names(legs.df), fixed = T)
names(legs.df) <- gsub('eestimate', 'comments.5', names(legs.df), fixed = T)
colnames(legs.df) <- make.unique(names(legs.df))
legs.df <- dplyr::rename(legs.df, survdate = date)
legs.df <- dplyr::rename(legs.df, sllength = length)
legs.df$string <- as.factor(legs.df$string)
legs.df.2 <- legs.df %>%
select(-comments.3) %>%
unite('all_comments', 'comments.1','comments.2', 'comments.4',
'comments.5', sep = ',') %>%
mutate(all_comments = gsub('NA', '', all_comments),
all_comments = gsub(',', '', all_comments),
all_comments = gsub('^$', NA, all_comments)) %>%
mutate(estimate.2 = estimate) %>%
mutate(estimate = if_else(is.na(all_comments) & estimate.2 == 'E', estimate.2,
if_else(all_comments == 'E',
all_comments, NA_character_))) %>%
mutate(comments = if_else(is.na(estimate), all_comments, NA_character_)) %>%
select(-c(estimate.2, all_comments)) %>%
as.data.frame()
## remove any characters or obvious erroes from shell length (e.g. where 'estimate (E)' or 0 has been entered in the raw data)
str(legs.df.2$sllength) #check
legs.df.2 <- legs.df.2 %>%
mutate(estimate = if_else(grepl('E', sllength), 'E', estimate),
sllength = as.numeric(gsub('E', '', sllength))) %>%
filter(sllength != 0)
# str(legs.df.2$sllength) #check
## remove data with no site name or shell length
legs.df.2 <- filter(legs.df.2, !is.na(site))
legs.df.2 <- filter(legs.df.2, !is.na(sllength))
## remove characters from site names and rename sites to a three letter acronym
# unique(bigabs$site)
legs.df.2$site <- gsub(' ', '', legs.df.2$site)
legs.df.2$site <- gsub('_', '', legs.df.2$site)
legs.df.2$site <- gsub('Telopea', 'TEL', legs.df.2$site)
legs.df.2$site <- gsub('SP', 'SEY', legs.df.2$site)
legs.df.2$site <- gsub('\\bT\\b', 'THU', legs.df.2$site)
legs.df.2$site <- gsub('BI', 'BET', legs.df.2$site)
legs.df.2$site <- gsub('TG', 'GAR', legs.df.2$site)
legs.df.2$site <- gsub('GIII', 'GEO', legs.df.2$site)
legs.df.2$site <- gsub('MB', 'MUN', legs.df.2$site)
legs.df.2$site <- gsub('MP', 'INN', legs.df.2$site)
legs.df.2$site <- gsub('LB', 'LOU', legs.df.2$site)
legs.df.2$site <- gsub('OB', 'OUT', legs.df.2$site)
## rename string names from earlier sampling periods
# table(legs.df.2$site, legs.df.2$string)
legs.df.2$string <- gsub( "Kar", "1", legs.df.2$string )
legs.df.2$string <- gsub( "Juv", "2", legs.df.2$string )
legs.df.2$string <- gsub( "N", "1", legs.df.2$string )
legs.df.2$string <- gsub( "S", "2", legs.df.2$string )
legs.df.2$string <- gsub( "North", "1", legs.df.2$string )
legs.df.2$string <- gsub( "South", "2", legs.df.2$string )
## rename east and west transect directions
# unique(legs.df.2$eastwest)
legs.df.2$eastwest <- gsub('w', 'W', legs.df.2$eastwest)
legs.df.2$eastwest <- gsub('N', 'E', legs.df.2$eastwest)
legs.df.2$eastwest <- gsub('S', 'W', legs.df.2$eastwest)
legs.df.2$eastwest <- gsub('L', 'W', legs.df.2$eastwest)
legs.df.2$eastwest <- gsub('R', 'E', legs.df.2$eastwest)
## add unique identifier for each measurement
legs.df.2$survindex <- as.factor(paste(legs.df.2$site, legs.df.2$survdate, legs.df.2$string,
legs.df.2$transect, sep="_"))
```
#### LEG density dataframe
To generate density estimates for LEG data, individual length data first need to be converted to counts then density.
```{r leg count data}
## Filter for all abalone
legs.dat <- legs.df.2 %>%
group_by(survindex) %>%
summarise(ab_n = n()) %>% #as.data.frame()
complete(survindex, fill = list(ab_n = 0)) %>%
as.data.frame()
## calculate abs per square metre
legs.dat$absm <- legs.dat$ab_n / 15
## unpack survindex variables and create new dataframe
leg.counts <- data.frame(separate(legs.dat, survindex, sep = "_",
into = c("site", "survdate",
"string","transect"), convert = TRUE),
legs.dat$survindex, legs.dat$ab_n, legs.dat$absm)
## set string as a factor
leg.counts$string <- as.factor(leg.counts$string)
## construct date and season variables
leg.counts$survdate <- as.Date(strptime(leg.counts$survdate, "%Y-%m-%d"))
leg.counts$sampyear <- year(leg.counts$survdate)
leg.counts$season <- getSeason(leg.counts$survdate)
## recode autumn samples as summer
leg.counts$season <- gsub( "Autumn", "Summer", leg.counts$season)
## create year.season variable and arrange in order (i.e. summer, winter, spring)
leg.counts$season <- as.factor(leg.counts$season)
leg.counts$season <- ordered(leg.counts$season, levels=c("Summer","Winter","Spring"))
leg.counts$yr.season <- interaction(leg.counts$sampyear,leg.counts$season)
# sort(unique(leg.counts$yr.season))
leg.counts$yr.season <-
ordered(leg.counts$yr.season, levels = c("2015.Summer", "2015.Winter", "2015.Spring",
"2016.Summer", "2016.Winter", "2016.Spring",
"2017.Summer", "2017.Winter", "2017.Spring",
"2018.Summer", "2018.Winter", "2018.Spring",
"2019.Summer", '2019.Winter', '2019.Spring'))
## adjust misclassified seasons for The Gardens
pick <- which(leg.counts$site == "GAR")
leg.counts$yr.season[pick] <- gsub( "2015.Summer", "2015.Spring",
leg.counts$yr.season[pick])
leg.counts$yr.season <- droplevels(leg.counts$yr.season)
## save a copy of the R files
saveRDS(leg.counts, 'C:/CloudStor/R_Stuff/FIS/leg.counts.RDS')
```
**OPTION:** the dataframe can also be seperated into different size classes to generate plots of legal and sub-legal abalone counts (see LEG plots)
```{r legal and sub-legal leg counts 1, echo=FALSE}
## Filter for sub-legal abalone
legs.dat.sub <- legs.df.2 %>%
filter(sllength <= 137) %>%
# bigabdat <- bigabs %>%
group_by(survindex) %>%
summarise(ab_n = n()) %>% #as.data.frame()
complete(survindex, fill = list(ab_n = 0)) %>%
as.data.frame()
## Filter for legal abalone
legs.dat.leg <- legs.df.2 %>%
filter(sllength >= 138) %>%
group_by(survindex) %>%
summarise(ab_n = n()) %>% #as.data.frame()
complete(survindex, fill = list(ab_n = 0)) %>%
as.data.frame()
## Filter for sub-legal abalone <10 mm
legs.dat.sub.ten <- legs.df.2 %>%
filter(sllength >= 128 & sllength < 138) %>%
group_by(survindex) %>%
summarise(ab_n = n()) %>% #as.data.frame()
complete(survindex, fill = list(ab_n = 0)) %>%
as.data.frame()
## Filter for legal abalone +10 mm
legs.dat.leg.ten <- legs.df.2 %>%
filter(sllength >= 139 & sllength <= 148) %>%
group_by(survindex) %>%
summarise(ab_n = n()) %>% #as.data.frame()
complete(survindex, fill = list(ab_n = 0)) %>%
as.data.frame()
## join dataframes created above for survindex
legs.dat.join <- left_join(legs.dat.sub, legs.dat.leg, by = 'survindex') %>%
left_join(., legs.dat.sub.ten, by = 'survindex') %>%
left_join(., legs.dat.leg.ten, by = 'survindex') %>%
left_join(., legs.dat, by = 'survindex')
## rename variables to identify abcounts from each size class
legs.dat.join <- dplyr::rename(legs.dat.join, ab_n_leg = ab_n.y)
legs.dat.join <- dplyr::rename(legs.dat.join, ab_n_sub = ab_n.x)
legs.dat.join <- dplyr::rename(legs.dat.join, ab_n_sub_ten = ab_n.x.x)
legs.dat.join <- dplyr::rename(legs.dat.join, ab_n_leg_ten = ab_n.y.y)
## calculate abs per square metre for joint dataframe
legs.dat.join$absm_sub <- legs.dat.join$ab_n_sub /15
legs.dat.join$absm_leg <- legs.dat.join$ab_n_leg /15
legs.dat.join$absm_sub_ten <- legs.dat.join$ab_n_sub_ten /15
legs.dat.join$absm_leg_ten <- legs.dat.join$ab_n_leg_ten /15
legs.dat.join$absm <- legs.dat.join$ab_n /15
## unpack survindex variables and create new dataframe for the joint dataframe
legs.counts.join <- data.frame(separate(legs.dat.join, survindex, sep = "_",
into = c("site", "survdate", "string","transect"),
convert = TRUE),
legs.dat.join$survindex, legs.dat.join$ab_n,
legs.dat.join$absm, legs.dat.join$ab_n_sub,
legs.dat.join$absm_sub, legs.dat.join$ab_n_leg,
legs.dat.join$absm_leg,
legs.dat.join$ab_n_sub_ten, legs.dat.join$absm_sub_ten,
legs.dat.join$ab_n_leg_ten, legs.dat.join$absm_leg_ten)
## set string as a factor
legs.counts.join$string <- as.factor(legs.counts.join$string)
## construct date and season variables
legs.counts.join$survdate <- as.Date(strptime(legs.counts.join$survdate, "%Y-%m-%d"))
legs.counts.join$sampyear <- year(legs.counts.join$survdate)
legs.counts.join$season <- getSeason(legs.counts.join$survdate)
## recode autumn samples as summer
legs.counts.join$season <- gsub( "Autumn", "Summer", legs.counts.join$season)
## create year.season variable and arrange in order (i.e. summer, winter, spring)
legs.counts.join$season <- as.factor(legs.counts.join$season)
legs.counts.join$season <- ordered(legs.counts.join$season,
levels=c("Summer","Winter","Spring"))
legs.counts.join$yr.season <- interaction(legs.counts.join$sampyear,
legs.counts.join$season)
# unique(legs.counts.join$yr.season)
legs.counts.join$yr.season <-
ordered(legs.counts.join$yr.season,
levels = c("2015.Summer", "2015.Winter", "2015.Spring",
"2016.Summer", "2016.Winter", "2016.Spring",
"2017.Summer", "2017.Winter", "2017.Spring",
"2018.Summer", "2018.Winter", "2018.Spring",
"2019.Summer", '2019.Winter', '2019.Spring'))
## adjust misclassified seasons
pick <- which(legs.counts.join$site == "GAR")
legs.counts.join$yr.season[pick] <- gsub( "2015.Summer", "2015.Spring",
legs.counts.join$yr.season[pick])
legs.counts.join$yr.season <- droplevels(legs.counts.join$yr.season)
## save a copy of the R files
saveRDS(legs.counts.join, 'C:/CloudStor/R_Stuff/FIS/legs.counts.join.RDS')
```
**OPTION:** the dataframe can also be seperated into individual LEG sampling sites
```{r leg counts by site, results="hide"}
## subset data to individual LEG sampling sites
list_legscounts.site <- split(legs.counts.join, legs.counts.join$site)
names(list_legscounts.site)
legscounts.sites <- c("legscounts.BET", "legscounts.BRB", "legscounts.BRS",
"legscounts.GAR", "legscounts.GEO", "legscounts.INN",
"legscounts.LOU", "legscounts.MUN", "legscounts.OUT",
"legscounts.SEY", "legscounts.TEL", "legscounts.THU")
for (i in 1:length(list_legscounts.site)) {
assign(legscounts.sites[i], list_legscounts.site[[i]])
}
## save a copy of the R files
saveRDS(list_legscounts.site, 'C:/CloudStor/R_Stuff/FIS/list_legscounts.site.RDS')
```
#### LEG size frequency dataframe
```{r leg size frequency data}
## create a copy of the original LEG dataframe
legs.sl <- legs.df.2
## construct date and season variables
legs.sl$sampyear <- year(legs.sl$survdate)
legs.sl$season <- getSeason(legs.sl$survdate)
## recode autumn samples as summer
legs.sl$season <- gsub( "Autumn", "Summer", legs.sl$season)
## create year.season variable and arrange in order (i.e. summer, winter, spring)
legs.sl$season <- as.factor(legs.sl$season)
legs.sl$season <- ordered(legs.sl$season, levels=c("Summer","Winter","Spring"))
legs.sl$yr.season <- interaction(legs.sl$sampyear,legs.sl$season)
legs.sl$yr.season <-
ordered(legs.sl$yr.season, levels = c("2015.Summer", "2015.Winter", "2015.Spring",
"2016.Summer", "2016.Winter", "2016.Spring",
"2017.Summer", "2017.Winter", "2017.Spring",
"2018.Summer", "2018.Winter", "2018.Spring",
"2019.Summer", '2019.Winter', '2019.Spring'))
## adjust misclassified seasons for The Gardens
pick <- which(legs.sl$site == "GAR")
legs.sl$yr.season[pick] <- gsub( "2015.Summer", "2015.Spring", legs.sl$yr.season[pick])
legs.sl$yr.season <- droplevels(legs.sl$yr.season)
## save a copy of the R files
saveRDS(legs.sl, 'C:/CloudStor/R_Stuff/FIS/legs.sl.RDS')
```
**OPTION:** the dataframe can also be seperated into individual LEG sampling sites
```{r leg size frequency site data, results="hide"}
## subset data into sites
list_legs.sl.site <- split(legs.sl, legs.sl$site)
names(list_legs.sl.site)
legs.sl.sites <- c("legs.sl.BET", "legs.sl.BRB", "legs.sl.BRS", "legs.sl.GAR",
"legs.sl.GEO", "legs.sl.INN", "legs.sl.LOU", "legs.sl.MUN",
"legs.sl.OUT", "legs.sl.SEY", "legs.sl.TEL", "legs.sl.THU")
for (i in 1:length(list_legs.sl.site)) {
assign(legs.sl.sites[i], list_legs.sl.site[[i]])
}
## save a copy of the R files
saveRDS(list_legs.sl.site, 'C:/CloudStor/R_Stuff/FIS/list_legs.sl.site.RDS')
```
## ARM data
ARM data is loaded from one Excel file containing seperate sheets for each site.
```{r load arm data, echo=FALSE}
## Load data
xl_arm_data <- 'R:/TAFI/TAFI_MRL_Sections/Abalone/Section Shared/Abalone_databases/Data/Data for Transfer/2018/Juvenile_data_2016.xlsx'
```
### Compile and clean ARM data
ARM data is first compiled into a single dataframe which enables some cleaning of data to occur prior to being seperated into abundance and size structure data for analysis.
```{r compile and clean arm data, warning=FALSE, message=FALSE}
## identify sheets in excel workbook
tab_names_arms <- excel_sheets(path = xl_arm_data)
## create list from seperate sheets
list_all_arms <- lapply(tab_names_arms, function(x) read_excel(path = xl_arm_data,
sheet = x, guess_max = 10000))
## remove list items (i.e. sheets) that are irrelevant
list_all_arms_2 <- list_all_arms[-c(2, 10)]
## create dataframe from seperate sheets
arms.df <- rbindlist(list_all_arms_2, fill = T)
## convert varible names to lower case, compile data comments columns and clean data,
## removing additional columns from the Excel import (i.e. each sheet contained
## different column names for these variables)
names(arms.df) <- gsub('/', '', names(arms.df), fixed = T)
names(arms.df) <- gsub(' ', '', names(arms.df), fixed = T)
arms.df <- dplyr::rename(arms.df, rock.plate.3 = RockorPlate)
colnames(arms.df) <- tolower(colnames(arms.df))
colnames(arms.df) <- make.unique(names(arms.df))
names(arms.df) <- gsub('comments', 'comments.1', names(arms.df), fixed = T)
names(arms.df) <- gsub('...8', 'comments.2', names(arms.df), fixed = T)
arms.df <- dplyr::rename(arms.df, site = location)
arms.df <- dplyr::rename(arms.df, survdate = date)
arms.df <- dplyr::rename(arms.df, sllength = ab_sl)
arms.df <- dplyr::rename(arms.df, rock.plate.1 = rp)
arms.df <- dplyr::rename(arms.df, rock.plate.2 = rockorplate)
arms.df <- dplyr::rename(arms.df, tag.col = tagcolour)
arms.df <- dplyr::rename(arms.df, tag.id.col = printcolour)
arms.df <- dplyr::rename(arms.df, tag.id = tag_id)
arms.df <- dplyr::rename(arms.df, tag.recap = tr)
arms.df$string <- as.factor(arms.df$string)
arms.df$rock.plate.3 <- gsub('r', 'R', arms.df$rock.plate.3)
arms.df$string = gsub('North', 1, arms.df$string)
arms.df$plate = gsub(8.5, 8, arms.df$plate)
arms.df <- arms.df %>%
mutate(comments.1 = if_else(sllength == 'OFF', 'plate off', comments.1),
sllength = gsub('OFF', NA, sllength))
## combine duplicate columns and compile dataframe
arms.df.2 <- arms.df %>%
unite('comments', 'comments.1', 'comments.2', sep = ',') %>%
mutate(comments = gsub('NA', '', comments),
comments = gsub(',', '', comments),
comments = gsub('^$', NA, comments)) %>%
unite('rock.plate', 'rock.plate.1', 'rock.plate.2', 'rock.plate.3', sep = ',') %>%
mutate(rock.plate = gsub('NA', '', rock.plate),
rock.plate = gsub(',', '', rock.plate),
rock.plate = gsub('^$', NA, rock.plate))
## remove data with no site name or shell length
arms.df.2 <- filter(arms.df.2, !is.na(site))
arms.df.2 <- filter(arms.df.2, !is.na(sllength))
## remove characters from site names and rename sites to a three letter acronym
# unique(arms.df.2$site)
arms.df.2$site <- gsub(' ', '', arms.df.2$site)
arms.df.2$site <- gsub('_', '', arms.df.2$site)
arms.df.2$site <- gsub('Telopea', 'TEL', arms.df.2$site)
arms.df.2$site <- gsub('SP', 'SEY', arms.df.2$site)
arms.df.2$site <- gsub('\\bT\\b', 'THU', arms.df.2$site)
arms.df.2$site <- gsub('BI', 'BET', arms.df.2$site)
arms.df.2$site <- gsub('TG', 'GAR', arms.df.2$site)
arms.df.2$site <- gsub('GIII', 'GEO', arms.df.2$site)
arms.df.2$site <- gsub('MB', 'MUN', arms.df.2$site)
arms.df.2$site <- gsub('SB', 'INN', arms.df.2$site)
arms.df.2$site <- gsub('LB', 'LOU', arms.df.2$site)
arms.df.2$site <- gsub('OS', 'OUT', arms.df.2$site)
arms.df.2$site <- gsub('G3', 'GEO', arms.df.2$site)
arms.df.2$site <- gsub('G4', 'GEO', arms.df.2$site)
arms.df.2$site <- gsub('G5', 'GEO', arms.df.2$site)
arms.df.2$site <- gsub('G6', 'GEO', arms.df.2$site)
arms.df.2$site <- gsub('G7', 'GEO', arms.df.2$site)
```
#### ARM size frequency dataframe
```{r arm size frequency data}
## A. Extract records with abs for length frequency analysis ####
arms.sl <- arms.df.2 %>%
mutate(sllength = as.numeric(as.character(sllength))) %>%
filter(is.nan(sllength) | !is.na(sllength))
## construct date and season variables
arms.sl$sampyear <- as.factor(year(arms.sl$survdate))
arms.sl$season <- getSeason(arms.sl$survdate)
## recode autumn samples as summer
arms.sl$season <- gsub( "Autumn", "Summer", arms.sl$season)
arms.sl$season <- as.factor(arms.sl$season)
arms.sl$season <- ordered(arms.sl$season, levels=c("Summer","Winter","Spring"))
## extract year.season and arrange in order (i.e. summer, winter, spring)
arms.sl$yr.season <- interaction(arms.sl$sampyear,arms.sl$season)
# levels(arms.sl$yr.season)
arms.sl$yr.season <-
ordered(arms.sl$yr.season, levels = c("2015.Summer", "2015.Winter", "2015.Spring",
"2016.Summer", "2016.Winter", "2016.Spring",
"2017.Summer", "2017.Winter", "2017.Spring",
"2018.Summer", "2018.Winter", "2018.Spring",
"2019.Summer", "2019.Winter", "2019.Spring"))
## recode Gardens 2015.summer samples as 2015.spring
pick <- which(arms.sl$site == "GAR")
arms.sl$yr.season[pick] <- gsub( "2015.Summer", "2015.Spring", arms.sl$yr.season[pick])
arms.sl$yr.season <- droplevels(arms.sl$yr.season)
## save a copy of the R files
saveRDS(arms.sl, 'C:/CloudStor/R_Stuff/FIS/arms.sl.RDS')
```
**OPTION:** the dataframe can also be seperated into individual ARM sampling sites
```{r arm size frequency site data, results="hide"}
## subset data into ARM sampling sites
list_arms.sl.site <- split(arms.sl, arms.sl$site)
names(list_arms.sl.site)
arms.sl.sites <- c("arms.sl.BET", "arms.sl.BRB", "arms.sl.BRS", "arms.sl.GAR",
"arms.sl.GEO", "arms.sl.INN", "arms.sl.OUT", "arms.sl.SEY")
for (i in 1:length(list_arms.sl.site)) {
assign(arms.sl.sites[i], list_arms.sl.site[[i]])
}
## save a copy of the R files
saveRDS(list_arms.sl.site, 'C:/CloudStor/R_Stuff/FIS/list_arms.sl.site.RDS')
```
#### ARM density dataframe
```{r arm count data}
## determine the surface area of the ARM (diameter = 400 mm)
platearea <- pi*0.2^2
## create unique ID/index for each ARM and survdate combination
arms.df.2$survindex <- as.factor(paste(arms.df.2$site,
arms.df.2$survdate,
arms.df.2$string,
arms.df.2$plate, sep="_"))
## subset and count number of animals per ARM by survdate
dat <- arms.df.2 %>%
mutate(sllength = as.numeric(as.character(sllength))) %>%
filter(is.nan(sllength) | !is.na(sllength)) %>%
group_by(survindex) %>%
summarise(ab_n=n()) %>%
complete(survindex, fill = list(ab_n = 0)) %>%
as.data.frame()
## calculate abs per square metre
dat$absm <- dat$ab_n * (1/platearea)
## unpack survindex variables and create new dataframe
arm.counts <- data.frame(separate(dat, survindex, sep = "_",
into = c("site", "survdate", "string","plate"),
convert = TRUE), dat$survindex, dat$ab_n, dat$absm)
## format date variable and add year/season variables
arm.counts$survdate <- as.Date(strptime(arm.counts$survdate, "%Y-%m-%d"))
arm.counts$sampyear <- as.factor(year(arm.counts$survdate))
arm.counts$season <- getSeason(arm.counts$survdate)
## recode autumn samples as summer
arm.counts$season <- gsub( "Autumn", "Summer", arm.counts$season)
arm.counts$season <- as.factor(arm.counts$season)
arm.counts$season <- ordered(arm.counts$season, levels=c("Summer","Winter","Spring"))
## create variable identifying year and season
arm.counts$yr.season <- interaction(arm.counts$sampyear,arm.counts$season)
arm.counts$yr.season <-
ordered(arm.counts$yr.season, levels = c("2015.Summer", "2015.Winter", "2015.Spring",
"2016.Summer", "2016.Winter", "2016.Spring",
"2017.Summer", "2017.Winter", "2017.Spring",
"2018.Summer", "2018.Winter", "2018.Spring",
"2019.Summer", "2019.Winter", "2019.Spring"))
## recode Gardens 2015.summer samples as 2015.spring
pick <- which(arm.counts$site == "GAR")
arm.counts$yr.season[pick] <- gsub( "2015.Summer", "2015.Spring",
arm.counts$yr.season[pick])
arm.counts$yr.season <- droplevels(arm.counts$yr.season)
## save a copy of the R files
saveRDS(arm.counts, 'C:/CloudStor/R_Stuff/FIS/arm.counts.RDS')
```
**OPTION:** the dataframe can also be seperated into different size classes to generate lagged association plots with adults abalone counts (see ARM and LEG plots)
```{r legal and sub-legal leg counts 2, echo=FALSE}
## Filter for juvenile abalone approx. 6-months old (i.e. <25 mm)
arms.dat.juv <- arms.df.2 %>%
filter(sllength <= 25) %>%
group_by(survindex) %>%
summarise(ab_n = n()) %>% #as.data.frame()
complete(survindex, fill = list(ab_n = 0)) %>%
as.data.frame()
## join dataframes created above for survindex
arms.counts.join <- dplyr::rename(arm.counts, survindex = dat.survindex) %>%
left_join(., arms.dat.juv, by = 'survindex')
## rename variables to identify abcounts from each size class
arms.counts.join <- dplyr::rename(arms.counts.join, ab_n = ab_n.x)
arms.counts.join <- dplyr::rename(arms.counts.join, ab_n_juv = ab_n.y)
## calculate abs per square metre for joint dataframe
arms.counts.join$absm_juv <- arms.counts.join$ab_n_juv/platearea
## save a copy of the R files
saveRDS(arms.counts.join, 'C:/CloudStor/R_Stuff/FIS/arms.counts.join.RDS')
```
## Combine data
For the 2018 Abalone Stock Assessment Report ARM and LEG data were combined so that both sources of size data could be displayed on the one figure/plot.
### Density data combined
```{r arm and leg combined density data, warning=FALSE}
## load most recent juvenile and adult data sets
leg.counts <- readRDS('C:/CloudStor/R_Stuff/FIS/leg.counts.RDS')
arm.counts <- readRDS('C:/CloudStor/R_Stuff/FIS/arm.counts.RDS')
## add column to identify FIS and ARM data
leg.counts$sampmethod <- 'LEG'
arm.counts$sampmethod <- 'ARM'
## rename absm columns to make unique for ARM or LEG
arm.counts <- dplyr::rename(arm.counts, absm.arm = absm)
leg.counts <- dplyr::rename(leg.counts, absm.leg = absm)
## convert arm.counts survdate to POSIXct
arm.counts$survdate <- as.Date(strptime(arm.counts$survdate, "%Y-%m-%d"))
## convert sampyear to factor from leg.counts df
leg.counts$sampyear <- as.factor(leg.counts$sampyear)
arm.counts$string <- as.factor(arm.counts$string)
## join FIS and ARM data
arm.leg.counts <- bind_rows(leg.counts, arm.counts)
## save a copy of the R files
saveRDS(arm.leg.counts, 'C:/CloudStor/R_Stuff/FIS/arm.leg.counts.RDS')
```
### Size frequency data combined
```{r arm and leg combined size data, warning=FALSE}
## load most recent ARM and LEG size frequency data sets
legs.sl <- readRDS('C:/CloudStor/R_Stuff/FIS/legs.sl.RDS')
arms.sl <- readRDS('C:/CloudStor/R_Stuff/FIS/arms.sl.RDS')
## convert sampyear to factor
arms.sl$sampyear <- as.factor(arms.sl$sampyear)
legs.sl$sampyear <- as.factor(legs.sl$sampyear)
# add column to identify ARM and LEG data
legs.sl$sampmethod <- 'LEG'
arms.sl$sampmethod <- 'ARM'
## rename shell length columns to make unique for ARM or LEG
arms.sl <- dplyr::rename(arms.sl, sllength.arm = sllength)
legs.sl <- dplyr::rename(legs.sl, sllength.leg = sllength)
## convert abcounts survdate to POSIXct
# legs.sl$survdate <- as.Date(strptime(legs.sl$survdate, "%Y-%m-%d"))
# legs.sl$survdate <- as.Date(strptime(legs.sl$survdate, "%Y-%m-%d"))
# join FIS and ARM data
arm.leg.sl <- bind_rows(legs.sl, arms.sl)
## save a copy of the R files
saveRDS(arm.leg.sl, 'C:/CloudStor/R_Stuff/FIS/arm.leg.sl.RDS')
```
## ARM and LEG plots
Create some abbreviated x-axis labels for plots where there is a long time series of data and potential for labels to appear squashed.
```{r season labels}
## create short label names for plot facets and axis
season_labels <- c("2015.Summer" = '2015.Su',
"2015.Winter" = '2015.Wi',
"2015.Spring" = '2015.Sp',
"2016.Summer" = '2016.Su',
"2016.Winter" = '2016.Wi',
"2016.Spring" = '2016.Sp',
"2017.Summer" = '2017.Su',
"2017.Winter" = '2017.Wi',
"2017.Spring" = '2017.Sp',
"2018.Summer" = '2018.Su',
"2018.Winter" = '2018.Wi',
"2018.Spring" = '2018.Sp',
"2019.Summer" = '2019.Su',
"2019.Winter" = '2019.Wi',
"2019.Spring" = '2019.Sp')
```
### Size frequency plot
```{r inverted arm leg size plot, warning=FALSE, results="hide"}
## load most recent combined ARM and LEG size frequency data set
arm.leg.sl <- readRDS('C:/CloudStor/R_Stuff/FIS/arm.leg.sl.RDS')
## exract unique sites and yr.seasons
arm.leg.sites <- unique(arm.leg.sl$site)
arm.leg.seasons <- data.frame(yr.season = unique(arm.leg.sl$yr.season))
## loop through sites to generate arm and leg plots autonomously
for (i in arm.leg.sites){
## subset site data
arm.leg.site <- subset(arm.leg.sl, site == i)
## re-order data so that facet plots in vertical order of two columns
arm.leg.site$yr.season <- factor(arm.leg.site$yr.season,
levels = c("2015.Summer", "2017.Winter",
"2015.Winter", "2017.Spring",
"2015.Spring", "2018.Summer",
"2016.Summer", "2018.Winter",
"2016.Winter", "2018.Spring",
"2016.Spring", "2019.Summer",
"2017.Summer", "2019.Winter",
'', "2019.Spring"))
## generate a summary table for chosen site to add counts to plots (i.e. n = xxx)
plot.n.LEG <- arm.leg.site %>%
filter(sampmethod == 'LEG') %>%
group_by(yr.season) %>%
summarise(n = paste('n =', n()))
plot.n.ARM <- arm.leg.site %>%
filter(sampmethod == 'ARM') %>%
group_by(yr.season) %>%
summarise(n = paste('n =', n()))
## generate dataframe to annotate 'no data' for missing seasons
arm.leg.summary <- arm.leg.site %>%
group_by(yr.season, sampmethod) %>%
summarise(n.sl = n()) %>%
as.data.frame()
ann_text <- left_join(arm.leg.seasons, arm.leg.summary, by = 'yr.season') %>%
mutate(lab = if_else(is.na(n.sl), 'NO DATA', NA_character_),
x = 90,
y = 40) %>%
filter(!is.na(lab)) %>%
mutate(yr.season = factor(yr.season)) %>%
select(c(yr.season, lab, x, y))
## re-order and convert yr.season to factor
ann_text$yr.season <- factor(ann_text$yr.season,
levels = c("2015.Summer", "2017.Winter",
"2015.Winter", "2017.Spring",
"2015.Spring", "2018.Summer",
"2016.Summer", "2018.Winter",
"2016.Winter", "2018.Spring",
"2016.Spring", "2019.Summer",
"2017.Summer", "2019.Winter",
'', "2019.Spring"))
## generate plot using 'if...else' statement to determine plot type depending on whether a site has ARMs installed
arm.leg.plot <- if(is.na(plot.n.ARM$yr.season)){
ggplot(data = arm.leg.site)+
geom_histogram(aes(x = sllength.leg, y = ..count..), binwidth = 10, fill = 'blue')+
geom_histogram(aes(x = sllength.arm, y = -..count..), binwidth = 10, fill = 'red')+
facet_wrap(. ~ yr.season, ncol = 2, drop = F)+
theme_bw()+
ylab("Frequency") +
xlab("Shell Length (mm)")+
coord_cartesian(ylim = c(-40, 115), xlim = c(0, 180))+
geom_hline(yintercept = 0, size = 0.1)+
geom_text(data = ann_text, aes(x = x, y = y, label = lab))+
geom_text(data = plot.n.LEG, aes(x = 160, y = 50, label = n),
colour = 'black', inherit.aes = F, parse = F, size = 3.5)+
geom_vline(aes(xintercept = 138),colour = 'red', linetype = 'dashed', size = 0.5)+
theme(legend.position = 'none')
} else {
ggplot(data = arm.leg.site)+
geom_histogram(aes(x = sllength.leg, y = ..count..), binwidth = 10, fill = 'blue')+
geom_histogram(aes(x = sllength.arm, y = -..count..), binwidth = 10, fill = 'red')+
facet_wrap(. ~ yr.season, ncol = 2, drop = F)+
theme_bw()+
ylab("Frequency") +
xlab("Shell Length (mm)")+
coord_cartesian(ylim = c(-40, 115), xlim = c(0, 180))+
geom_hline(yintercept = 0, size = 0.1)+
geom_text(data = ann_text, aes(x = x, y = y, label = lab))+
geom_text(data = plot.n.LEG, aes(x = 160, y = 50, label = n),
colour = 'black', inherit.aes = F, parse = F, size = 3.5)+
geom_text(data = plot.n.ARM, aes(x = 10, y = -30, label = if_else(n == 'n = 0', '', n)),
colour = 'black', inherit.aes = F, parse = F, size = 3.5, na.rm = F)+
geom_vline(aes(xintercept = 138),colour = 'red', linetype = 'dashed', size = 0.5)+
theme(legend.position = 'none')
}
# print(arm.leg.plot)
setwd('C:/CloudStor/R_Stuff/FIS')
ggsave(filename = paste('ARM_LEG_LF_', i, '.pdf', sep = ''),
plot = arm.leg.plot, units = 'mm', width = 190, height = 250)
ggsave(filename = paste('ARM_LEG_LF_', i, '.wmf', sep = ''),
plot = arm.leg.plot, units = 'mm', width = 190, height = 250)
}
```
#### SF for PowerPoint
```{r inverted arm leg size plot powerpoint, warning=FALSE, results="hide"}
## load most recent combined ARM and LEG size frequency data set
arm.leg.sl <- readRDS('C:/CloudStor/R_Stuff/FIS/arm.leg.sl.RDS')
## subset chosen site and last four sampling seasons for powerpoint presentation
unique(arm.leg.sl$site)
selected.site <- 'GEO'
selected.season <- c('2018.Spring', '2019.Summer', '2019.Winter', '2019.Spring')
arm.leg.site.lastfour <- arm.leg.sl %>%
filter(site %in% selected.site & yr.season %in% selected.season)
## re-order data so that facet plots in vertical order of two columns
arm.leg.site.lastfour$yr.season <- factor(arm.leg.site.lastfour$yr.season,
levels = c("2018.Spring",
"2019.Summer",
"2019.Winter",
"2019.Spring"))
## generate a summary table for chosen site to add counts to plots (i.e. n = xxx)
plot.n.LEG.lastfour <- arm.leg.site.lastfour %>%
filter(sampmethod == 'LEG') %>%
group_by(yr.season) %>%
summarise(n = paste('n =', n()))
plot.n.ARM.lastfour <- arm.leg.site.lastfour %>%
filter(sampmethod == 'ARM') %>%
group_by(yr.season) %>%
summarise(n = paste('n =', n()))
## manually generate dataframe to annotate 'no data' for missing seasons
# ann_text <- data.frame(x = 90, y = 40,
# lab = 'NO DATA',
# yr.season = c('2018.Spring', '2019.Summer'))
arm.leg.plot.lastfour <- ggplot(data = arm.leg.site.lastfour)+
geom_histogram(aes(x = sllength.leg, y = ..count..), binwidth = 10, fill = 'blue')+
geom_histogram(aes(x = sllength.arm, y = -..count..), binwidth = 10, fill = 'red')+
facet_wrap(. ~ yr.season, ncol = 1, drop = F)+
theme_bw()+
ylab("Frequency") +
xlab("Shell Length (mm)")+
coord_cartesian(ylim = c(-50, 115), xlim = c(0, 180))+
geom_hline(yintercept = 0, size = 0.1)+
# geom_text(data = ann_text, aes(x = x, y = y, label = lab))+
geom_text(data = plot.n.LEG.lastfour, aes(x = 160, y = 50, label = n),
colour = 'black', inherit.aes = F, parse = F, size = 3.5)+
geom_text(data = plot.n.ARM.lastfour, aes(x = 10, y = -30, label = n),
colour = 'black', inherit.aes = F, parse = F, size = 3.5)+
geom_vline(aes(xintercept = 138),colour = 'red', linetype = 'dashed', size = 0.5)
print(arm.leg.plot.lastfour)
#setwd('C:/CloudStor/R_Stuff/FIS')
ggsave(filename = paste('ARM_LEG_LF_LASTFOUR_', selected.site, '.pdf', sep = ''),
plot = arm.leg.plot.lastfour, units = 'mm', width = 190, height = 250)
ggsave(filename = paste('ARM_LEG_LF_LASTFOUR_', selected.site, '.wmf', sep = ''),
plot = arm.leg.plot.lastfour, units = 'mm', width = 190, height = 250)
ggsave(filename = paste('ARM_LEG_LF_LASTFOUR_', selected.site, '.png', sep = ''),
plot = arm.leg.plot.lastfour, units = 'mm', width = 190, height = 250)
```
### Density plot
```{r arm leg density plot, results='hide'}
## load most recent combined ARM and LEG size frequency data set
arm.leg.counts <- readRDS('C:/CloudStor/R_Stuff/FIS/arm.leg.counts.RDS')
## exract unique sites and yr.seasons
arm.leg.sites <- unique(arm.leg.counts$site)
arm.leg.seasons <- data.frame(yr.season = unique(arm.leg.counts$yr.season))
## loop through sites to generate arm and leg plots autonomously
for (i in arm.leg.sites){
## subset site data
arm.leg.site.den <- subset(arm.leg.counts, site == i)
# ## subset chosen site
# unique(arm.leg.counts$site)
# selected.site <- 'GAR'
# arm.leg.site.den <- subset(arm.leg.counts, site %in% selected.site)
## re-order data so that yr.season is in sequence
arm.leg.site.den$string <- factor(as.integer(arm.leg.site.den$string), levels = c(1,2))
arm.leg.site.den$yr.season <-
ordered(arm.leg.site.den$yr.season, levels = c("2015.Summer", "2015.Winter",
"2015.Spring", "2016.Summer",
"2016.Winter", "2016.Spring",
"2017.Summer", "2017.Winter",
"2017.Spring", "2018.Summer",
"2018.Winter", "2018.Spring",
"2019.Summer", "2019.Winter",
'2019.Spring'))
## summarise data for arm and leg density
leg.summ <- arm.leg.site.den %>%
filter(sampmethod == 'LEG') %>%
group_by(string, yr.season) %>%
summarise(leg_mean = mean(absm.leg),
leg_n = n(),
leg_se = sd(absm.leg)/sqrt(leg_n))
arm.summ <- arm.leg.site.den %>%
filter(sampmethod == 'ARM') %>%
group_by(string, yr.season) %>%
summarise(arm_mean = mean(absm.arm),
arm_n = n(),
arm_se = sd(absm.arm)/sqrt(arm_n))
## arm density plot
arm_den <- ggplot()+
geom_line(data = arm.summ, aes(x = yr.season, y = arm_mean, group = factor(string),
linetype = string), position = position_dodge(0.5), colour = 'red')+
geom_point(data = arm.summ, aes(x = yr.season, y = arm_mean, group = factor(string),
colour = string), size = 3, position = position_dodge(0.5),
colour = 'red')+
geom_errorbar(data = arm.summ, aes(x = yr.season,
ymin = arm_mean - arm_se, ymax = arm_mean + arm_se,
group = factor(string), colour = string),
position = position_dodge(0.5), width = 0.1, colour = 'red')+
ylab(bquote('ARM Density ('*~m^2*')'))+
scale_x_discrete(labels = season_labels, drop = F)+
scale_color_manual(values = c('red'))+
theme_bw()+
#theme(legend.position = c(0.1, 0.9), legend.direction = 'vertical')+
theme(legend.position = 'none')+
labs(col = 'String')+