-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOR_WA_Strandings_1989_2016.Rmd
2621 lines (2216 loc) · 115 KB
/
OR_WA_Strandings_1989_2016.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: "Pinniped Strandings"
output:
word_document:
reference_docx: markdownstyledoc.docx
---
```{r include = FALSE}
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE, fig.width = 4, fig.height = 3.5)
```
```{r}
#CHUNK OUTLINE
#Load packages, setup, plot themes
#Load, clean data
#Sex class all strandings
#Sex class of HI strandings
#Age class of all and HI strandings
#All strandings over time
#HI and FI over time
#HI types over time
#Species composition over whole study period for all and HI cases
#Species over time for all and HI cases
#Proportion of cases that are HI
#Seasonal analyses for all and HI cases
#Seasonal analysis for species
#State-level spatial
#County-level: WA
#County-level: OR
#Creating large tables - county
#Creating large summary tables - age, sex, species, HI prevalence
#Maps
```
```{r load packages, echo = FALSE}
# install.packages("ggmap")
# install.packages("data.table")
#install.packages("devtools")
library(devtools)
#devtools::install_github("hadley/ggplot2")
#devtools::install_github("adletaw/captioner")
library(tidyr)
library(ggmap)
library(data.table)
library(ggfortify)
library(dplyr)
library(ggplot2)
library(cowplot)
library(scales)
library(captioner)
library(knitr)
library(reshape2)
library(stringr)
library(magrittr)
#library(ggsci)
#library(packrat)
#library(ggTimeSeries)
library(stats) #kruskal.test
library(PMCMR) # posthoc.kruskal.nemenyi.test https://cran.r-project.org/web/packages/PMCMR/vignettes/PMCMR.pdf
library(strucchange) # chow test https://cran.r-project.org/web/packages/strucchange/strucchange.pdf
library(pgirmess) #kruskalmc https://cran.r-project.org/web/packages/pgirmess/pgirmess.pdf
library(coin) #independence_test?? https://cran.r-project.org/web/packages/coin/coin.pdf
setwd("~/Documents/R/Strandings")
# Define PlotTheme ----
plot_theme <- function(...) {
theme(
#text = element_text(size = 11),
axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5, color = "black", size = 10),
axis.text = element_text(vjust = 0.5, color = "black", size = 10),
axis.title = element_text(size = 11),
axis.line.y = element_line(colour = "black"),
axis.line.x = element_line(colour = "black"),
plot.background = element_rect(),
panel.background = element_blank(),
panel.grid = element_blank(),
legend.title = element_blank(),
legend.key = element_blank(),
legend.text = element_text(size = 8),
...)
}
# Define Function for Publication Plots
pubfigure_simple_theme <- function(...) {
theme(
axis.text.x = element_blank(),
axis.text.y = element_text(vjust = 0.5, color = "black", size = 10),
axis.title.x = element_blank(),
axis.line.y = element_line(colour = "black"),
axis.line.x = element_line(colour = "black"),
plot.background = element_rect(),
panel.background = element_blank(),
panel.grid = element_blank(),
legend.title = element_blank(),
legend.key = element_blank(),
legend.text = element_text(size = 5.5),
...)
}
# Define Plot Theme
pubfigure_theme <- function(...) {
theme(
#text = element_text(size = 11),
axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5, color = "black", size = 10),
axis.text.y = element_text(vjust = 0.5, color = "black", size = 10),
axis.title = element_text(size = 10),
axis.line.y = element_line(colour = "black"),
axis.line.x = element_line(colour = "black"),
plot.background = element_rect(),
panel.background = element_blank(),
panel.grid = element_blank(),
legend.title = element_blank(),
legend.key = element_blank(),
legend.text = element_text(size = 5.5),
...)
}
pubfigure_simple_theme <- function(...) {
theme(
axis.text.x = element_blank(),
axis.text.y = element_text(vjust = 0.5, color = "black", size = 10),
axis.title.x = element_blank(),
axis.line.y = element_line(colour = "black"),
axis.line.x = element_line(colour = "black"),
plot.background = element_rect(),
panel.background = element_blank(),
panel.grid = element_blank(),
legend.title = element_blank(),
legend.key = element_blank(),
legend.text = element_text(size = 5.5),
...)
}
pubfigure_theme <- function(...) {
theme(
#text = element_text(size = 11),
axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5, color = "black", size = 10),
axis.text.y = element_text(vjust = 0.5, color = "black", size = 10),
axis.title = element_text(size = 10),
axis.line.y = element_line(colour = "black"),
axis.line.x = element_line(colour = "black"),
plot.background = element_rect(),
panel.background = element_blank(),
panel.grid = element_blank(),
legend.title = element_blank(),
legend.key = element_blank(),
legend.text = element_text(size = 5.5),
...)
}
case <- function(x)
paste0(toupper(substr(x, 1, 1)), tolower(substring(x, 2)))
figs <- captioner(prefix="Figure")
tbls <- captioner(prefix="Table")
# figs("name")
# ## [1] "Figure 1: Caption."
#
# figs("name",display="cite")
# ## [1] "Figure 1"
#
# figs("name",display="num")
# ## [1] "1"
```
```{r load pre-cleaned csv, echo = FALSE}
pinnipeds_data <- read.csv("pinnipeds_data_protected.csv", header = TRUE, na.strings = "", stringsAsFactors = FALSE) %>%
filter(Year.of.Observation > 1990)
pinnipeds_data$Age.Class <- factor(pinnipeds_data$Age.Class,
levels = c("Pup", "Yearling", "Subadult", "Adult", "Unid", "NA"))
pinnipeds_data$Month.of.Observation <- factor(pinnipeds_data$Month.of.Observation,
levels = c('JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'))
```
```{r sex of all strandings, echo = TRUE}
#Are there any correlations or patterns in age or sex and strandings?
#Sex and all
Sex_all <- pinnipeds_data %>%
filter(Sex == 'Male' | Sex == 'Female') %>%
group_by(Sex) %>%
summarize(cnt = n_distinct(National.Database.Number))
Sex_all_yr <- pinnipeds_data %>%
filter(Sex == 'Male' | Sex == 'Female') %>%
group_by(Sex, Year.of.Observation) %>%
summarize(cnt = n_distinct(National.Database.Number))
Sex_all_yr_mo <- pinnipeds_data %>%
filter(Sex == 'Male' | Sex == 'Female') %>%
group_by(Sex, Year.of.Observation, Month.of.Observation) %>%
summarize(cnt = n_distinct(National.Database.Number))
##HELP which of these outputs do I use? Mean monthly or mean annual? Monthly averages have smaller stdev, but maybe because differeneces between sex are smaller when not summed to the year level.
#Anova shows annual mean stranding is different between sexes, p < 0.05
summary(aov(cnt ~ Sex, Sex_all_yr))
sd(Sex_all_yr$cnt)
#Anova shows monthly mean stranding is different between sexes, p < 0.05
summary(aov(cnt ~ Sex, Sex_all_yr_mo)) #mean monthly
summary(aov(cnt ~ Sex + Year.of.Observation, Sex_all_yr_mo)) #mean monthly given difs in years?
sd(Sex_all_yr_mo$cnt)
#100% stacked bar chart - year - not much variation across years, though low perc females in 09-10.
Sex_all_yr_figure_stack <- ggplot(Sex_all_yr,
aes(x = as.factor(Year.of.Observation), y = cnt, fill = Sex)) +
geom_bar(stat = 'identity', position = 'fill') +
scale_y_continuous(labels = comma) +
xlab("") + ylab("Proportion of Strandings") +
plot_theme(legend.position = 'top')
#ggsave(Sex_all_yr_figure_stack, file = "./Figures/Sex_all_yr_figure_stack.pdf")
Sex_all_yr_figure <-
ggplot(Sex_all_yr, aes(x = as.factor(Year.of.Observation), y = cnt, fill = Sex)) +
geom_bar(stat = 'identity') +
scale_y_continuous(labels = comma) +
xlab("") + ylab("Total Strandings") +
plot_theme(legend.position = 'top')
#ggsave(Sex_all_yr_figure, file = "./Figures/Sex_all_yr_figure.pdf")
#Larger IQR for males
Sex_all_yr_boxplot <-
ggplot(Sex_all_yr_mo,
aes(x = as.factor(Year.of.Observation), y = cnt, fill = Sex)) +
geom_boxplot() +
scale_y_continuous(labels = comma) +
xlab("") + ylab("Mean Monthly Strandings") +
plot_theme(legend.position = 'top')
#ggsave(Sex_all_yr_boxplot, file = "./Figures/Sex_all_yr_boxplot.pdf")
#100% stacked bar chart - month - higher female percentage in august compared to december
Sex_all_month_figure <-
ggplot(Sex_all_yr_mo, aes(x = as.factor(Month.of.Observation), y = cnt, fill = Sex)) +
geom_bar(stat = 'identity', position = 'fill') +
xlab("") + ylab("Proportion of Strandings") +
plot_theme(legend.position = 'top')
#ggsave(Sex_all_month_figure, file = "./Figures/Sex_all_mo_figure.pdf")
#summary(aov(cnt ~ Month.of.Observation*Sex, Sex_all_yr_mo))
#glm shows seasonal peak, males dif from females, and males seasonal peak in jul/aug?
sex_all_mo_model <- summary(glm(cnt ~ Month.of.Observation*Sex, family = poisson(link = log), Sex_all_yr_mo))
#Tukey comparisons show which months males and females are different from each other and different from themselves.
#sexmonthsTukey <- TukeyHSD(aov(cnt ~ Sex + Month.of.Observation + Month.of.Observation*Sex, Sex_all_yr_mo))
# #Would be great to subset for sig p values
#sigmonths <- sexmonthsTukey$Sex[4] < 0.01
```
```{r Sex of HI cases}
#From above, we can see that there are differences between sexes for overall cases, but are these differences also apparent for human interaction cases?
#Sex and HI
Sex_HI <- pinnipeds_data %>%
filter(Sex == 'Male' | Sex == 'Female') %>%
group_by(Sex, Findings.of.Human.Interaction) %>%
summarize(cnt = n_distinct(National.Database.Number)) %>%
dcast(Sex ~ Findings.of.Human.Interaction, value.var = 'cnt')
Sex_HI_yr <- pinnipeds_data %>%
filter(Sex == 'Male' | Sex == 'Female') %>%
filter(Findings.of.Human.Interaction == 'Y' & Interaction.Type != 'NA') %>%
group_by(Sex, Year.of.Observation, Interaction.Type) %>%
summarize(cnt = n_distinct(National.Database.Number))
Sex_HI_mo <- pinnipeds_data %>%
filter(Sex == 'Male' | Sex == 'Female') %>%
filter(Findings.of.Human.Interaction == 'Y' & Interaction.Type != 'NA') %>%
group_by(Sex, Month.of.Observation, Interaction.Type) %>%
summarize(cnt = n_distinct(National.Database.Number))
#males different from females
sex_HI_model <- glm(cnt ~ Sex, family = poisson(link = log), Sex_HI_mo)
summary(sex_HI_model)
#same as sex_all_mo_model above - season peak, m/f different, seasonal peak for males?
sex_HI_mo_model <- glm(cnt ~ Month.of.Observation*Sex, family = poisson(link = log), Sex_HI_mo)
summary(sex_HI_mo_model)
#Anova shows interaction types are different, sexes are different, and types for each sex are different. Look below at pairwise for specific differences.
#summary(aov(cnt ~ Sex + Interaction.Type + Sex*Interaction.Type, Sex_HI_yr))
#Tukey comparisons show which sex/type combinations are different from each other. I would prefer to just compare Male-Female gunshot wounds, not male gunshots versus female fisheries.
#TukeyHSD(aov(cnt ~ Sex*Interaction.Type, Sex_HI_yr))
#100% stacked bar chart - year - females fewer gunshot
HI_type_sex_figure <- ggplot(Sex_HI_yr, aes(x = Interaction.Type, y = cnt, fill = Sex)) +
geom_bar(stat = 'identity', position = 'fill') +
xlab("") + ylab("Proportion of Strandings") +
plot_theme(legend.position = 'top')
#ggsave(HI_type_sex_figure, file = "./Figures/HI_type_sex_figure.pdf")
```
```{r age class}
#Do specific age classes strand more or less frequently than others?
age_all <- pinnipeds_data %>%
transform(Age.Class = ifelse(Year.of.Observation < 2002, 'NA', as.character(Age.Class))) %>%
#filter(Year.of.Observation > 2001) %>%
group_by(Age.Class) %>%
summarize(cnt = n_distinct(National.Database.Number)) %>%
transform(Age.Class = factor(Age.Class))
#age_all$prop <- round(age_all$cnt/sum(age_all$cnt), 2)*100
# age_all_table <- age_all
# colnames(age_all_table) <- c("Age", "Number", "Proportion (%)")
age_sex_all <- pinnipeds_data %>%
#filter(Year.of.Observation > 2001) %>%
transform(Age.Class = ifelse(Year.of.Observation < 2002, 'NA', as.character(Age.Class))) %>%
group_by(Sex, Age.Class) %>%
summarize(cnt = n_distinct(National.Database.Number))
# age_sex_all_figure <-
# ggplot(age_sex_all, aes(x = as.factor(Age.Class), y = cnt, fill = Sex)) +
# geom_bar(stat = 'identity', position = 'fill') +
# xlab("") + ylab("Proportion of Strandings") +
# plot_theme(legend.position = 'top') +
# scale_fill_brewer(palette = 'Set1')
#ggsave(age_sex_all_figure, file = "./Figures/age_sex_all_figure.pdf")
age_sex_table <- age_sex_all %>%
dcast(Age.Class ~ Sex, value.var = 'cnt') %>%
filter(Age.Class != 'NA') %>%
transform(Prop.Fem = round(Female/(Female + Male + Unid), 3)*100,
Prop.Male = round(Male/(Female + Male + Unid), 3)*100,
Prop.Unid = round(Unid/(Female + Male + Unid), 3)*100) %>%
merge(age_all, by = 'Age.Class') %>%
arrange(Age.Class) %>%
select(c(Age.Class, cnt, Female, Prop.Fem, Male, Prop.Male, Unid, Prop.Unid))
colnames(age_sex_table) <- c("Age.Class", "Total (N)", "Female (N)", "Female (%)", "Male (N)", "Male (%)", "Unid. (N)", "Unid. (%)")
average_sex <- c(as.character("Average"), "--", "--", round(mean(age_sex_table[,4]), 1), "--", round(mean(age_sex_table[,6]), 1), "--", round(mean(age_sex_table[,8]), 1))
age_sex_table <- rbind(age_sex_table, average_sex, stringsAsFactors = F)
age_sex_table <- write.csv(age_sex_table, file = "./Figures/age_sex_table.csv", row.names = F)
```
```{r all strandings over time}
#Are the number of cases of all combined species increasing or decreasing over time?
data_by_year <- pinnipeds_data %>%
group_by(Year.of.Observation) %>%
dplyr::summarize(cnt = n_distinct(National.Database.Number))
#Statistically significant change in all stranding cases in OR and WA combined over time (p < 0.05, 25 strandings per year increase).
timeseries_all_model <- glm(cnt ~ Year.of.Observation, family = poisson(link = log), data = data_by_year)
timeseries_all_model <- lm(cnt ~ Year.of.Observation, data = data_by_year)
summary(timeseries_all_model)
plot(timeseries_all_model)
all_yr_figure <-
ggplot(data_by_year, aes(x = Year.of.Observation, y = cnt)) +
geom_point(position = "identity") +
geom_smooth(method = "loess", se = FALSE, col = 'black', linetype = 3) +
xlab("") + ylab("Annual Strandings") +
scale_y_continuous(labels = comma) +
plot_theme() +
scale_color_brewer(palette = 'Set1')
#ggsave(all_yr_figure, file = "./Figures/all_year_figure.pdf")
```
```{r HI and FI number of cases over time}
#Are the number of HI cases of all combined species increasing or decreasing over time?
HI_by_year <- pinnipeds_data %>%
filter(Findings.of.Human.Interaction == 'Y') %>%
group_by(Year.of.Observation) %>%
summarize(cnt = n_distinct(National.Database.Number))
#Regression shows significant increase (6/yr) of all HI cases, p < 0.05
timeseries_HI_model <- glm(cnt ~ Year.of.Observation, family = poisson(link = log), data = HI_by_year)
timeseries_HI_model <- lm(cnt ~ Year.of.Observation, data = HI_by_year)
autoplot(timeseries_HI_model)
summary(timeseries_HI_model)
#anova confirms years are different, p-val < 0.05
summary(aov(cnt ~ Year.of.Observation, data = HI_by_year))
HI_year_figure <-
ggplot(HI_by_year, aes(x = Year.of.Observation, y = cnt)) +
geom_point(position = "identity") +
geom_smooth(method = "lm", se = FALSE, col = 'black', linetype = 3) +
xlab("") + ylab("Annual Human Interaction Cases") +
scale_y_continuous(labels = comma) +
#scale_x_continuous(breaks = c(1989:2015)) +
plot_theme(legend.position = 'top') +
scale_color_brewer(palette = 'Set1')
#ggsave(HI_year_figure, file = "./Figures/HI_year_figure.pdf")
```
```{r HI types over time}
#Are specific types of HI cases changing over time?
HI_by_year_type <- pinnipeds_data %>%
filter(Findings.of.Human.Interaction == 'Y' & Interaction.Type != 'NA') %>%
group_by(Interaction.Type, Year.of.Observation) %>%
summarize(cnt = n_distinct(National.Database.Number))
#Regression shows there is an effect of year for all HI types, that they are increasing over time (approx 1-2 cases/year for fish, gunshot, and other).
timeseries_HI_type_model <- glm(cnt ~ Year.of.Observation + Interaction.Type, family = poisson(link = log), data = HI_by_year_type)
summary(timeseries_HI_type_model)
autoplot(timeseries_HI_type_model)
#Tukey shows average annual HI types are not all different from one another (boat has significantly less)
TukeyHSD(aov(cnt ~ Interaction.Type, data = HI_by_year_type))
HI_type_year_figure <-
ggplot(HI_by_year_type, aes(x = Year.of.Observation, y = cnt,
group = Interaction.Type, col = Interaction.Type)) +
geom_point(position = "identity") +
geom_smooth(method = "lm", se = FALSE) +
xlab("") + ylab("Human Interaction Cases") +
plot_theme(legend.position = 'top') +
scale_color_brewer(palette = 'Set1')
#ggsave(HI_type_year_figure, file = "./Figures/HI_type_year_figure.pdf")
```
```{r categorical species comparison for all years all HI and FI}
#Do some species strand more frequently than others? All years combined here, time series in below chunk.
# Yes, harbor seals, CSL, and stellers strand more
species <- pinnipeds_data %>%
group_by(Pinniped.Common.Name) %>%
summarize(cnt = n_distinct(National.Database.Number))
kruskal.test(species)
species_year <- pinnipeds_data %>%
filter(Pinniped.Common.Name != 'Unidentified') %>%
group_by(Year.of.Observation, Pinniped.Common.Name) %>%
summarize(cnt = n_distinct(National.Database.Number))
species_year_mean <- pinnipeds_data %>%
group_by(Year.of.Observation, Pinniped.Common.Name) %>%
summarize(cnt = n_distinct(National.Database.Number)) %>%
group_by(Pinniped.Common.Name) %>%
summarize(mean = mean(cnt))
species_figure <- species_year %>%
filter(Pinniped.Common.Name != 'Unidentified') %>%
ggplot(aes(Pinniped.Common.Name, cnt)) +
geom_boxplot() +
scale_y_continuous(labels = comma) +
xlab("") + ylab("Annual Strandings") +
plot_theme()
#ggsave(species_figure, file = "./Figures/species_figure.pdf")
#Anova shows average annual strandings are significantly different between species. Should I also have year in the anova?
summary(aov(cnt ~ Pinniped.Common.Name*Year.of.Observation, data = species_year))
summary(glm(cnt ~ Pinniped.Common.Name, family = poisson(link = log), data = species_year))
#Tukey shows which species are different from each other
#pairwise.t.test(species.year$cnt, species.year$Pinniped.Common.Name, p.adj = "none")
kruskalmc(species_year$cnt ~ species_year$Pinniped.Common.Name)
#Are HI and FI cases signficantly different between species as well?
##HI cases
species_year_HI <- pinnipeds_data %>%
filter(Pinniped.Common.Name != 'Unidentified') %>%
filter(Findings.of.Human.Interaction == 'Y' & Interaction.Type != 'NA') %>%
group_by(Year.of.Observation, Pinniped.Common.Name) %>%
summarize(cnt = n_distinct(National.Database.Number))
species_year_HI_figure <-
ggplot(species_year_HI, aes(Pinniped.Common.Name, cnt)) +
geom_boxplot() +
xlab("") + ylab("Annual Human Interaction Cases") +
scale_y_continuous(labels = comma) +
plot_theme()
#ggsave(species_year_HI_figure, file = "./Figures/species_year_HI_figure.pdf")
#Anova shows that yes, the mean annual HI strandings are different across species.
#Harbor seals are different from everything else, but no other sig difs
summary(aov(cnt ~ Pinniped.Common.Name, data = species_year_HI))
TukeyHSD(aov(cnt ~ Pinniped.Common.Name, data = species_year_HI))
##FI cases
##CSLs are shot more than any other species, and way more proportionally than overall strandings or HI
species_year_FI <- pinnipeds_data %>%
filter(Fishery.Interaction == 'Y' & Pinniped.Common.Name != 'Unidentified') %>%
group_by(Year.of.Observation, Pinniped.Common.Name) %>%
summarize(cnt = n_distinct(National.Database.Number))
species_fish_figure <-
ggplot(species_year_FI, aes(Pinniped.Common.Name, cnt)) +
geom_boxplot() +
xlab("") + ylab("Annual Fisheries Interactions") +
plot_theme()
#ggsave(species_fish_figure, file = "./Figures/species_fish_figure.pdf")
#Sig difs overall, but not pairwise?
summary(aov(cnt ~ Pinniped.Common.Name, data = species_year_FI))
TukeyHSD(aov(cnt ~ Pinniped.Common.Name, data = species_year_FI))
species_year_shot <- pinnipeds_data %>%
filter(Shot == 'Y' & Pinniped.Common.Name != 'Unidentified') %>%
group_by(Year.of.Observation, Pinniped.Common.Name) %>%
summarize(cnt = n_distinct(National.Database.Number))
species_shot_figure <-
ggplot(species_year_shot, aes(Pinniped.Common.Name, cnt)) +
geom_boxplot() +
xlab("") + ylab("Annual Gunshot Woundss") +
plot_theme()
#ggsave(species_shot_figure, file = "./Figures/species_shot_figure.pdf")
#No sig difs between species for gunshot wound cases. Sig difs for more recent years only. p = 0.06
summary(aov(cnt ~ Pinniped.Common.Name, data = species_year_shot))
TukeyHSD(aov(cnt ~ Pinniped.Common.Name, data = species_year_shot))
```
```{r timeline species comparison for all HI and FI}
#Are strandings or HI FI cases of certain species increasing or decreasing over time?
#We would expect proportions of certain types of cases to remain constant over time, so are the proportions of HI and FI cases changing?
#All species changing over time (HS and CSL increasing, others decreasing); HELP output suggests negative slope, but looks like an increasing trend in figure for stellers
timeseries_all_model_sp <- glm(cnt ~ Pinniped.Common.Name + Year.of.Observation, family = poisson(link = log), data = species_year)
summary(timeseries_all_model_sp)
autoplot(timeseries_all_model_sp)
#All species HI changing over time, increasing for CSL and HS by less than a case per year, others decreasing by up to 2 cases/yr
timeseries_HI_model_sp <- glm(cnt ~ Pinniped.Common.Name + Year.of.Observation, family = poisson(link = log), data = species_year_HI)
summary(timeseries_HI_model_sp)
species_all_figure <-
ggplot(species_year, aes(x = Year.of.Observation, y = cnt,
group = Pinniped.Common.Name, col = Pinniped.Common.Name)) +
geom_point(stat = 'identity', position = 'jitter') +
geom_smooth(method = 'lm', se = F) +
ylab("Annual Strandings") + xlab("") +
scale_y_continuous(labels = comma) +
plot_theme(legend.position = 'top') +
scale_color_brewer(palette = 'Set2')
#ggsave(species_all_figure, file = "./Figures/species_all_figure.pdf")
#strandings by year, species stacked
species_all_figure_stacked <-
ggplot(species_year, aes(x = factor(Year.of.Observation), y = cnt, fill = Pinniped.Common.Name)) +
geom_bar(stat = 'identity') +
ylab("Annual Strandings") + xlab("") +
scale_y_continuous(labels = comma) +
plot_theme(legend.position = 'top') +
scale_fill_brewer(palette = 'Set2')
#ggsave(species_all_figure_stacked, file = "./Figures/species_all_figure_stacked.pdf")
species_HI_figure <-
ggplot(species_year_HI, aes(x = factor(Year.of.Observation), y = cnt,
col = Pinniped.Common.Name, group = Pinniped.Common.Name)) +
geom_point(stat = 'identity') +
geom_smooth(method = 'lm', se = F) +
ylab("Human Interaction Cases") + xlab("") +
plot_theme(legend.position = 'top') +
scale_color_brewer(palette = 'Set1')
#ggsave(species_HI_figure, file = "./Figures/species_HI_figure.pdf")
#Are fisheries interactions cases changing over time for particular species?
# Yes, harbors going up, others going down? But the figure really looks like they're going up. Do I need to have year in the model?
#Anova shows average annual FI cases are different across species
summary(aov(cnt ~ Pinniped.Common.Name, data = species_year_FI))
#All species except NES (not sig) and CSL/HS (increasing) decreasing over time
model_species_FI <- glm(cnt ~ Year.of.Observation + Pinniped.Common.Name, family = poisson(link = log), data = species_year_FI)
autoplot(model_species_FI)
summary(model_species_FI)
species_year_FI_figure <-
ggplot(species_year_FI, aes(x = Year.of.Observation, y = cnt,
col = Pinniped.Common.Name, group = Pinniped.Common.Name)) +
geom_point(stat = 'identity', position = 'jitter') +
geom_smooth(method = 'lm', se = F) +
ylab("Fisheries and Gunshot Wounds") + xlab("") +
plot_theme(legend.position = 'top') +
scale_color_brewer(palette = 'Set1')
#ggsave(species_year_FI_figure, file = "./Figures/species_year_FI_figure.pdf")
#Stacked
stacked_FI_figure <-
ggplot(species_year_FI, aes(x = factor(Year.of.Observation), y = cnt,
fill = Pinniped.Common.Name)) +
geom_bar(stat = 'identity') +
ylab("Total fisheries Interactions") + xlab("") +
plot_theme(legend.position = 'top') +
scale_fill_brewer(palette = 'Set2')
#ggsave(stacked_FI_figure, file = "./Figures/stacked_FI_figure.pdf")
#Exploring single species
# year.species.FI.TEST <- pinnipeds_data %>%
# filter(Pinniped.Common.Name == 'California sea lion') %>%
# filter(Fishery.Interaction == 'Y') %>%
# group_by(Year.of.Observation) %>%
# summarize(cnt = n_distinct(National.Database.Number))
#
# summary(lm(cnt ~ Year.of.Observation, year.species.FI.TEST))
```
```{r proportion of cases}
#Is the proportion of HI cases changing? More an artifact of improving diagnostics, but interesting nonetheless
#Proportion of HI cases goes up
#Proportion of FI cases doesn't seem to go up as much
#Proportion of shots goes up
#Updated: attempt at prop.trend.test: (successes, totals) - see stranding stats.Rmd
year_prop_HI <- pinnipeds_data %>%
group_by(Findings.of.Human.Interaction, Year.of.Observation) %>%
summarize(cnt = n_distinct(National.Database.Number)) %>%
dcast(Year.of.Observation ~ Findings.of.Human.Interaction, value.var = 'cnt') %>%
transform(Prop.HI = round(Y/(Y + N + CBD), 2)*100)
#test prevalence for year groups?
HI_prev_species_TEST <- pinnipeds_data %>%
filter(Pinniped.Common.Name != 'Unidentified') %>%
transform(Decade = ifelse(Year.of.Observation < 2000, "1",
ifelse(Year.of.Observation > 1999 & Year.of.Observation < 2010, "2", ifelse(Year.of.Observation > 2009, "3", "")))) %>%
group_by(Pinniped.Common.Name, Decade, Findings.of.Human.Interaction) %>%
summarize(cnt = n_distinct(National.Database.Number)) %>%
dcast(Pinniped.Common.Name + Decade ~ Findings.of.Human.Interaction, value.var = 'cnt')
HI_prev_species_TEST[is.na(HI_prev_species_TEST)] <- 0
HI_prev_species_TEST <- HI_prev_species_TEST %>%
transform(Prop.HI = round(Y/(Y+N+CBD), 2))
ggplot(HI_prev_species_TEST, aes(Decade, Prop.HI, col = Pinniped.Common.Name)) +
geom_point(stat = 'identity') +
geom_line() +
geom_smooth(method = 'lm', se = F) +
pubfigure_theme(legend.position = 'top')
#proportion of HI per species - prevalence
HI_prev_species_table <- pinnipeds_data %>%
filter(Pinniped.Common.Name != 'Unidentified') %>%
group_by(Pinniped.Common.Name, Year.of.Observation, Findings.of.Human.Interaction) %>%
summarize(cnt = n_distinct(National.Database.Number)) %>%
dcast(Pinniped.Common.Name + Year.of.Observation ~ Findings.of.Human.Interaction, value.var = 'cnt')
HI_prev_species_table[is.na(HI_prev_species_table)] <- 0
HI_prev_species_table <- HI_prev_species_table %>%
transform(Prop.HI = round(Y/(Y+N+CBD), 2))
ggplot(HI_prev_species_table, aes(Year.of.Observation, Prop.HI, col = Pinniped.Common.Name)) +
geom_point(stat = 'identity') +
geom_line() +
#geom_smooth(method = 'lm', se = F) +
pubfigure_theme(legend.position = 'top')
#Prevalence of all combined species
HI_prev <- pinnipeds_data %>%
group_by(Year.of.Observation, Findings.of.Human.Interaction) %>%
summarize(cnt = n_distinct(National.Database.Number)) %>%
dcast(Year.of.Observation ~ Findings.of.Human.Interaction, value.var = 'cnt')
HI_prev[is.na(HI_prev)] <- 0
HI_prev <- HI_prev %>%
transform(Prop.HI = round(Y/(Y+N+CBD), 2))
ggplot(HI_prev, aes(Year.of.Observation, Prop.HI)) +
geom_point(stat = 'identity') +
geom_line() +
geom_smooth(method = 'lm', se = F, col = "black", linetype = 3) +
xlab("") + ylab("Prevalence of Human Interactions") +
pubfigure_theme(legend.position = 'top')
#Need stats for proportions over time - can I do regression on a proportion?
timeseries_HIprev_model <- glm(Prop.HI ~ Year.of.Observation, family = poisson(link = log), data = HI_prev)
summary(timeseries_HIprev_model)
autoplot(timeseries_HIprev_model)
#Need stats for proportions over time - can I do regression on a proportion?
timeseries_HIprev_model_sp <- glm(Prop.HI ~ Year.of.Observation + Pinniped.Common.Name, family = poisson(link = log), data = HI_prev_species_table)
summary(timeseries_HIprev_model_sp)
autoplot(timeseries_HIprev_model_sp)
#Prevalence of specific HI types per species over time in chunk near bottom - "allprev"
#Proportion of fisheries
year_prop_FI <- pinnipeds_data %>%
group_by(Fishery.Interaction, Year.of.Observation) %>%
summarize(cnt = n_distinct(National.Database.Number)) %>%
dcast(Year.of.Observation ~ Fishery.Interaction, value.var = 'cnt') %>%
transform(Prop.FI = round(Y/(Y + N), 2))
year_prop_shot <- pinnipeds_data %>%
group_by(Shot, Year.of.Observation) %>%
summarize(cnt = n_distinct(National.Database.Number)) %>%
dcast(Year.of.Observation ~ Shot, value.var = 'cnt') %>%
transform(Prop.shot = round(Y/(Y + N), 2))
sp_prop_FI_shot <- pinnipeds_data %>%
filter(Sex != 'Unid') %>%
group_by(Shot, Fishery.Interaction, Pinniped.Common.Name, Sex) %>%
summarize(cnt = n_distinct(National.Database.Number)) %>%
transform(Fishery.Shot =
ifelse(Fishery.Interaction == 'Y', "Y",
ifelse(Shot == 'Y', "Y", "N"))) %>%
group_by(Fishery.Shot, Pinniped.Common.Name, Sex) %>%
summarize(sum = sum(cnt)) %>%
dcast(Pinniped.Common.Name + Sex ~ Fishery.Shot, value.var = 'sum') %>%
transform(Prop.FI.shot = round(Y/(Y + N), 2))
sp_prop_shot <- pinnipeds_data %>%
filter(Sex != 'Unid') %>%
group_by(Shot, Pinniped.Common.Name, Sex) %>%
summarize(cnt = n_distinct(National.Database.Number)) %>%
# transform(Fishery.Shot =
# ifelse(Fishery.Interaction == 'Y', "Y",
# ifelse(Shot == 'Y', "Y", "N"))) %>%
group_by(Shot, Pinniped.Common.Name, Sex) %>%
summarize(sum = sum(cnt)) %>%
dcast(Pinniped.Common.Name + Sex ~ Shot, value.var = 'sum') %>%
transform(Prop.shot = round(Y/(Y + N), 2))
HI_species_prev <- pinnipeds_data %>%
filter(Pinniped.Common.Name != 'Unidentified') %>%
group_by(Year.of.Observation,
Findings.of.Human.Interaction, Pinniped.Common.Name) %>%
summarize(cnt = n_distinct(National.Database.Number)) %>%
dcast(Year.of.Observation + Pinniped.Common.Name ~ Findings.of.Human.Interaction, value.var = 'cnt')
HI_species_prev[is.na(HI_species_prev)] <- 0
HI_species_prev <- HI_species_prev %>%
transform(Prop.HI = round(Y/(Y+N+CBD), 2))
#by species
HI_species_prev_figure <-
ggplot(HI_species_prev, aes(x = Year.of.Observation, y = Prop.HI)) +
#geom_point(stat = 'identity', position = 'identity') +
geom_smooth(aes(Year.of.Observation, Prop.HI), col = 'black') +
geom_line(aes(Year.of.Observation, Prop.HI, group = Pinniped.Common.Name, col = Pinniped.Common.Name)) +
#geom_smooth(aes(Year.of.Observation, Prop.HI, group = Pinniped.Common.Name, col = Pinniped.Common.Name), se = F) +
xlab("") + ylab("Proportion of HI") +
pubfigure_theme(legend.position = 'top') +
scale_color_grey()
HI_prev_condition <- pinnipeds_data %>%
group_by(Findings.of.Human.Interaction, Observation.Status.clean) %>%
summarize(cnt = n_distinct(National.Database.Number)) %>%
dcast(Observation.Status.clean ~ Findings.of.Human.Interaction, value.var = 'cnt')
HI_prev_condition[is.na(HI_prev_condition)] <- 0
HI_prev_condition <- HI_prev_condition %>%
transform(Prop.HI = round(Y/(Y+N+CBD), 2))
HI_prev_allconds <- pinnipeds_data %>%
group_by(Findings.of.Human.Interaction) %>%
summarize(cnt = n_distinct(National.Database.Number)) %>%
dcast(. ~ Findings.of.Human.Interaction) %>%
transform(prop = Y/(CBD+N))
HI_prev_allconds[is.na(HI_prev_allconds)] <- 0
HI_prev_allconds <- HI_prev_allconds %>%
transform(Prop.HI = round(Y/(Y+N+CBD), 2))
```
```{r monthly all HI FI}
#Are there seasonal patterns in all stranding cases? Only alive and fresh dead because timing matters - hard to tell when decomposed individuals stranded
monthly_all <- pinnipeds_data %>%
filter(Observation.Status == 'ALIVE' | Observation.Status == 'FRESH DEAD') %>%
group_by(Year.of.Observation, Month.of.Observation, Sex, Age.Class, Water.Body) %>%
summarize(cnt = n_distinct(National.Database.Number))
monthly_stats <- monthly_all %>%
group_by(Year.of.Observation, Month.of.Observation) %>%
summarize(cnt = sum(cnt))
#Overall anova and pairwise tests show that there is a seasonal peak (ie some months are different than others)
# summary(aov(cnt ~ Month.of.Observation, data = monthly_stats))
# TukeyHSD(aov(cnt ~ Month.of.Observation, data = monthly_stats))
#pairwise.t.test(monthly_all$cnt, monthly_all$Month.of.Observation, p.adj = "none")
#Kruskal-Wallis
kruskal.test(monthly_stats)
kruskalmc(monthly_stats$cnt ~ monthly_stats$Month.of.Observation)
posthoc.kruskal.nemenyi.test(cnt ~ Month.of.Observation, monthly_stats, dist = "Tukey")
posthoc.kruskal.nemenyi.test(cnt ~ Month.of.Observation, monthly_stats, dist = "Chisquare")
#Poisson - shows all months are different from the mean? but doesn't show which are dif from eachother?
monthly_all_model <- glm(cnt ~ Month.of.Observation, family = poisson(link = log), data = monthly_stats)
summary(monthly_all_model)
#All monthly cases by region
monthly_reg_figure <-
monthly_all %>% group_by(Month.of.Observation, Water.Body) %>%
summarize(sum = sum(cnt)) %>%
ggplot(aes(x = factor(Month.of.Observation), y = sum, fill = Water.Body)) +
geom_bar(stat = 'identity') +
ylab("Total Strandings") + xlab("") +
scale_y_continuous(labels = comma) +
plot_theme(legend.position = 'top') +
scale_fill_brewer(palette = 'Set1')
#All monthly cases by sex
monthly_sex_figure <-
monthly_all %>% group_by(Month.of.Observation, Sex) %>%
summarize(sum = sum(cnt)) %>%
ggplot(aes(x = factor(Month.of.Observation), y = sum, fill = Sex)) +
geom_bar(stat = 'identity') +
ylab("Total Strandings") + xlab("") +
scale_y_continuous(labels = comma) +
plot_theme(legend.position = 'top') +
scale_fill_brewer(palette = 'Set1')
#ggsave(monthly_sex_figure, file = "./Figures/monthly_sex_figure.pdf")
#Monthly strandings by age class
monthly_age_figure <- monthly_all %>%
group_by(Month.of.Observation, Age.Class) %>%
summarize(sum = sum(cnt)) %>%
ggplot(aes(x = factor(Month.of.Observation), y = sum, fill = as.factor(Age.Class))) +
geom_bar(stat = 'identity') +
ylab("Total Strandings") + xlab("") +
scale_y_continuous(labels = comma) +
plot_theme(legend.position = 'top') +
scale_fill_brewer(palette = 'Set3')
#ggsave(monthly_age_figure, file = "./Figures/monthly_age_figure.pdf")
monthly_age_stats <- monthly_all %>%
group_by(Month.of.Observation, Year.of.Observation, Age.Class) %>%
summarize(cnt = sum(cnt))
# kruskal.test(monthly_age_stats)
# kruskalmc(monthly_age_stats$cnt ~ monthly_age_stats$Month.of.Observation)
# posthoc.kruskal.nemenyi.test(cnt ~ Month.of.Observation + Age.Class, monthly_age_stats, dist = "Tukey")
# posthoc.kruskal.nemenyi.test(cnt ~ Month.of.Observation + Age.Class, monthly_age_stats, dist = "Chisquare")
##Stats for age HI type
age_HI_stats <- pinnipeds_data %>%
filter(Findings.of.Human.Interaction == 'Y' &
Interaction.Type != 'NA' & Age.Class != 'Unid') %>%
group_by(Age.Class, Year.of.Observation, Interaction.Type) %>%
summarize(cnt = n_distinct(National.Database.Number))
summary(aov(cnt ~ Age.Class + Interaction.Type, data = age_HI_stats))
TukeyHSD(aov(cnt ~ Age.Class + Interaction.Type + Age.Class*Interaction.Type, data = age_HI_stats))
#Seasonal age composition - pups are the only one that has the seasonal peak
monthly_age <- pinnipeds_data %>% group_by(Month.of.Observation, Age.Class) %>%
summarize(cnt = n_distinct(National.Database.Number)) %>%
dcast(Month.of.Observation ~ Age.Class, value.var = 'cnt') %>%
transform(Tot = Pup + Yearling + Subadult + Adult + Unid) %>%
transform(Pup.prop = round(Pup/Tot, 2)*100)
monthly_age_HI <- pinnipeds_data %>%
filter(Findings.of.Human.Interaction == 'Y' & Interaction.Type != 'NA') %>%
group_by(Month.of.Observation, Age.Class) %>%
summarize(cnt = n_distinct(National.Database.Number)) %>%
dcast(Month.of.Observation ~ Age.Class, value.var = 'cnt') %>%
transform(Tot = Pup + Yearling + Subadult + Adult + Unid) %>%
transform(Pup.prop = round(Pup/Tot, 2)*100)
#Peaks by the years
monthly_years_figure <-
ggplot(monthly_all, aes(x = factor(Month.of.Observation), y = cnt,
group = factor(Year.of.Observation), color = factor(Year.of.Observation))) +
#geom_area() +
geom_line(aes(group = factor(Year.of.Observation))) +
#geom_smooth(se = F) +
ylab("Strandings per Month") + xlab("") +
scale_y_continuous(labels = comma) +
plot_theme() #+
#scale_color_brewer()
#ggsave(monthly_years_figure, file = "./Figures/monthly_years_figure.pdf")
#Are there seasonal patterns in HI cases?
monthly_HI <- pinnipeds_data %>%
filter(Findings.of.Human.Interaction == 'Y') %>%
filter(Observation.Status == 'ALIVE' | Observation.Status == 'FRESH DEAD') %>%
group_by(Month.of.Observation, Year.of.Observation, Interaction.Type, Sex, Age.Class, Water.Body) %>%
summarize(cnt = n_distinct(National.Database.Number))
monthly_HI_yr_mo <- pinnipeds_data %>%
filter(Findings.of.Human.Interaction == 'Y') %>%
filter(Observation.Status == 'ALIVE' | Observation.Status == 'FRESH DEAD') %>%
group_by(Month.of.Observation, Year.of.Observation) %>%
summarize(cnt = n_distinct(National.Database.Number))
#Regression shows different in Jan and summer
monthly_HI_model <- glm(cnt ~ Month.of.Observation, family = poisson(link = log), data = monthly_HI_yr_mo)
summary(monthly_HI_model)
#summary(aov(cnt ~ Month.of.Observation, data = monthly_HI_yr_mo))
#plot of HI types over season per region
regplotdata <- monthly_HI %>%
filter(Interaction.Type == 'Gunshot') %>%
group_by(Month.of.Observation, Water.Body) %>%
summarize(cnt = sum(cnt))
reg_figure <- ggplot(regplotdata, aes(x = factor(Month.of.Observation), y = cnt, group = Water.Body, col = Water.Body)) +
geom_line() +
ylab("Human Interaction Cases") + xlab("") +
plot_theme(legend.position = 'top') +
scale_fill_brewer(palette = 'Set1')
monthly_HI_YNCBD <- pinnipeds_data %>%
filter(Observation.Status == 'ALIVE' | Observation.Status == 'FRESH DEAD') %>%
group_by(Findings.of.Human.Interaction, Month.of.Observation) %>%
summarize(cnt = n_distinct(National.Database.Number))
monthly_HI_YNCBD_prop <- pinnipeds_data %>%
filter(Observation.Status == 'ALIVE' | Observation.Status == 'FRESH DEAD') %>%
group_by(Findings.of.Human.Interaction, Month.of.Observation) %>%
summarize(cnt = n_distinct(National.Database.Number)) %>%
dcast(Month.of.Observation ~ Findings.of.Human.Interaction, value.var = 'cnt') %>%
transform(prop.Y = round(Y/(CBD+N+Y), 2)*100)
#Bar chart showing proportion of Y, N, and CBD HI cases
ggplot(monthly_HI_YNCBD, aes(x = factor(Month.of.Observation), y = cnt, fill = Findings.of.Human.Interaction)) +
geom_bar(stat = 'identity') +
ylab("Total Human Interaction Cases") + xlab("") +
plot_theme(legend.position = 'top') +
scale_fill_brewer(palette = 'Set1')
#Bar chart showing only HI cases - sum of total ever cases in each month
monthly_HI_figure <- monthly_HI %>%
group_by(Month.of.Observation) %>%
summarize(cnt = sum(cnt)) %>%
ggplot(aes(x = factor(Month.of.Observation), y = cnt)) +
geom_bar(stat = 'identity') +
ylab("Total Human Interaction Cases") + xlab("") +
scale_y_continuous(labels = comma) +
plot_theme() +
scale_fill_brewer(palette = 'Set1')
#ggsave(monthly_HI_figure, file = "./Figures/monthly_HI_figure.pdf")
#Bar chart showing monthly strandings by interaction type
monthly_HI_figure_stacked <- monthly_HI %>%
filter(Interaction.Type != 'NA') %>%
group_by(Month.of.Observation, Interaction.Type) %>%
summarize(sum = sum(cnt)) %>%
ggplot(aes(x = factor(Month.of.Observation), y = sum, fill = Interaction.Type)) +
geom_bar(stat = 'identity') +
ylab("Total Human Interaction Cases") + xlab("") +
plot_theme(legend.position = 'top') +
scale_fill_brewer(palette = 'Set1')
#ggsave(monthly_HI_figure_stacked, file = "./Figures/monthly_HI_figure_stacked.pdf")
#Bar chart showing monthly strandings by sex
monthly_HI %>% group_by(Month.of.Observation, Sex) %>%
summarize(sum = sum(cnt)) %>%
ggplot(aes(x = factor(Month.of.Observation), y = sum, fill = Sex)) +
geom_bar(stat = 'identity') +
ylab("Total Human Interaction Cases") + xlab("") +
plot_theme(legend.position = 'top') +
scale_fill_brewer(palette = 'Set1')
#Monthly HI strandings by age class
monthly_HI_age_figure <-
monthly_HI %>% group_by(Month.of.Observation, Age.Class) %>%
summarize(sum = sum(cnt)) %>%
ggplot(aes(x = factor(Month.of.Observation), y = sum, fill = Age.Class)) +
geom_bar(stat = 'identity') +
ylab("Total Human Interaction Cases") + xlab("") +
plot_theme(legend.position = 'top') +
scale_fill_brewer(palette = 'Set1')
#ggsave(monthly_HI_age_figure, file = "./Figures/monthly_HI_age_figure.pdf")
#Peaks by the years
monthly_HI_year_figure <-
ggplot(monthly_HI, aes(x = factor(Month.of.Observation), y = cnt, group = factor(Year.of.Observation), color = factor(Year.of.Observation))) +
#geom_line(aes(group = factor(Year.of.Observation))) +
geom_smooth(se = F) +
ylab("Monthly Human Interaction Cases") + xlab("") +
plot_theme() #+
#scale_color_brewer(palette = 'Set3')
#ggsave(monthly_HI_year_figure, file = "./Figures/monthly_HI_year_figure.pdf")
#Is there an effect of month on FI?
monthly_FI <- pinnipeds_data %>%
filter(Fishery.Interaction == 'Y') %>%
filter(Observation.Status == 'ALIVE' | Observation.Status == 'FRESH DEAD') %>%