#Input Data

#all_lakes <- read_xlsx("Data/All_Lakes_KAG_020322.xlsx")
all_lakes <- read_csv("All_Lakes_KAG_020322.csv")
## Rows: 1550 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): Sample_Code, Lake, Taxa, Strain
## dbl (2): Year, Year_TP
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
all_lakes <- as.data.frame(all_lakes)

#Break lakes into separate dataframes to be analyzed individually
  all_lakes$Lake <- as.factor(all_lakes$Lake)
  levels(all_lakes$Lake)
## [1] "Bald_Eagle"   "Christmas"    "Grays_Bay"    "Ham"          "Independence"
## [6] "North_Arm"    "Phelps_Bay"   "Smiths_Bay"
  eagle <- subset(all_lakes, all_lakes$Lake == "Bald_Eagle")
  head(eagle)
##     Sample_Code       Lake Taxa Year Year_TP Strain
## 239    MYR-7079 Bald_Eagle  EWM 2018    2018 MC-E-1
## 240    MYR-7080 Bald_Eagle  NWM 2018    2018 BE-N-2
## 241    MYR-7081 Bald_Eagle  NWM 2018    2018 BE-N-2
## 242    MYR-7082 Bald_Eagle  EWM 2018    2018 MC-E-1
## 243    MYR-7083 Bald_Eagle  EWM 2018    2018 MC-E-1
## 244    MYR-7084 Bald_Eagle  EWM 2018    2018 MC-E-1
  christmas <- subset(all_lakes, all_lakes$Lake == "Christmas")
  head(christmas)
##   Sample_Code      Lake Taxa Year Year_TP Strain
## 1    MYR-6915 Christmas  EWM 2018    2018 MC-E-1
## 2    MYR-6916 Christmas  EWM 2018    2018 MC-E-1
## 3    MYR-6917 Christmas  NWM 2018    2018 CH-N-1
## 4    MYR-6918 Christmas  EWM 2018    2018 MC-E-1
## 5    MYR-6919 Christmas  NWM 2018    2018 CH-N-1
## 6    MYR-6920 Christmas  NWM 2018    2018 CH-N-1
  grays_bay <- subset(all_lakes, all_lakes$Lake == "Grays_Bay")
  head(grays_bay)
##     Sample_Code      Lake Taxa Year Year_TP Strain
## 502    MYR-7276 Grays_Bay  HWM 2018    2018 MC-H-7
## 503    MYR-7283 Grays_Bay  HWM 2018    2018 MC-H-7
## 504    MYR-7284 Grays_Bay  HWM 2018    2018 MC-H-7
## 505    MYR-7288 Grays_Bay  HWM 2018    2018 MC-H-7
## 506    MYR-7290 Grays_Bay  HWM 2018    2018 MC-H-7
## 507    MYR-7295 Grays_Bay  HWM 2018    2018 MC-H-7
  ham <- subset(all_lakes, all_lakes$Lake == "Ham")
  head(ham)
##     Sample_Code Lake Taxa Year Year_TP  Strain
## 730    MYR-7166  Ham  HWM 2018  2018.5 HM-H-14
## 731    MYR-7167  Ham  HWM 2018  2018.5 HM-H-14
## 732    MYR-7168  Ham  HWM 2018  2018.5 HM-H-14
## 733    MYR-7169  Ham  HWM 2018  2018.5 HM-H-14
## 734    MYR-7170  Ham  HWM 2018  2018.5 HM-H-14
## 735    MYR-7171  Ham  HWM 2018  2018.5 HM-H-14
  indp <- subset(all_lakes, all_lakes$Lake == "Independence")
  head(indp)
##     Sample_Code         Lake Taxa Year Year_TP  Strain
## 922    MYR-6855 Independence  HWM 2018    2018 IN-H-99
## 923    MYR-6856 Independence  HWM 2018    2018 IN-H-99
## 924    MYR-6857 Independence  HWM 2018    2018 IN-H-99
## 925    MYR-6858 Independence  HWM 2018    2018 IN-H-99
## 926    MYR-6859 Independence  HWM 2018    2018 IN-H-99
## 927    MYR-6860 Independence  HWM 2018    2018 IN-H-99
  north_arm <- subset(all_lakes, all_lakes$Lake == "North_Arm")
  head(north_arm)
##      Sample_Code      Lake Taxa Year Year_TP  Strain
## 1136    MYR-7856 North_Arm  HWM 2019  2019.5  MC-H-7
## 1137    MYR-7857 North_Arm  HWM 2019  2019.5 MC-H-12
## 1138    MYR-7858 North_Arm  HWM 2019  2019.5  MC-H-9
## 1139    MYR-7859 North_Arm  HWM 2019  2019.5  MC-H-7
## 1140    MYR-7860 North_Arm  HWM 2019  2019.5  MC-H-7
## 1141    MYR-7861 North_Arm  HWM 2019  2019.5  MC-H-9
  phelps <- subset(all_lakes, all_lakes$Lake == "Phelps_Bay")
  head(phelps)
##      Sample_Code       Lake Taxa Year Year_TP  Strain
## 1243    MYR-8125 Phelps_Bay  HWM 2019  2019.5  PB-H-7
## 1244    MYR-8253 Phelps_Bay  HWM 2019  2019.5  PB-H-8
## 1245    MYR-8254 Phelps_Bay  HWM 2019  2019.5  PB-H-7
## 1246    MYR-8256 Phelps_Bay  HWM 2019  2019.5  PB-H-7
## 1247    MYR-8257 Phelps_Bay  HWM 2019  2019.5  PB-H-8
## 1248    MYR-8258 Phelps_Bay  NWM 2019  2019.5 PB-N-10
  smith_geno <- subset(all_lakes, all_lakes$Lake == "Smiths_Bay")
  head(smith_geno)
##      Sample_Code       Lake Taxa Year Year_TP Strain
## 1354    MYR-6935 Smiths_Bay  EWM 2018    2018 MC-E-1
## 1355    MYR-6936 Smiths_Bay  EWM 2018    2018 MC-E-1
## 1356    MYR-6937 Smiths_Bay  EWM 2018    2018 MC-E-1
## 1357    MYR-6939 Smiths_Bay  EWM 2018    2018 MC-E-1
## 1358    MYR-6940 Smiths_Bay  EWM 2018    2018 MC-E-1
## 1359    MYR-7368 Smiths_Bay  EWM 2018    2018 MC-E-1

Analyze Bald Eagle Lake

#1 Graph with y-axis as percent of total sites visited
  #_________________________________________________________________________________________________
  head(eagle)
##     Sample_Code       Lake Taxa Year Year_TP Strain
## 239    MYR-7079 Bald_Eagle  EWM 2018    2018 MC-E-1
## 240    MYR-7080 Bald_Eagle  NWM 2018    2018 BE-N-2
## 241    MYR-7081 Bald_Eagle  NWM 2018    2018 BE-N-2
## 242    MYR-7082 Bald_Eagle  EWM 2018    2018 MC-E-1
## 243    MYR-7083 Bald_Eagle  EWM 2018    2018 MC-E-1
## 244    MYR-7084 Bald_Eagle  EWM 2018    2018 MC-E-1
  eagle_counts <- eagle %>% count(Year_TP,Strain, Taxa)
  eagle
##     Sample_Code       Lake Taxa Year Year_TP Strain
## 239    MYR-7079 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 240    MYR-7080 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 241    MYR-7081 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 242    MYR-7082 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 243    MYR-7083 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 244    MYR-7084 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 245    MYR-7085 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 246    MYR-7086 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 247    MYR-7087 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 248    MYR-7088 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 249    MYR-7089 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 250    MYR-7090 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 251    MYR-7091 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 252    MYR-7092 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 253    MYR-7093 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 254    MYR-7094 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 255    MYR-7095 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 256    MYR-7096 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 257    MYR-7097 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 258    MYR-7098 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 259    MYR-7099 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 260    MYR-7100 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 261    MYR-7101 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 262    MYR-7102 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 263    MYR-7103 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 264    MYR-7104 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 265    MYR-7105 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 266    MYR-7106 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 267    MYR-7107 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 268    MYR-7108 Bald_Eagle  NWM 2018  2018.0 BE-N-4
## 269    MYR-7110 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 270    MYR-7111 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 271    MYR-7112 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 272    MYR-7113 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 273    MYR-7114 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 274    MYR-7115 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 275    MYR-7116 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 276    MYR-7117 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 277    MYR-7118 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 278    MYR-7119 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 279    MYR-7120 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 280    MYR-7187 Bald_Eagle  EWM 2018  2018.5 MC-E-1
## 281    MYR-7188 Bald_Eagle  EWM 2018  2018.5 MC-E-1
## 282    MYR-7189 Bald_Eagle  NWM 2018  2018.5 BE-N-2
## 283    MYR-7190 Bald_Eagle  EWM 2018  2018.5 MC-E-1
## 284    MYR-7191 Bald_Eagle  EWM 2018  2018.5 MC-E-1
## 285    MYR-7192 Bald_Eagle  EWM 2018  2018.5 MC-E-1
## 286    MYR-7193 Bald_Eagle  HWM 2018  2018.5 BE-H-3
## 287    MYR-7194 Bald_Eagle  HWM 2018  2018.5 BE-H-3
## 288    MYR-7195 Bald_Eagle  NWM 2018  2018.5 BE-N-4
## 289    MYR-7196 Bald_Eagle  NWM 2018  2018.5 BE-N-2
## 290    MYR-7197 Bald_Eagle  NWM 2018  2018.5 BE-N-2
## 291    MYR-7198 Bald_Eagle  NWM 2018  2018.5 BE-N-2
## 292    MYR-7199 Bald_Eagle  NWM 2018  2018.5 BE-N-2
## 293    MYR-7200 Bald_Eagle  NWM 2018  2018.5 BE-N-2
## 294    MYR-7201 Bald_Eagle  NWM 2018  2018.5 BE-N-2
## 295    MYR-7202 Bald_Eagle  HWM 2018  2018.5 BE-H-3
## 296    MYR-7764 Bald_Eagle  HWM 2019  2019.0 BE-H-3
## 297    MYR-7765 Bald_Eagle  HWM 2019  2019.0 BE-H-3
## 298    MYR-7766 Bald_Eagle  NWM 2019  2019.0 BE-N-2
## 299    MYR-7767 Bald_Eagle  NWM 2019  2019.0 BE-N-2
## 300    MYR-7768 Bald_Eagle  NWM 2019  2019.0 BE-N-2
## 301    MYR-7769 Bald_Eagle  NWM 2019  2019.0 BE-N-2
## 302    MYR-7770 Bald_Eagle  NWM 2019  2019.0 BE-N-2
## 303    MYR-7771 Bald_Eagle  HWM 2019  2019.0 BE-H-3
## 304    MYR-7773 Bald_Eagle  NWM 2019  2019.0 BE-N-2
## 305    MYR-7774 Bald_Eagle  NWM 2019  2019.0 BE-N-2
## 306    MYR-7775 Bald_Eagle  NWM 2019  2019.0 BE-N-2
## 307    MYR-7776 Bald_Eagle  NWM 2019  2019.0 BE-N-2
## 308    MYR-7777 Bald_Eagle  NWM 2019  2019.0 BE-N-2
## 309    MYR-7778 Bald_Eagle  NWM 2019  2019.0 BE-N-2
## 310    MYR-7779 Bald_Eagle  HWM 2019  2019.0 BE-H-3
## 311    MYR-7781 Bald_Eagle  NWM 2019  2019.0 BE-N-2
## 312    MYR-7782 Bald_Eagle  HWM 2019  2019.0 BE-H-3
## 313    MYR-7783 Bald_Eagle  NWM 2019  2019.0 BE-N-2
## 314    MYR-7784 Bald_Eagle  NWM 2019  2019.0 BE-N-2
## 315    MYR-7848 Bald_Eagle NWM? 2019  2019.5 BE-N-6
## 316    MYR-7850 Bald_Eagle  HWM 2019  2019.5 BE-H-3
## 317    MYR-7851 Bald_Eagle  NWM 2019  2019.5 BE-N-2
## 318    MYR-7852 Bald_Eagle  NWM 2019  2019.5 BE-N-2
## 319    MYR-7853 Bald_Eagle  NWM 2019  2019.5 BE-N-2
## 320    MYR-7854 Bald_Eagle  EWM 2019  2019.5 MC-E-1
## 321    MYR-7855 Bald_Eagle  NWM 2019  2019.5 BE-N-2
## 322    MYR-7883 Bald_Eagle  NWM 2019  2019.5 BE-N-2
## 323    MYR-7885 Bald_Eagle  NWM 2019  2019.5 BE-N-2
## 324    MYR-7886 Bald_Eagle  NWM 2019  2019.5 BE-N-2
## 325    MYR-7887 Bald_Eagle  NWM 2019  2019.5 BE-N-2
## 326    MYR-7888 Bald_Eagle  NWM 2019  2019.5 BE-N-2
## 327    MYR-7889 Bald_Eagle  HWM 2019  2019.5 BE-H-3
## 328    MYR-7890 Bald_Eagle  NWM 2019  2019.5 BE-N-2
## 329    MYR-7891 Bald_Eagle  NWM 2019  2019.5 BE-N-2
## 330    MYR-7893 Bald_Eagle  NWM 2019  2019.5 BE-N-2
## 331    MYR-8623 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 332    MYR-8624 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 333    MYR-8625 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 334    MYR-8626 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 335    MYR-8627 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 336    MYR-8628 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 337    MYR-8629 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 338    MYR-8630 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 339    MYR-8631 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 340    MYR-8632 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 341    MYR-8633 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 342    MYR-8634 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 343    MYR-8635 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 344    MYR-8636 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 345    MYR-8637 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 346    MYR-8638 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 347    MYR-8639 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 348    MYR-8640 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 349    MYR-8641 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 350    MYR-8642 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 351    MYR-8643 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 352    MYR-8644 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 353    MYR-8645 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 354    MYR-8646 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 355    MYR-8647 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 356    MYR-8648 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 357    MYR-8649 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 358    MYR-8650 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 359    MYR-8651 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 360    MYR-8652 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 361    MYR-8653 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 362    MYR-8654 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 363    MYR-8655 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 364    MYR-8656 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 365    MYR-8657 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 366    MYR-8658 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 367    MYR-8659 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 368    MYR-8660 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 369    MYR-8661 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 370    MYR-8662 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 371    MYR-8663 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 372    MYR-8664 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 373    MYR-8665 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 374    MYR-8666 Bald_Eagle  EWM 2018  2018.0 MC-E-1
## 375    MYR-8667 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 376    MYR-8668 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 377    MYR-8669 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 378    MYR-8670 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 379    MYR-8671 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 380    MYR-8672 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 381    MYR-8673 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 382    MYR-8674 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 383    MYR-8675 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 384    MYR-8676 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 385    MYR-8677 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 386    MYR-8678 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 387    MYR-8679 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 388    MYR-8680 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 389    MYR-8681 Bald_Eagle  NWM 2018  2018.0 BE-N-2
## 390    MYR-8682 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 391    MYR-8683 Bald_Eagle  HWM 2018  2018.0 BE-H-3
## 392    MYR-9084 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 393    MYR-9085 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 394    MYR-9086 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 395    MYR-9087 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 396    MYR-9089 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 397    MYR-9091 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 398    MYR-9092 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 399    MYR-9093 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 400    MYR-9095 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 401    MYR-9096 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 402    MYR-9097 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 403    MYR-9098 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 404    MYR-9099 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 405    MYR-9101 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 406    MYR-9102 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 407    MYR-9104 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 408    MYR-9106 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 409    MYR-9109 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 410    MYR-9110 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 411    MYR-9111 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 412    MYR-9112 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 413    MYR-9113 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 414    MYR-9114 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 415    MYR-9116 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 416    MYR-9117 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 417    MYR-9118 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 418    MYR-9119 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 419    MYR-9120 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 420    MYR-9122 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 421    MYR-9123 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 422    MYR-9125 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 423    MYR-9126 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 424    MYR-9127 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 425    MYR-9129 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 426    MYR-9130 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 427    MYR-9131 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 428    MYR-9132 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 429    MYR-9134 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 430    MYR-9137 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 431    MYR-9138 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 432    MYR-9139 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 433    MYR-9140 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 434    MYR-9519 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 435    MYR-9520 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 436    MYR-9522 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 437    MYR-9523 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 438    MYR-9525 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 439    MYR-9526 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 440    MYR-9527 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 441    MYR-9528 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 442    MYR-9727 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 443    MYR-9729 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 444    MYR-9731 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 445    MYR-9732 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 446    MYR-9733 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 447    MYR-9734 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 448    MYR-9736 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 449    MYR-9737 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 450    MYR-9738 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 451    MYR-9739 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 452    MYR-9742 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 453    MYR-9744 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 454    MYR-9745 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 455    MYR-9746 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 456    MYR-9749 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 457    MYR-9750 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 458    MYR-9752 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 459    MYR-9753 Bald_Eagle  NWM 2020  2020.0 BE-N-2
## 460    MYR-9755 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 461    MYR-9758 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 462    MYR-9759 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 463    MYR-9760 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 464    MYR-9761 Bald_Eagle  NWM 2020  2020.5 BE-N-2
## 465    MYR-9088 Bald_Eagle  HWM 2020  2020.5 BE-H-3
## 466    MYR-9090 Bald_Eagle  HWM 2020  2020.5 BE-H-3
## 467    MYR-9094 Bald_Eagle  HWM 2020  2020.5 BE-H-3
## 468    MYR-9100 Bald_Eagle  HWM 2020  2020.5 BE-H-3
## 469    MYR-9103 Bald_Eagle  HWM 2020  2020.5 BE-H-3
## 470    MYR-9105 Bald_Eagle  HWM 2020  2020.5 BE-H-3
## 471    MYR-9115 Bald_Eagle  HWM 2020  2020.0 BE-H-3
## 472    MYR-9121 Bald_Eagle  HWM 2020  2020.0 BE-H-3
## 473    MYR-9124 Bald_Eagle  HWM 2020  2020.0 BE-H-3
## 474    MYR-9128 Bald_Eagle  HWM 2020  2020.0 BE-H-3
## 475    MYR-9133 Bald_Eagle  HWM 2020  2020.0 BE-H-3
## 476    MYR-9136 Bald_Eagle  HWM 2020  2020.0 BE-H-3
## 477    MYR-9141 Bald_Eagle  HWM 2020  2020.0 BE-H-3
## 478    MYR-9518 Bald_Eagle  HWM 2020  2020.5 BE-H-3
## 479    MYR-9521 Bald_Eagle  HWM 2020  2020.5 BE-H-3
## 480    MYR-9524 Bald_Eagle  HWM 2020  2020.5 BE-H-3
## 481    MYR-9529 Bald_Eagle  HWM 2020  2020.5 BE-H-3
## 482    MYR-9725 Bald_Eagle  HWM 2020  2020.0 BE-H-3
## 483    MYR-9726 Bald_Eagle  HWM 2020  2020.0 BE-H-3
## 484    MYR-9728 Bald_Eagle  HWM 2020  2020.0 BE-H-3
## 485    MYR-9740 Bald_Eagle  HWM 2020  2020.0 BE-H-3
## 486    MYR-9741 Bald_Eagle  HWM 2020  2020.0 BE-H-3
## 487    MYR-9743 Bald_Eagle  HWM 2020  2020.0 BE-H-3
## 488    MYR-9747 Bald_Eagle  HWM 2020  2020.0 BE-H-3
## 489    MYR-9748 Bald_Eagle  HWM 2020  2020.0 BE-H-3
## 490    MYR-9751 Bald_Eagle  HWM 2020  2020.0 BE-H-3
## 491    MYR-9754 Bald_Eagle  HWM 2020  2020.5 BE-H-3
## 492    MYR-9756 Bald_Eagle  HWM 2020  2020.5 BE-H-3
## 493    MYR-9757 Bald_Eagle  HWM 2020  2020.5 BE-H-3
## 494    MYR-9762 Bald_Eagle  HWM 2020  2020.5 BE-H-3
## 495    MYR-9764 Bald_Eagle  HWM 2020  2020.5 BE-H-3
## 496    MYR-9765 Bald_Eagle  HWM 2020  2020.5 BE-H-3
## 497    MYR-9730 Bald_Eagle  NWM 2020  2020.0 BE-N-4
## 498    MYR-9735 Bald_Eagle  NWM 2020  2020.0 BE-N-4
## 499    MYR-9108 Bald_Eagle NWM? 2020  2020.5 BE-N-5
## 500    MYR-9763 Bald_Eagle NWM? 2020  2020.5 BE-N-5
## 501    MYR-9135 Bald_Eagle NWM? 2020  2020.0 BE-N-6
  eagle_counts$Percent_Ocupied <- ((eagle_counts$n)/151)*100
  
  eagle_plot_Percent_Ocupied <- eagle_counts %>%
    ggplot()+geom_line(aes(x=Year_TP,y=Percent_Ocupied,col=Strain))+geom_point(aes(x=Year_TP,y=Percent_Ocupied, col=Strain), size = 2) 
  eagle_PO_annotated <- print(eagle_plot_Percent_Ocupied + 
                                ggtitle("A. Bald Eagle") + 
                                theme_light() +
                                geom_vline(xintercept = 2018.25, linetype="dashed", color = "red") +
                                guides(col=guide_legend(ncol=1,byrow=TRUE)) + 
                                labs(y="Percent of Sampled Sites (%)", x = "Year") )   

  #2) CHI SQUARED ANALYSIS WITHIN YEAR
  #_________________________________________________________________________________________________
    set.seed(1025)
    head(eagle)
##     Sample_Code       Lake Taxa Year Year_TP Strain
## 239    MYR-7079 Bald_Eagle  EWM 2018    2018 MC-E-1
## 240    MYR-7080 Bald_Eagle  NWM 2018    2018 BE-N-2
## 241    MYR-7081 Bald_Eagle  NWM 2018    2018 BE-N-2
## 242    MYR-7082 Bald_Eagle  EWM 2018    2018 MC-E-1
## 243    MYR-7083 Bald_Eagle  EWM 2018    2018 MC-E-1
## 244    MYR-7084 Bald_Eagle  EWM 2018    2018 MC-E-1
    eagle$Strain <- as.factor(eagle$Strain)
    eagle$Year_TP_F <- as.factor(eagle$Year_TP)
    eagle$Year_F <- as.factor(eagle$Year)
    
    eagle_2018 <- eagle[eagle$Year == 2018 , ]
    eagle_2019 <- eagle[eagle$Year == 2019 , ]
    eagle_2020 <- eagle[eagle$Year == 2020 , ]
    
    #CHI SQUARED 2018 
    eagle_chi_geno_2018 <- chisq.test(eagle_2018$Strain, eagle_2018$Year_TP_F, correct = TRUE,
                                      p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                      simulate.p.value = TRUE, B = 2000)
    eagle_chi_geno_2018$p.value
## [1] 0.133933
    #CHI SQUARED 2019 
    eagle_chi_geno_2019 <- chisq.test(eagle_2019$Strain, eagle_2019$Year_TP_F, correct = TRUE,
                                      p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                      simulate.p.value = TRUE, B = 2000)
    eagle_chi_geno_2019$p.value
## [1] 0.3558221
    #CHI SQUARED 2020
    eagle_chi_geno_2020 <- chisq.test(eagle_2020$Strain, eagle_2020$Year_TP_F, correct = TRUE,
                                      p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                      simulate.p.value = TRUE, B = 2000)
    eagle_chi_geno_2020$p.value
## [1] 0.2648676
  #3) CHI SQUARED ANALYSIS BTWN YEARS
  #_________________________________________________________________________________________________
    head(eagle)
##     Sample_Code       Lake Taxa Year Year_TP Strain Year_TP_F Year_F
## 239    MYR-7079 Bald_Eagle  EWM 2018    2018 MC-E-1      2018   2018
## 240    MYR-7080 Bald_Eagle  NWM 2018    2018 BE-N-2      2018   2018
## 241    MYR-7081 Bald_Eagle  NWM 2018    2018 BE-N-2      2018   2018
## 242    MYR-7082 Bald_Eagle  EWM 2018    2018 MC-E-1      2018   2018
## 243    MYR-7083 Bald_Eagle  EWM 2018    2018 MC-E-1      2018   2018
## 244    MYR-7084 Bald_Eagle  EWM 2018    2018 MC-E-1      2018   2018
    tally(~Year_F, data = eagle)
## Year_F
## 2018 2019 2020 
##  118   35  110
    eagle$Strain <- as.factor(eagle$Strain)
    eagle$Year_TP_F <- as.factor(eagle$Year_TP_F)
    eagle$Year_F <- as.factor(eagle$Year)
    
    time_one <- c("2018", "2019", "2020")
    eagle_btwn <- eagle[eagle$Year_TP_F %in% time_one , ]
    eagle_btwn <- droplevels(eagle_btwn)
    tally(~Year_TP_F, data = eagle_btwn)
## Year_TP_F
## 2018 2019 2020 
##  102   19   59
    eagle_btwn_18_19 <-eagle_btwn[eagle_btwn$Year == 2018 | eagle_btwn$Year == 2019 , ] 
    eagle_btwn_18_19 <- droplevels(eagle_btwn_18_19)
    tally(~Year, data = eagle_btwn_18_19)
## Year
## 2018 2019 
##  102   19
    eagle_btwn_18_19$Strain <- as.factor(eagle_btwn_18_19$Strain)
    eagle_btwn_18_19$Year_F <- as.factor(eagle_btwn_18_19$Year)
    
    
    eagle_btwn_19_20 <-eagle_btwn[eagle_btwn$Year == 2019 | eagle_btwn$Year == 2020 , ] 
    eagle_btwn_19_20 <- droplevels(eagle_btwn_19_20)
    tally(~Year_TP_F, data = eagle_btwn_19_20)
## Year_TP_F
## 2019 2020 
##   19   59
    eagle_btwn_19_20$Strain <- as.factor(eagle_btwn_19_20$Strain)
    eagle_btwn_19_20$Year_F <- as.factor(eagle_btwn_19_20$Year)
    
    #CHI SQUARED COMPARING 2018 TO 2019
    eagle_chi_btwn_18_19 <- chisq.test(eagle_btwn_18_19$Strain, eagle_btwn_18_19$Year_F, correct = TRUE,
                                       p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                       simulate.p.value = TRUE, B = 2000)
    eagle_chi_btwn_18_19$p.value
## [1] 0.0009995002
    #CHI SQUARED COMPARING 2019 TO 2020
    eagle_chi_btwn_19_20 <- chisq.test(eagle_btwn_19_20$Strain, eagle_btwn_19_20$Year_TP_F, correct = TRUE,
                                       p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                       simulate.p.value = TRUE, B = 2000)
    eagle_chi_btwn_19_20$p.value
## [1] 1
  #4) ALL THREE YEARS (first t1 to last t2)
  #_________________________________________________________________________________________________
    head(eagle)
##     Sample_Code       Lake Taxa Year Year_TP Strain Year_TP_F Year_F
## 239    MYR-7079 Bald_Eagle  EWM 2018    2018 MC-E-1      2018   2018
## 240    MYR-7080 Bald_Eagle  NWM 2018    2018 BE-N-2      2018   2018
## 241    MYR-7081 Bald_Eagle  NWM 2018    2018 BE-N-2      2018   2018
## 242    MYR-7082 Bald_Eagle  EWM 2018    2018 MC-E-1      2018   2018
## 243    MYR-7083 Bald_Eagle  EWM 2018    2018 MC-E-1      2018   2018
## 244    MYR-7084 Bald_Eagle  EWM 2018    2018 MC-E-1      2018   2018
    tally(~Year_TP_F, data = eagle)
## Year_TP_F
##   2018 2018.5   2019 2019.5   2020 2020.5 
##    102     16     19     16     59     51
    list_three_yr <- c( 2018, 2020.5 )
    eagle_three_yr_2018 <- as.data.frame(eagle[eagle$Year_TP_F == 2018 , ])
    eagle_three_yr_2020 <- as.data.frame(eagle[eagle$Year_TP_F == 2020.5 , ])
    eagle_three_yr <- rbind(eagle_three_yr_2018, eagle_three_yr_2020)
    
    eagle_chi_three_yr <- chisq.test(eagle_three_yr$Strain, eagle_three_yr$Year_TP_F, correct = TRUE,
                                     p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                     simulate.p.value = TRUE, B = 2000)
    eagle_chi_three_yr
## 
##  Pearson's Chi-squared test with simulated p-value (based on 2000
##  replicates)
## 
## data:  eagle_three_yr$Strain and eagle_three_yr$Year_TP_F
## X-squared = 34.386, df = NA, p-value = 0.0004998

Analyze Christmas Lake

#1 Graph with y-axis as percent of total sites visited
  #_________________________________________________________________________________________________
      head(christmas)
##   Sample_Code      Lake Taxa Year Year_TP Strain
## 1    MYR-6915 Christmas  EWM 2018    2018 MC-E-1
## 2    MYR-6916 Christmas  EWM 2018    2018 MC-E-1
## 3    MYR-6917 Christmas  NWM 2018    2018 CH-N-1
## 4    MYR-6918 Christmas  EWM 2018    2018 MC-E-1
## 5    MYR-6919 Christmas  NWM 2018    2018 CH-N-1
## 6    MYR-6920 Christmas  NWM 2018    2018 CH-N-1
      christmas_counts <- christmas %>% count(Year_TP,Strain, Taxa)
      christmas_counts
##    Year_TP Strain Taxa  n
## 1   2018.0 CH-N-1  NWM 18
## 2   2018.0 CH-N-3  NWM  2
## 3   2018.0 MC-E-1  EWM 41
## 4   2018.5 CH-N-1  NWM 19
## 5   2018.5 CH-N-3  NWM  3
## 6   2018.5 MC-E-1  EWM 21
## 7   2019.0 CH-N-1  NWM 19
## 8   2019.0 MC-E-1  EWM 20
## 9   2019.5 CH-N-1  NWM 26
## 10  2019.5 CH-N-3  NWM  4
## 11  2019.5 MC-E-1  EWM 13
## 12  2020.0 CH-N-1  NWM 36
## 13  2020.0 CH-N-3  NWM  2
## 14  2020.0 MC-E-1  EWM 14
      christmas_counts$Percent_Ocupied <- ((christmas_counts$n)/113)*100
      
      christmas_plot_Percent_Ocupied <- christmas_counts %>%
        ggplot()+geom_line(aes(x=Year_TP,y=Percent_Ocupied,col=Strain))+geom_point(aes(x=Year_TP,y=Percent_Ocupied, col=Strain), size = 2) 
      Christmas_PO_annotated <- print(christmas_plot_Percent_Ocupied + 
                                        ggtitle("H. Christmas") + 
                                        theme_light() +
                                        ylim(0, 40) +
                                        guides(col=guide_legend(ncol=1,byrow=TRUE)) + 
                                        labs(y="Percent of Sampled Sites (%)", x = "Year") )   

      Christmas_PO_annotated

    #2) CHI SQUARED ANALYSIS WITHIN YEAR
    #_________________________________________________________________________________________________
      set.seed(1025)
      head(christmas)
##   Sample_Code      Lake Taxa Year Year_TP Strain
## 1    MYR-6915 Christmas  EWM 2018    2018 MC-E-1
## 2    MYR-6916 Christmas  EWM 2018    2018 MC-E-1
## 3    MYR-6917 Christmas  NWM 2018    2018 CH-N-1
## 4    MYR-6918 Christmas  EWM 2018    2018 MC-E-1
## 5    MYR-6919 Christmas  NWM 2018    2018 CH-N-1
## 6    MYR-6920 Christmas  NWM 2018    2018 CH-N-1
      christmas$Strain <- as.factor(christmas$Strain)
      christmas$Year_TP_F <- as.factor(christmas$Year_TP)
      christmas$Year_F <- as.factor(christmas$Year)
      
      christmas_2018 <- christmas[christmas$Year == 2018 , ]
      christmas_2019 <- christmas[christmas$Year == 2019 , ]
      christmas_2020 <- christmas[christmas$Year == 2020 , ]
      
      #CHI SQUARED 2018 
      head(christmas)
##   Sample_Code      Lake Taxa Year Year_TP Strain Year_TP_F Year_F
## 1    MYR-6915 Christmas  EWM 2018    2018 MC-E-1      2018   2018
## 2    MYR-6916 Christmas  EWM 2018    2018 MC-E-1      2018   2018
## 3    MYR-6917 Christmas  NWM 2018    2018 CH-N-1      2018   2018
## 4    MYR-6918 Christmas  EWM 2018    2018 MC-E-1      2018   2018
## 5    MYR-6919 Christmas  NWM 2018    2018 CH-N-1      2018   2018
## 6    MYR-6920 Christmas  NWM 2018    2018 CH-N-1      2018   2018
      christmas$Year_TP_F <- as.factor(christmas$Year_TP)
      
      christmas_chi_geno_2018 <- chisq.test(christmas_2018$Strain, christmas_2018$Year_TP_F, correct = TRUE,
                                            p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                            simulate.p.value = TRUE, B = 2000)
      christmas_chi_geno_2018$p.value
## [1] 0.183908
      #CHI SQUARED 2019
      christmas_chi_geno_2019 <- chisq.test(christmas_2019$Strain, christmas_2019$Year_TP_F, correct = TRUE,
                                            p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                            simulate.p.value = TRUE, B = 2000)
      christmas_chi_geno_2019$p.value
## [1] 0.04197901
    #3) CHI SQUARED ANALYSIS BTWN YEARS
    #_________________________________________________________________________________________________
      head(christmas)
##   Sample_Code      Lake Taxa Year Year_TP Strain Year_TP_F Year_F
## 1    MYR-6915 Christmas  EWM 2018    2018 MC-E-1      2018   2018
## 2    MYR-6916 Christmas  EWM 2018    2018 MC-E-1      2018   2018
## 3    MYR-6917 Christmas  NWM 2018    2018 CH-N-1      2018   2018
## 4    MYR-6918 Christmas  EWM 2018    2018 MC-E-1      2018   2018
## 5    MYR-6919 Christmas  NWM 2018    2018 CH-N-1      2018   2018
## 6    MYR-6920 Christmas  NWM 2018    2018 CH-N-1      2018   2018
      tally(~Year_F, data = christmas)
## Year_F
## 2018 2019 2020 
##  104   82   52
      christmas$Strain <- as.factor(christmas$Strain)
      christmas$Year_TP_F <- as.factor(christmas$Year_TP_F)
      christmas$Year_F <- as.factor(christmas$Year)
      
      time_one <- c("2018", "2019", "2020")
      christmas_btwn <- christmas[christmas$Year_TP_F %in% time_one , ]
      christmas_btwn <- droplevels(christmas_btwn)
      tally(~Year_TP_F, data = christmas_btwn)
## Year_TP_F
## 2018 2019 2020 
##   61   39   52
      christmas_btwn_18_19 <-christmas_btwn[christmas_btwn$Year == 2018 | christmas_btwn$Year == 2019 , ] 
      christmas_btwn_18_19 <- droplevels(christmas_btwn_18_19)
      tally(~Year, data = christmas_btwn_18_19)
## Year
## 2018 2019 
##   61   39
      christmas_btwn_18_19$Strain <- as.factor(christmas_btwn_18_19$Strain)
      christmas_btwn_18_19$Year_F <- as.factor(christmas_btwn_18_19$Year)
      
      
      christmas_btwn_19_20 <-christmas_btwn[christmas_btwn$Year == 2019 | christmas_btwn$Year == 2020 , ] 
      christmas_btwn_19_20 <- droplevels(christmas_btwn_19_20)
      tally(~Year_TP_F, data = christmas_btwn_19_20)
## Year_TP_F
## 2019 2020 
##   39   52
      christmas_btwn_19_20$Strain <- as.factor(christmas_btwn_19_20$Strain)
      christmas_btwn_19_20$Year_F <- as.factor(christmas_btwn_19_20$Year)
      
      #CHI SQUARED COMPARING 2018 TO 2019
      christmas_chi_btwn_18_19 <- chisq.test(christmas_btwn_18_19$Strain, christmas_btwn_18_19$Year_F, correct = TRUE,
                                             p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                             simulate.p.value = TRUE, B = 2000)
      christmas_chi_btwn_18_19$p.value
## [1] 0.07846077
      #CHI SQUARED COMPARING 2019 TO 2020
      christmas_chi_btwn_19_20 <- chisq.test(christmas_btwn_19_20$Strain, christmas_btwn_19_20$Year_TP_F, correct = TRUE,
                                             p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                             simulate.p.value = TRUE, B = 2000)
      christmas_chi_btwn_19_20$p.value
## [1] 0.01999
    #4) ALL THREE YEARS (first t1 to last t2)
    #_________________________________________________________________________________________________
    
      head(christmas)
##   Sample_Code      Lake Taxa Year Year_TP Strain Year_TP_F Year_F
## 1    MYR-6915 Christmas  EWM 2018    2018 MC-E-1      2018   2018
## 2    MYR-6916 Christmas  EWM 2018    2018 MC-E-1      2018   2018
## 3    MYR-6917 Christmas  NWM 2018    2018 CH-N-1      2018   2018
## 4    MYR-6918 Christmas  EWM 2018    2018 MC-E-1      2018   2018
## 5    MYR-6919 Christmas  NWM 2018    2018 CH-N-1      2018   2018
## 6    MYR-6920 Christmas  NWM 2018    2018 CH-N-1      2018   2018
      tally(~Year_TP_F, data = christmas)
## Year_TP_F
##   2018 2018.5   2019 2019.5   2020 
##     61     43     39     43     52
      christmas_three_yr_2018 <- as.data.frame(christmas[christmas$Year_TP_F == 2018 , ])
      christmas_three_yr_2020 <- as.data.frame(christmas[christmas$Year_TP_F == 2020 , ])
      christmas_three_yr <- rbind(christmas_three_yr_2018, christmas_three_yr_2020)
      
      christmas_chi_three_yr <- chisq.test(christmas_three_yr$Strain, christmas_three_yr$Year_TP_F, correct = TRUE,
                                           p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                           simulate.p.value = TRUE, B = 2000)
      
      christmas_chi_three_yr$p.value
## [1] 0.0004997501

Analyze Grays Bay of Lake Minnetonka

#1 Graph with y-axis as percent of total sites visited
    #_________________________________________________________________________________________________
      head(grays_bay)
##     Sample_Code      Lake Taxa Year Year_TP Strain
## 502    MYR-7276 Grays_Bay  HWM 2018    2018 MC-H-7
## 503    MYR-7283 Grays_Bay  HWM 2018    2018 MC-H-7
## 504    MYR-7284 Grays_Bay  HWM 2018    2018 MC-H-7
## 505    MYR-7288 Grays_Bay  HWM 2018    2018 MC-H-7
## 506    MYR-7290 Grays_Bay  HWM 2018    2018 MC-H-7
## 507    MYR-7295 Grays_Bay  HWM 2018    2018 MC-H-7
      #grays_bay$Year_TP <- grays_bay$Time_Point
      grays_bay_counts <- grays_bay %>% count(Year_TP,Strain, Taxa)
      grays_bay_counts
##    Year_TP   Strain Taxa  n
## 1   2018.0  MC-H-12  HWM 13
## 2   2018.0 MC-H-136  HWM  1
## 3   2018.0 MC-H-137  HWM  2
## 4   2018.0 MC-H-138  HWM  1
## 5   2018.0   MC-H-7  HWM  6
## 6   2018.5  MC-H-12  HWM 19
## 7   2018.5 MC-H-136  HWM  1
## 8   2018.5 MC-H-137  HWM  4
## 9   2018.5 MC-H-138  HWM  3
## 10  2018.5   MC-H-7  HWM  4
## 11  2019.0  MC-H-12  HWM 30
## 12  2019.0 MC-H-136  HWM  1
## 13  2019.0 MC-H-137  HWM  4
## 14  2019.0   MC-H-7  HWM  7
## 15  2019.5  MC-H-12  HWM 31
## 16  2019.5 MC-H-136  HWM  1
## 17  2019.5 MC-H-137  HWM  3
## 18  2019.5   MC-H-7  HWM  9
## 19  2020.0  MC-H-12  HWM 49
## 20  2020.0 MC-H-136  HWM  2
## 21  2020.0 MC-H-137  HWM  4
## 22  2020.0 MC-H-138  HWM  1
## 23  2020.0   MC-H-7  HWM 10
## 24  2020.5  MC-H-12  HWM 18
## 25  2020.5 MC-H-138  HWM  2
## 26  2020.5   MC-H-7  HWM  2
      grays_bay_counts$Percent_Ocupied <- ((grays_bay_counts$n)/125)*100
      grays_bay_counts
##    Year_TP   Strain Taxa  n Percent_Ocupied
## 1   2018.0  MC-H-12  HWM 13            10.4
## 2   2018.0 MC-H-136  HWM  1             0.8
## 3   2018.0 MC-H-137  HWM  2             1.6
## 4   2018.0 MC-H-138  HWM  1             0.8
## 5   2018.0   MC-H-7  HWM  6             4.8
## 6   2018.5  MC-H-12  HWM 19            15.2
## 7   2018.5 MC-H-136  HWM  1             0.8
## 8   2018.5 MC-H-137  HWM  4             3.2
## 9   2018.5 MC-H-138  HWM  3             2.4
## 10  2018.5   MC-H-7  HWM  4             3.2
## 11  2019.0  MC-H-12  HWM 30            24.0
## 12  2019.0 MC-H-136  HWM  1             0.8
## 13  2019.0 MC-H-137  HWM  4             3.2
## 14  2019.0   MC-H-7  HWM  7             5.6
## 15  2019.5  MC-H-12  HWM 31            24.8
## 16  2019.5 MC-H-136  HWM  1             0.8
## 17  2019.5 MC-H-137  HWM  3             2.4
## 18  2019.5   MC-H-7  HWM  9             7.2
## 19  2020.0  MC-H-12  HWM 49            39.2
## 20  2020.0 MC-H-136  HWM  2             1.6
## 21  2020.0 MC-H-137  HWM  4             3.2
## 22  2020.0 MC-H-138  HWM  1             0.8
## 23  2020.0   MC-H-7  HWM 10             8.0
## 24  2020.5  MC-H-12  HWM 18            14.4
## 25  2020.5 MC-H-138  HWM  2             1.6
## 26  2020.5   MC-H-7  HWM  2             1.6
      grays_bay_plot_Percent_Ocupied <- grays_bay_counts %>%
        ggplot()+geom_line(aes(x=Year_TP,y=Percent_Ocupied,col=Strain))+geom_point(aes(x=Year_TP,y=Percent_Ocupied, col=Strain), size = 2) 
      grays_PO_annotated <- print(grays_bay_plot_Percent_Ocupied + 
                                    ggtitle("B. Grays Bay") + 
                                    theme_light() +
                                    geom_vline(xintercept = 2018.25, linetype="dashed", color = "red") +
                                    geom_vline(xintercept = 2019.25, linetype="dashed", color = "red") +
                                    geom_vline(xintercept = 2020.25, linetype="dashed", color = "red") +
                                    guides(col=guide_legend(ncol=1,byrow=TRUE)) + 
                                    labs(y="Percent of Sampled Sites (%)", x = "Year") )   

      grays_PO_annotated

    #2) CHI SQUARED ANALYSIS WITHIN YEAR
    #_________________________________________________________________________________________________
      head(grays_bay)
##     Sample_Code      Lake Taxa Year Year_TP Strain
## 502    MYR-7276 Grays_Bay  HWM 2018    2018 MC-H-7
## 503    MYR-7283 Grays_Bay  HWM 2018    2018 MC-H-7
## 504    MYR-7284 Grays_Bay  HWM 2018    2018 MC-H-7
## 505    MYR-7288 Grays_Bay  HWM 2018    2018 MC-H-7
## 506    MYR-7290 Grays_Bay  HWM 2018    2018 MC-H-7
## 507    MYR-7295 Grays_Bay  HWM 2018    2018 MC-H-7
      grays_bay$Genotype <- as.factor(grays_bay$Strain)
      grays_bay$Year_TP_F <- as.factor(grays_bay$Year_TP)
      grays_bay$Year_F <- as.factor(grays_bay$Year)
      
      grays_bay_2018 <- grays_bay[grays_bay$Year == 2018 , ]
      grays_bay_2019 <- grays_bay[grays_bay$Year == 2019 , ]
      grays_bay_2020 <- grays_bay[grays_bay$Year == 2020 , ]
      
      grays_bay$Year_TP_F <- as.factor(grays_bay$Year_TP)
      
      #CHI SQUARED 2018
      grays_bay_chi_geno_2018 <- chisq.test(grays_bay_2018$Strain, grays_bay_2018$Year_TP_F, correct = TRUE,
                                            p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                            simulate.p.value = TRUE, B = 2000)
      grays_bay_chi_geno_2018$p.value
## [1] 0.7876062
      #CHI SQUARED 2019 
      grays_bay_chi_geno_2019 <- chisq.test(grays_bay_2019$Strain, grays_bay_2019$Year_TP_F, correct = TRUE,
                                            p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                            simulate.p.value = TRUE, B = 2000)
      grays_bay_chi_geno_2019$p.value
## [1] 0.9365317
      #CHI SQUARED 2020 
      grays_bay_chi_geno_2020 <- chisq.test(grays_bay_2020$Strain, grays_bay_2020$Year_TP_F, correct = TRUE,
                                            p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                            simulate.p.value = TRUE, B = 2000)
      grays_bay_chi_geno_2020$p.value
## [1] 0.2183908
    #3) CHI SQUARED ANALYSIS BTWN YEARS
    #_________________________________________________________________________________________________
      head(grays_bay)
##     Sample_Code      Lake Taxa Year Year_TP Strain Genotype Year_TP_F Year_F
## 502    MYR-7276 Grays_Bay  HWM 2018    2018 MC-H-7   MC-H-7      2018   2018
## 503    MYR-7283 Grays_Bay  HWM 2018    2018 MC-H-7   MC-H-7      2018   2018
## 504    MYR-7284 Grays_Bay  HWM 2018    2018 MC-H-7   MC-H-7      2018   2018
## 505    MYR-7288 Grays_Bay  HWM 2018    2018 MC-H-7   MC-H-7      2018   2018
## 506    MYR-7290 Grays_Bay  HWM 2018    2018 MC-H-7   MC-H-7      2018   2018
## 507    MYR-7295 Grays_Bay  HWM 2018    2018 MC-H-7   MC-H-7      2018   2018
      tally(~Year_F, data = grays_bay)
## Year_F
## 2018 2019 2020 
##   54   86   88
      grays_bay$Strain <- as.factor(grays_bay$Strain)
      grays_bay$Year_TP_F <- as.factor(grays_bay$Year_TP_F)
      grays_bay$Year_F <- as.factor(grays_bay$Year)
      
      time_one <- c("2018", "2019", "2020")
      grays_bay_btwn <- grays_bay[grays_bay$Year_TP_F %in% time_one , ]
      grays_bay_btwn <- droplevels(grays_bay_btwn)
      tally(~Year_TP_F, data = grays_bay_btwn)
## Year_TP_F
## 2018 2019 2020 
##   23   42   66
      grays_bay_btwn_18_19 <-grays_bay_btwn[grays_bay_btwn$Year == 2018 | grays_bay_btwn$Year == 2019 , ] 
      grays_bay_btwn_18_19 <- droplevels(grays_bay_btwn_18_19)
      tally(~Year, data = grays_bay_btwn_18_19)
## Year
## 2018 2019 
##   23   42
      grays_bay_btwn_18_19$Strain <- as.factor(grays_bay_btwn_18_19$Strain)
      grays_bay_btwn_18_19$Year_F <- as.factor(grays_bay_btwn_18_19$Year)
      
      
      grays_bay_btwn_19_20 <-grays_bay_btwn[grays_bay_btwn$Year == 2019 | grays_bay_btwn$Year == 2020 , ] 
      grays_bay_btwn_19_20 <- droplevels(grays_bay_btwn_19_20)
      tally(~Year_TP_F, data = grays_bay_btwn_19_20)
## Year_TP_F
## 2019 2020 
##   42   66
      grays_bay_btwn_19_20$Strain <- as.factor(grays_bay_btwn_19_20$Strain)
      grays_bay_btwn_19_20$Year_F <- as.factor(grays_bay_btwn_19_20$Year)
      
      #CHI SQUARED COMPARING 2018 TO 2019
      grays_bay_chi_btwn_18_19 <- chisq.test(grays_bay_btwn_18_19$Strain, grays_bay_btwn_18_19$Year_F, correct = TRUE,
                                             p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                             simulate.p.value = TRUE, B = 2000)
      grays_bay_chi_btwn_18_19$p.value
## [1] 0.5682159
      #CHI SQUARED COMPARING 2019 TO 2020 
      grays_bay_chi_btwn_19_20 <- chisq.test(grays_bay_btwn_19_20$Strain, grays_bay_btwn_19_20$Year_TP_F, correct = TRUE,
                                             p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                             simulate.p.value = TRUE, B = 2000)
      grays_bay_chi_btwn_19_20$p.value
## [1] 0.9635182
    #4) ALL THREE YEARS (first t1 to last t2)
    #_________________________________________________________________________________________________
      
      head(grays_bay)
##     Sample_Code      Lake Taxa Year Year_TP Strain Genotype Year_TP_F Year_F
## 502    MYR-7276 Grays_Bay  HWM 2018    2018 MC-H-7   MC-H-7      2018   2018
## 503    MYR-7283 Grays_Bay  HWM 2018    2018 MC-H-7   MC-H-7      2018   2018
## 504    MYR-7284 Grays_Bay  HWM 2018    2018 MC-H-7   MC-H-7      2018   2018
## 505    MYR-7288 Grays_Bay  HWM 2018    2018 MC-H-7   MC-H-7      2018   2018
## 506    MYR-7290 Grays_Bay  HWM 2018    2018 MC-H-7   MC-H-7      2018   2018
## 507    MYR-7295 Grays_Bay  HWM 2018    2018 MC-H-7   MC-H-7      2018   2018
      tally(~Year_TP_F, data = grays_bay)
## Year_TP_F
##   2018 2018.5   2019 2019.5   2020 2020.5 
##     23     31     42     44     66     22
      grays_bay_three_yr_2018 <- as.data.frame(grays_bay[grays_bay$Year_TP_F == 2018 , ])
      grays_bay_three_yr_2020 <- as.data.frame(grays_bay[grays_bay$Year_TP_F == 2020.5 , ])
      grays_bay_three_yr <- rbind(grays_bay_three_yr_2018, grays_bay_three_yr_2020)
      
      grays_bay_chi_three_yr <- chisq.test(grays_bay_three_yr$Strain, grays_bay_three_yr$Year_TP_F, correct = TRUE,
                                           p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                           simulate.p.value = TRUE, B = 2000)
      grays_bay_chi_three_yr
## 
##  Pearson's Chi-squared test with simulated p-value (based on 2000
##  replicates)
## 
## data:  grays_bay_three_yr$Strain and grays_bay_three_yr$Year_TP_F
## X-squared = 6.1206, df = NA, p-value = 0.1639

Analyze Ham Lake

#1 Graph with y-axis as percent of total sites visited
      #_________________________________________________________________________________________________
        names(ham)
## [1] "Sample_Code" "Lake"        "Taxa"        "Year"        "Year_TP"    
## [6] "Strain"
        ham_counts <- ham %>% count(Year_TP,Strain, Taxa)
        ham_counts
##    Year_TP  Strain Taxa  n
## 1   2018.0 HM-H-14  HWM 31
## 2   2018.0 HM-N-15  NWM  3
## 3   2018.5 HM-H-14  HWM 48
## 4   2018.5 HM-N-15  NWM  1
## 5   2019.0 HM-H-14  HWM  6
## 6   2019.0 HM-N-15  NWM  6
## 7   2019.5 HM-H-14  HWM 18
## 8   2019.5 HM-N-15  NWM  6
## 9   2020.0 HM-H-14  HWM 17
## 10  2020.0 HM-N-15  NWM  5
## 11  2020.5 HM-H-14  HWM 42
## 12  2020.5 HM-N-15  NWM  9
        is.data.frame(ham_counts)
## [1] TRUE
        ham_counts$Percent_Ocupied <- ((ham_counts$n)/147)*100
        ham_counts$Strain <- ham_counts$Strain
        
        ham_plot_Percent_Ocupied <- ham_counts %>%
          ggplot()+geom_line(aes(x=Year_TP,y=Percent_Ocupied,col=Strain))+geom_point(aes(x=Year_TP,y=Percent_Ocupied, col=Strain), size = 2) 
        Ham_PO_annotated <- print(ham_plot_Percent_Ocupied + 
                                    ggtitle("C. Ham") + 
                                    theme_light() +
                                    geom_vline(xintercept = 2018.65, linetype="dashed", color = "red") +
                                    guides(col=guide_legend(ncol=1,byrow=TRUE)) + 
                                    labs(y="Percent of Sampled Sites (%)", x = "Year") )  

        Ham_PO_annotated

      #2) CHI SQUARED ANALYSIS WITHIN YEAR
      #_________________________________________________________________________________________________
        set.seed(1025) 
        head(ham)
##     Sample_Code Lake Taxa Year Year_TP  Strain
## 730    MYR-7166  Ham  HWM 2018  2018.5 HM-H-14
## 731    MYR-7167  Ham  HWM 2018  2018.5 HM-H-14
## 732    MYR-7168  Ham  HWM 2018  2018.5 HM-H-14
## 733    MYR-7169  Ham  HWM 2018  2018.5 HM-H-14
## 734    MYR-7170  Ham  HWM 2018  2018.5 HM-H-14
## 735    MYR-7171  Ham  HWM 2018  2018.5 HM-H-14
        ham$Strain <- as.factor(ham$Strain)
        ham$Year_TP_F <- as.factor(ham$Year_TP)
        ham$Year_F <- as.factor(ham$Year)
        
        ham_2018 <- ham[ham$Year == 2018 , ]
        ham_2019 <- ham[ham$Year == 2019 , ]
        ham_2020 <- ham[ham$Year == 2020 , ]
        
        #CHI SQUARED 2018
        ham_chi_geno_2018 <- chisq.test(ham_2018$Strain, ham_2018$Year_TP_F, correct = TRUE,
                                        p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                        simulate.p.value = TRUE, B = 2000)
        ham_chi_geno_2018$p.value
## [1] 0.2823588
        #CHI SQUARED 2019 
        ham_chi_geno_2019 <- chisq.test(ham_2019$Strain, ham_2019$Year_TP_F, correct = TRUE,
                                        p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                        simulate.p.value = TRUE, B = 2000)
        ham_chi_geno_2019$p.value
## [1] 0.2543728
        #CHI SQUARED 2020
        ham_chi_geno_2020 <- chisq.test(ham_2020$Strain, ham_2020$Year_TP_F, correct = TRUE,
                                        p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                        simulate.p.value = TRUE, B = 2000)
        ham_chi_geno_2020$p.value
## [1] 0.7551224
      #3) CHI SQUARED ANALYSIS BTWN YEARS
      #_________________________________________________________________________________________________
        head(ham)
##     Sample_Code Lake Taxa Year Year_TP  Strain Year_TP_F Year_F
## 730    MYR-7166  Ham  HWM 2018  2018.5 HM-H-14    2018.5   2018
## 731    MYR-7167  Ham  HWM 2018  2018.5 HM-H-14    2018.5   2018
## 732    MYR-7168  Ham  HWM 2018  2018.5 HM-H-14    2018.5   2018
## 733    MYR-7169  Ham  HWM 2018  2018.5 HM-H-14    2018.5   2018
## 734    MYR-7170  Ham  HWM 2018  2018.5 HM-H-14    2018.5   2018
## 735    MYR-7171  Ham  HWM 2018  2018.5 HM-H-14    2018.5   2018
        tally(~Year_F, data = ham)
## Year_F
## 2018 2019 2020 
##   83   36   73
        ham$Strain <- as.factor(ham$Strain)
        ham$Year_TP_F <- as.factor(ham$Year_TP_F)
        ham$Year_F <- as.factor(ham$Year)
        
        time_one <- c("2018", "2019", "2020")
        ham_btwn <- ham[ham$Year_TP_F %in% time_one , ]
        ham_btwn <- droplevels(ham_btwn)
        tally(~Year_TP_F, data = ham_btwn)
## Year_TP_F
## 2018 2019 2020 
##   34   12   22
        ham_btwn_18_19 <-ham_btwn[ham_btwn$Year == 2018 | ham_btwn$Year == 2019 , ] 
        ham_btwn_18_19 <- droplevels(ham_btwn_18_19)
        tally(~Year, data = ham_btwn_18_19)
## Year
## 2018 2019 
##   34   12
        ham_btwn_18_19$Strain <- as.factor(ham_btwn_18_19$Strain)
        ham_btwn_18_19$Year_F <- as.factor(ham_btwn_18_19$Year)
        
        ham_btwn_19_20 <-ham_btwn[ham_btwn$Year == 2019 | ham_btwn$Year == 2020 , ] 
        ham_btwn_19_20 <- droplevels(ham_btwn_19_20)
        tally(~Year_TP_F, data = ham_btwn_19_20)
## Year_TP_F
## 2019 2020 
##   12   22
        ham_btwn_19_20$Strain <- as.factor(ham_btwn_19_20$Strain)
        ham_btwn_19_20$Year_F <- as.factor(ham_btwn_19_20$Year)
        
        #CHI SQUARED COMPARING 2018 TO 2019
        ham_chi_btwn_18_19 <- chisq.test(ham_btwn_18_19$Strain, ham_btwn_18_19$Year_F, correct = TRUE,
                                         p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                         simulate.p.value = TRUE, B = 2000)
        ham_chi_btwn_18_19$p.value
## [1] 0.008495752
        #CHI SQUARED COMPARING 2019 TO 2020
        ham_chi_btwn_19_20 <- chisq.test(ham_btwn_19_20$Strain, ham_btwn_19_20$Year_TP_F, correct = TRUE,
                                         p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                         simulate.p.value = TRUE, B = 2000)
        ham_chi_btwn_19_20$p.value
## [1] 0.1414293
      #4) ALL THREE YEARS (first t1 to last t2)
      #_________________________________________________________________________________________________
        ham_three_yr_2018 <- as.data.frame(ham[ham$Year_TP_F == 2018 , ])
        ham_three_yr_2020 <- as.data.frame(ham[ham$Year_TP_F == 2020.5 , ])
        ham_three_yr <- rbind(ham_three_yr_2018, ham_three_yr_2020)
        
        ham_chi_three_yr <- chisq.test(ham_three_yr$Strain, ham_three_yr$Year_TP_F, correct = TRUE,
                                       p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                       simulate.p.value = TRUE, B = 2000)
        ham_chi_three_yr
## 
##  Pearson's Chi-squared test with simulated p-value (based on 2000
##  replicates)
## 
## data:  ham_three_yr$Strain and ham_three_yr$Year_TP_F
## X-squared = 1.3099, df = NA, p-value = 0.3313

Analyze Independence Lake

#1 Graph with y-axis as percent of total sites visited
        #_________________________________________________________________________________________________
          head(indp)
##     Sample_Code         Lake Taxa Year Year_TP  Strain
## 922    MYR-6855 Independence  HWM 2018    2018 IN-H-99
## 923    MYR-6856 Independence  HWM 2018    2018 IN-H-99
## 924    MYR-6857 Independence  HWM 2018    2018 IN-H-99
## 925    MYR-6858 Independence  HWM 2018    2018 IN-H-99
## 926    MYR-6859 Independence  HWM 2018    2018 IN-H-99
## 927    MYR-6860 Independence  HWM 2018    2018 IN-H-99
          indp_counts <- indp %>% count(Year_TP,Strain, Taxa)
          indp_counts
##    Year_TP  Strain Taxa  n
## 1   2018.0 IN-H-99  HWM 22
## 2   2018.0  MC-E-1  EWM 25
## 3   2018.5 IN-H-99  HWM 24
## 4   2018.5  MC-E-1  EWM 22
## 5   2019.0 IN-H-99  HWM 15
## 6   2019.0  MC-E-1  EWM 10
## 7   2019.5 IN-H-99  HWM 14
## 8   2019.5  MC-E-1  EWM 10
## 9   2020.0 IN-H-99  HWM 31
## 10  2020.0  MC-E-1  EWM 11
## 11  2020.5 IN-H-99  HWM 18
## 12  2020.5  MC-E-1  EWM 12
          is.data.frame(indp_counts)
## [1] TRUE
          indp_counts$Percent_Ocupied <- ((indp_counts$n)/198)*100
          indp_counts$Strain <- indp_counts$Strain
          
          indp_plot_Percent_Ocupied <- indp_counts %>%
            ggplot()+geom_line(aes(x=Year_TP,y=Percent_Ocupied,col=Strain))+geom_point(aes(x=Year_TP,y=Percent_Ocupied, col=Strain), size = 2) 
          indp_PO_annotated <- print(indp_plot_Percent_Ocupied + 
                                       ggtitle("G. Independence") + 
                                       theme_light() +
                                       ylim(0, 18) +
                                       guides(col=guide_legend(ncol=1,byrow=TRUE)) + 
                                       labs(y="Percent of Sampled Sites (%)", x = "Year") ) 

        #2) CHI SQUARED ANALYSIS WITHIN YEAR
        #_________________________________________________________________________________________________
          head(indp)
##     Sample_Code         Lake Taxa Year Year_TP  Strain
## 922    MYR-6855 Independence  HWM 2018    2018 IN-H-99
## 923    MYR-6856 Independence  HWM 2018    2018 IN-H-99
## 924    MYR-6857 Independence  HWM 2018    2018 IN-H-99
## 925    MYR-6858 Independence  HWM 2018    2018 IN-H-99
## 926    MYR-6859 Independence  HWM 2018    2018 IN-H-99
## 927    MYR-6860 Independence  HWM 2018    2018 IN-H-99
          indp$Year_TP_F <- as.factor(indp$Year_TP)
          indp$Strain <- as.factor(indp$Strain)
          
          indp_2018 <- indp[indp$Year == 2018 , ]
          indp_2019 <- indp[indp$Year == 2019 , ]
          indp_2020 <- indp[indp$Year == 2020 , ]
          
          #CHI SQUARED 2018 
          indp_chi_geno_2018 <- chisq.test(indp_2018$Strain, indp_2018$Year_TP_F, correct = TRUE,
                                           p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                           simulate.p.value = TRUE, B = 2000)
          indp_chi_geno_2018$p.value
## [1] 0.6721639
          #CHI SQUARED 2019 
          indp_chi_geno_2019 <- chisq.test(indp_2019$Strain, indp_2019$Year_TP_F, correct = TRUE,
                                           p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                           simulate.p.value = TRUE, B = 2000)
          indp_chi_geno_2019$p.value
## [1] 1
          #CHI SQUARED 2020
          indp_chi_geno_2020 <- chisq.test(indp_2020$Strain, indp_2020$Year_TP_F, correct = TRUE,
                                           p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                           simulate.p.value = TRUE, B = 2000)
          indp_chi_geno_2020$p.value
## [1] 0.3133433
        #3) CHI SQUARED ANALYSIS BTWN YEARS
        #_________________________________________________________________________________________________
          head(indp)
##     Sample_Code         Lake Taxa Year Year_TP  Strain Year_TP_F
## 922    MYR-6855 Independence  HWM 2018    2018 IN-H-99      2018
## 923    MYR-6856 Independence  HWM 2018    2018 IN-H-99      2018
## 924    MYR-6857 Independence  HWM 2018    2018 IN-H-99      2018
## 925    MYR-6858 Independence  HWM 2018    2018 IN-H-99      2018
## 926    MYR-6859 Independence  HWM 2018    2018 IN-H-99      2018
## 927    MYR-6860 Independence  HWM 2018    2018 IN-H-99      2018
          tally(~Year_TP_F, data = indp)
## Year_TP_F
##   2018 2018.5   2019 2019.5   2020 2020.5 
##     47     46     25     24     42     30
          time_one <- c("2018", "2019", "2020")
          indp_btwn <- indp[indp$Year_TP_F %in% time_one , ]
          indp_btwn <- droplevels(indp_btwn)
          tally(~Year_TP_F, data = indp_btwn)
## Year_TP_F
## 2018 2019 2020 
##   47   25   42
          indp_btwn_18_19 <-indp_btwn[indp_btwn$Year == 2018 | indp_btwn$Year == 2019 , ] 
          indp_btwn_18_19 <- droplevels(indp_btwn_18_19)
          tally(~Year_TP_F, data = indp_btwn_18_19)
## Year_TP_F
## 2018 2019 
##   47   25
          indp_btwn_19_20 <-indp_btwn[indp_btwn$Year == 2019 | indp_btwn$Year == 2020 , ] 
          indp_btwn_19_20 <- droplevels(indp_btwn_19_20)
          tally(~Year_TP_F, data = indp_btwn_19_20)
## Year_TP_F
## 2019 2020 
##   25   42
          #CHI SQUARED COMPARING 2018 TO 2019
          indp_chi_btwn_18_19 <- chisq.test(indp_btwn_18_19$Strain, indp_btwn_18_19$Year_TP_F, correct = TRUE,
                                            p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                            simulate.p.value = TRUE, B = 2000)
          indp_chi_btwn_18_19$p.value
## [1] 0.3293353
          #CHI SQUARED COMPARING 2019 TO 2020
          indp_chi_btwn_19_20 <- chisq.test(indp_btwn_19_20$Strain, indp_btwn_19_20$Year_TP_F, correct = TRUE,
                                            p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                            simulate.p.value = TRUE, B = 2000)
          indp_chi_btwn_19_20$p.value
## [1] 0.2793603
        #4) ALL THREE YEARS (first t1 to last t2)
        #_________________________________________________________________________________________________
          head(indp)
##     Sample_Code         Lake Taxa Year Year_TP  Strain Year_TP_F
## 922    MYR-6855 Independence  HWM 2018    2018 IN-H-99      2018
## 923    MYR-6856 Independence  HWM 2018    2018 IN-H-99      2018
## 924    MYR-6857 Independence  HWM 2018    2018 IN-H-99      2018
## 925    MYR-6858 Independence  HWM 2018    2018 IN-H-99      2018
## 926    MYR-6859 Independence  HWM 2018    2018 IN-H-99      2018
## 927    MYR-6860 Independence  HWM 2018    2018 IN-H-99      2018
          tally(~Year_TP, data = indp)
## Year_TP
##   2018 2018.5   2019 2019.5   2020 2020.5 
##     47     46     25     24     42     30
          indp$Strain <- as.factor(indp$Strain)
          indp$Year_TP_F <- as.factor(indp$Year_TP)
          
          indp_three_yr_2018 <- as.data.frame(indp[indp$Year_TP_F == 2018 , ])
          indp_three_yr_2020 <- as.data.frame(indp[indp$Year_TP_F == 2020.5 , ])
          indp_three_yr <- rbind(indp_three_yr_2018, indp_three_yr_2020)
          
          indp_chi_three_yr <- chisq.test(indp_three_yr$Strain, indp_three_yr$Year_TP_F, correct = TRUE,
                                          p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                          simulate.p.value = TRUE, B = 2000)
          indp_chi_three_yr
## 
##  Pearson's Chi-squared test with simulated p-value (based on 2000
##  replicates)
## 
## data:  indp_three_yr$Strain and indp_three_yr$Year_TP_F
## X-squared = 1.2765, df = NA, p-value = 0.3498

Analyze North Arm of Lake Minnetonka

#1 Graph with y-axis as percent of total sites visited
    #_________________________________________________________________________________________________
          
          head(north_arm)
##      Sample_Code      Lake Taxa Year Year_TP  Strain
## 1136    MYR-7856 North_Arm  HWM 2019  2019.5  MC-H-7
## 1137    MYR-7857 North_Arm  HWM 2019  2019.5 MC-H-12
## 1138    MYR-7858 North_Arm  HWM 2019  2019.5  MC-H-9
## 1139    MYR-7859 North_Arm  HWM 2019  2019.5  MC-H-7
## 1140    MYR-7860 North_Arm  HWM 2019  2019.5  MC-H-7
## 1141    MYR-7861 North_Arm  HWM 2019  2019.5  MC-H-9
          north_arm$Genotype <- as.factor(north_arm$Strain)
          north_arm$Year_TP_F <- as.factor(north_arm$Year_TP)
          north_arm$Year_F <- as.factor(north_arm$Year)
          north_arm$Year <- as.numeric(north_arm$Year)
          
        head(north_arm)
##      Sample_Code      Lake Taxa Year Year_TP  Strain Genotype Year_TP_F Year_F
## 1136    MYR-7856 North_Arm  HWM 2019  2019.5  MC-H-7   MC-H-7    2019.5   2019
## 1137    MYR-7857 North_Arm  HWM 2019  2019.5 MC-H-12  MC-H-12    2019.5   2019
## 1138    MYR-7858 North_Arm  HWM 2019  2019.5  MC-H-9   MC-H-9    2019.5   2019
## 1139    MYR-7859 North_Arm  HWM 2019  2019.5  MC-H-7   MC-H-7    2019.5   2019
## 1140    MYR-7860 North_Arm  HWM 2019  2019.5  MC-H-7   MC-H-7    2019.5   2019
## 1141    MYR-7861 North_Arm  HWM 2019  2019.5  MC-H-9   MC-H-9    2019.5   2019
        tally(~Year, data = north_arm)
## Year
## 2018 2019 2020 
##   84    7   16
        north_arm$Year_TP <- north_arm$Time_Point
        north_arm_counts <- north_arm %>% count(Year_TP_F,Strain)
        north_arm_counts
##    Year_TP_F   Strain  n
## 1       2018   MC-H-7  8
## 2     2018.2 MC-H-106  2
## 3     2018.2  MC-H-12  2
## 4     2018.2   MC-H-7 58
## 5     2018.2   MC-H-9  1
## 6     2018.2  NB-H_14  2
## 7     2018.2   NB-H_3 11
## 8     2019.5 MC-H-106  1
## 9     2019.5  MC-H-12  1
## 10    2019.5   MC-H-7  3
## 11    2019.5   MC-H-9  2
## 12    2020.5  MC-H-12  2
## 13    2020.5   MC-H-7 10
## 14    2020.5   MC-H-9  3
## 15    2020.5  NB-H_14  1
        north_arm_counts$Percent_Ocupied <- ((north_arm_counts$n)/229)*100
        north_arm_counts
##    Year_TP_F   Strain  n Percent_Ocupied
## 1       2018   MC-H-7  8       3.4934498
## 2     2018.2 MC-H-106  2       0.8733624
## 3     2018.2  MC-H-12  2       0.8733624
## 4     2018.2   MC-H-7 58      25.3275109
## 5     2018.2   MC-H-9  1       0.4366812
## 6     2018.2  NB-H_14  2       0.8733624
## 7     2018.2   NB-H_3 11       4.8034934
## 8     2019.5 MC-H-106  1       0.4366812
## 9     2019.5  MC-H-12  1       0.4366812
## 10    2019.5   MC-H-7  3       1.3100437
## 11    2019.5   MC-H-9  2       0.8733624
## 12    2020.5  MC-H-12  2       0.8733624
## 13    2020.5   MC-H-7 10       4.3668122
## 14    2020.5   MC-H-9  3       1.3100437
## 15    2020.5  NB-H_14  1       0.4366812
        north_arm$Strain <- as.factor(north_arm$Strain)
        north_arm_counts$Year_TP_F <- as.character(north_arm_counts$Year_TP_F)
        north_arm_counts$Year_TP_F <- as.numeric(north_arm_counts$Year_TP_F)
        north_arm_plot_Percent_Ocupied <- north_arm_counts %>%
            ggplot() + geom_line(aes(x=Year_TP_F,y=Percent_Ocupied,col=Strain))+
            geom_point(aes(x=Year_TP_F,y=Percent_Ocupied, col=Strain), size = 2) 
        
        north_arm_PO_annotated <- print(north_arm_plot_Percent_Ocupied + 
                                          ggtitle("E. North Arm") + 
                                          theme_light() +
                                          geom_vline(xintercept = 2018.25, linetype="dashed", color = "red") +
                                          guides(col=guide_legend(ncol=1,byrow=TRUE)) + 
                                          labs(y="Percent of Sampled Sites (%)", x = "Year") )

        north_arm_PO_annotated 

    #2) CHI SQUARED ANALYSIS WITHIN YEAR
    #_________________________________________________________________________________________________
        #Only one timepoint per year for North Arm Lake
        set.seed(1025)

        
    #3) CHI SQUARED ANALYSIS BTWN YEARS
    #_________________________________________________________________________________________________
        head(north_arm)
##      Sample_Code      Lake Taxa Year  Strain Genotype Year_TP_F Year_F
## 1136    MYR-7856 North_Arm  HWM 2019  MC-H-7   MC-H-7    2019.5   2019
## 1137    MYR-7857 North_Arm  HWM 2019 MC-H-12  MC-H-12    2019.5   2019
## 1138    MYR-7858 North_Arm  HWM 2019  MC-H-9   MC-H-9    2019.5   2019
## 1139    MYR-7859 North_Arm  HWM 2019  MC-H-7   MC-H-7    2019.5   2019
## 1140    MYR-7860 North_Arm  HWM 2019  MC-H-7   MC-H-7    2019.5   2019
## 1141    MYR-7861 North_Arm  HWM 2019  MC-H-9   MC-H-9    2019.5   2019
        tally(~Year_F, data = north_arm)
## Year_F
## 2018 2019 2020 
##   84    7   16
        north_arm$Genotype <- as.factor(north_arm$Genotype)
        north_arm$Year_TP_F <- as.factor(north_arm$Year_TP_F)
        north_arm$Year_F <- as.factor(north_arm$Year)
        
        time_one <- c("2018", "2019", "2020")
        north_arm_btwn <- north_arm[north_arm$Year %in% time_one , ]
        north_arm_btwn <- droplevels(north_arm_btwn)
        tally(~Year, data = north_arm_btwn)
## Year
## 2018 2019 2020 
##   84    7   16
        north_arm_btwn_18_19 <-north_arm_btwn[north_arm_btwn$Year == 2018 | north_arm_btwn$Year == 2019 , ] 
        north_arm_btwn_18_19 <- droplevels(north_arm_btwn_18_19)
        tally(~Year, data = north_arm_btwn_18_19)
## Year
## 2018 2019 
##   84    7
        north_arm_btwn_18_19$Genotype <- as.factor(north_arm_btwn_18_19$Genotype)
        north_arm_btwn_18_19$Year_F <- as.factor(north_arm_btwn_18_19$Year)
        
        
        north_arm_btwn_19_20 <-north_arm_btwn[north_arm_btwn$Year == 2019 | north_arm_btwn$Year == 2020 , ] 
        north_arm_btwn_19_20 <- droplevels(north_arm_btwn_19_20)
        tally(~Year_TP_F, data = north_arm_btwn_19_20)
## Year_TP_F
## 2019.5 2020.5 
##      7     16
        north_arm_btwn_19_20$Genotype <- as.factor(north_arm_btwn_19_20$Genotype)
        north_arm_btwn_19_20$Year_F <- as.factor(north_arm_btwn_19_20$Year)
        
        #CHI SQUARED COMPARING 2018 TO 2019
        north_arm_chi_btwn_18_19 <- chisq.test(north_arm_btwn_18_19$Genotype, north_arm_btwn_18_19$Year, correct = TRUE,
                                               p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                               simulate.p.value = TRUE, B = 2000)
        north_arm_chi_btwn_18_19$p.value
## [1] 0.005997001
        #CHI SQUARED COMPARING 2019 TO 2020
        north_arm_chi_btwn_19_20 <- chisq.test(north_arm_btwn_19_20$Genotype, north_arm_btwn_19_20$Year, correct = TRUE,
                                               p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                               simulate.p.value = TRUE, B = 2000)
        north_arm_chi_btwn_19_20$p.value
## [1] 0.6546727
    #4) ALL THREE YEARS (first t1 to last t2)
    #_________________________________________________________________________________________________
        head(north_arm)
##      Sample_Code      Lake Taxa Year  Strain Genotype Year_TP_F Year_F
## 1136    MYR-7856 North_Arm  HWM 2019  MC-H-7   MC-H-7    2019.5   2019
## 1137    MYR-7857 North_Arm  HWM 2019 MC-H-12  MC-H-12    2019.5   2019
## 1138    MYR-7858 North_Arm  HWM 2019  MC-H-9   MC-H-9    2019.5   2019
## 1139    MYR-7859 North_Arm  HWM 2019  MC-H-7   MC-H-7    2019.5   2019
## 1140    MYR-7860 North_Arm  HWM 2019  MC-H-7   MC-H-7    2019.5   2019
## 1141    MYR-7861 North_Arm  HWM 2019  MC-H-9   MC-H-9    2019.5   2019
        north_arm$Genotype <- as.factor(north_arm$Genotype)
        north_arm$Year_TP_F <- as.factor(north_arm$Year_TP)
        
        tally(~Genotype + Year_TP_F, data = north_arm)
##           Year_TP_F
## Genotype   2018 2018.2 2019.5 2020.5
##   MC-H-106    0      2      1      0
##   MC-H-12     0      2      1      2
##   MC-H-7      8     58      3     10
##   MC-H-9      0      1      2      3
##   NB-H_14     0      2      0      1
##   NB-H_3      0     11      0      0
        levels(north_arm$Year_TP_F)
## [1] "2018"   "2018.2" "2019.5" "2020.5"
        north_arm_three_yr_2018 <- as.data.frame(north_arm[north_arm$Year_TP_F == 2018.2 , ])
        tally(~Genotype + Year_TP_F, data = north_arm_three_yr_2018)
##           Year_TP_F
## Genotype   2018 2018.2 2019.5 2020.5
##   MC-H-106    0      2      0      0
##   MC-H-12     0      2      0      0
##   MC-H-7      0     58      0      0
##   MC-H-9      0      1      0      0
##   NB-H_14     0      2      0      0
##   NB-H_3      0     11      0      0
        north_arm_three_yr_2020 <- as.data.frame(north_arm[north_arm$Year_TP_F == 2020.5 , ])
        tally(~Genotype + Year_TP_F, data = north_arm_three_yr_2020)
##           Year_TP_F
## Genotype   2018 2018.2 2019.5 2020.5
##   MC-H-106    0      0      0      0
##   MC-H-12     0      0      0      2
##   MC-H-7      0      0      0     10
##   MC-H-9      0      0      0      3
##   NB-H_14     0      0      0      1
##   NB-H_3      0      0      0      0
        north_arm_three_yr <- rbind(north_arm_three_yr_2018, north_arm_three_yr_2020)
        
        tally(~Genotype + Year_TP_F, data = north_arm_three_yr)
##           Year_TP_F
## Genotype   2018 2018.2 2019.5 2020.5
##   MC-H-106    0      2      0      0
##   MC-H-12     0      2      0      2
##   MC-H-7      0     58      0     10
##   MC-H-9      0      1      0      3
##   NB-H_14     0      2      0      1
##   NB-H_3      0     11      0      0
        north_arm_chi_three_yr <- chisq.test(north_arm_three_yr$Genotype, north_arm_three_yr$Year_TP_F, correct = TRUE,
                                             p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                             simulate.p.value = TRUE, B = 2000)
        north_arm_chi_three_yr
## 
##  Pearson's Chi-squared test with simulated p-value (based on 2000
##  replicates)
## 
## data:  north_arm_three_yr$Genotype and north_arm_three_yr$Year_TP_F
## X-squared = 15.81, df = NA, p-value = 0.01449

Analyze Phelps Bay of Lake Minnetonka

#1 Graph with y-axis as percent of total sites visited
    #_________________________________________________________________________________________________
        head(phelps)
##      Sample_Code       Lake Taxa Year Year_TP  Strain
## 1243    MYR-8125 Phelps_Bay  HWM 2019  2019.5  PB-H-7
## 1244    MYR-8253 Phelps_Bay  HWM 2019  2019.5  PB-H-8
## 1245    MYR-8254 Phelps_Bay  HWM 2019  2019.5  PB-H-7
## 1246    MYR-8256 Phelps_Bay  HWM 2019  2019.5  PB-H-7
## 1247    MYR-8257 Phelps_Bay  HWM 2019  2019.5  PB-H-8
## 1248    MYR-8258 Phelps_Bay  NWM 2019  2019.5 PB-N-10
        tally(~Year_TP, data = phelps)
## Year_TP
## 2019.5   2020 2020.5 
##     40     63      8
        phelps_counts <- phelps %>% count(Year_TP,Strain)
        phelps_counts
##    Year_TP  Strain  n
## 1   2019.5  PB-H-2  1
## 2   2019.5  PB-H-7 24
## 3   2019.5  PB-H-8 10
## 4   2019.5 PB-N-10  5
## 5   2020.0  PB-H-2  1
## 6   2020.0  PB-H-3  2
## 7   2020.0  PB-H-7 27
## 8   2020.0  PB-H-8 21
## 9   2020.0 PB-N-10 12
## 10  2020.5  PB-H-8  1
## 11  2020.5 PB-N-10  7
        phelps_counts$Percent_Ocupied <- ((phelps_counts$n)/148)*100
        phelps_counts
##    Year_TP  Strain  n Percent_Ocupied
## 1   2019.5  PB-H-2  1       0.6756757
## 2   2019.5  PB-H-7 24      16.2162162
## 3   2019.5  PB-H-8 10       6.7567568
## 4   2019.5 PB-N-10  5       3.3783784
## 5   2020.0  PB-H-2  1       0.6756757
## 6   2020.0  PB-H-3  2       1.3513514
## 7   2020.0  PB-H-7 27      18.2432432
## 8   2020.0  PB-H-8 21      14.1891892
## 9   2020.0 PB-N-10 12       8.1081081
## 10  2020.5  PB-H-8  1       0.6756757
## 11  2020.5 PB-N-10  7       4.7297297
        phelps_plot_Percent_Ocupied <- phelps_counts %>%
          ggplot()+geom_line(aes(x=Year_TP,y=Percent_Ocupied,col=Strain))+geom_point(aes(x=Year_TP,y=Percent_Ocupied, col=Strain), size = 2) 
        
        phelps_PO_annotated <- print(phelps_plot_Percent_Ocupied + 
                                       ggtitle("D. Phelps") + 
                                       theme_light() +
                                       xlim(2018, 2020.5) + 
                                       geom_vline(xintercept = 2019.95, linetype="dashed", color = "red") +
                                       guides(col=guide_legend(ncol=1,byrow=TRUE)) + 
                                       labs(y="Percent of Sampled Sites (%)", x = "Year") )

    #2) CHI SQUARED ANALYSIS WITHIN YEAR
    #_________________________________________________________________________________________________
        set.seed(1025)
        
        head(phelps)
##      Sample_Code       Lake Taxa Year Year_TP  Strain
## 1243    MYR-8125 Phelps_Bay  HWM 2019  2019.5  PB-H-7
## 1244    MYR-8253 Phelps_Bay  HWM 2019  2019.5  PB-H-8
## 1245    MYR-8254 Phelps_Bay  HWM 2019  2019.5  PB-H-7
## 1246    MYR-8256 Phelps_Bay  HWM 2019  2019.5  PB-H-7
## 1247    MYR-8257 Phelps_Bay  HWM 2019  2019.5  PB-H-8
## 1248    MYR-8258 Phelps_Bay  NWM 2019  2019.5 PB-N-10
        phelps$Strain <- as.factor(phelps$Strain)
        phelps$Year_TP_F <- as.factor(phelps$Year_TP)
        head(phelps)
##      Sample_Code       Lake Taxa Year Year_TP  Strain Year_TP_F
## 1243    MYR-8125 Phelps_Bay  HWM 2019  2019.5  PB-H-7    2019.5
## 1244    MYR-8253 Phelps_Bay  HWM 2019  2019.5  PB-H-8    2019.5
## 1245    MYR-8254 Phelps_Bay  HWM 2019  2019.5  PB-H-7    2019.5
## 1246    MYR-8256 Phelps_Bay  HWM 2019  2019.5  PB-H-7    2019.5
## 1247    MYR-8257 Phelps_Bay  HWM 2019  2019.5  PB-H-8    2019.5
## 1248    MYR-8258 Phelps_Bay  NWM 2019  2019.5 PB-N-10    2019.5
        tally(~Year_TP_F, data = phelps)
## Year_TP_F
## 2019.5   2020 2020.5 
##     40     63      8
        head(phelps)
##      Sample_Code       Lake Taxa Year Year_TP  Strain Year_TP_F
## 1243    MYR-8125 Phelps_Bay  HWM 2019  2019.5  PB-H-7    2019.5
## 1244    MYR-8253 Phelps_Bay  HWM 2019  2019.5  PB-H-8    2019.5
## 1245    MYR-8254 Phelps_Bay  HWM 2019  2019.5  PB-H-7    2019.5
## 1246    MYR-8256 Phelps_Bay  HWM 2019  2019.5  PB-H-7    2019.5
## 1247    MYR-8257 Phelps_Bay  HWM 2019  2019.5  PB-H-8    2019.5
## 1248    MYR-8258 Phelps_Bay  NWM 2019  2019.5 PB-N-10    2019.5
        tally(~ Year, data = phelps)
## Year
## 2019 2020 
##   40   71
        phelps_2019 <- phelps[phelps$Year == 2019 , ]
        phelps_2020 <- phelps[phelps$Year == 2020 , ]
        
        tally(~ Strain + Year_TP_F, data = phelps_2020)
##          Year_TP_F
## Strain    2019.5 2020 2020.5
##   PB-H-2       0    1      0
##   PB-H-3       0    2      0
##   PB-H-7       0   27      0
##   PB-H-8       0   21      1
##   PB-N-10      0   12      7
        #CHI SQUARED 2020
        tally(~Strain + Year_TP_F, data = phelps_2020)
##          Year_TP_F
## Strain    2019.5 2020 2020.5
##   PB-H-2       0    1      0
##   PB-H-3       0    2      0
##   PB-H-7       0   27      0
##   PB-H-8       0   21      1
##   PB-N-10      0   12      7
        phelps_chi_geno_2020 <- chisq.test(phelps_2020$Strain, phelps_2020$Year_TP_F, correct = TRUE,
                                           p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                           simulate.p.value = TRUE, B = 2000) 
        phelps_chi_geno_2020$p.value
## [1] 0.01349325
    #3) CHI SQUARED ANALYSIS BTWN YEARS
    #_________________________________________________________________________________________________
        head(phelps)
##      Sample_Code       Lake Taxa Year Year_TP  Strain Year_TP_F
## 1243    MYR-8125 Phelps_Bay  HWM 2019  2019.5  PB-H-7    2019.5
## 1244    MYR-8253 Phelps_Bay  HWM 2019  2019.5  PB-H-8    2019.5
## 1245    MYR-8254 Phelps_Bay  HWM 2019  2019.5  PB-H-7    2019.5
## 1246    MYR-8256 Phelps_Bay  HWM 2019  2019.5  PB-H-7    2019.5
## 1247    MYR-8257 Phelps_Bay  HWM 2019  2019.5  PB-H-8    2019.5
## 1248    MYR-8258 Phelps_Bay  NWM 2019  2019.5 PB-N-10    2019.5
        tally(~Year_TP_F, data = phelps)
## Year_TP_F
## 2019.5   2020 2020.5 
##     40     63      8
        phelps$Strain <- as.factor(phelps$Strain)
        phelps$Year_TP_F <- as.factor(phelps$Year_TP_F)
        phelps$Year_F <- as.factor(phelps$Year)
        
        phelps_time <- c("2019.5", "2020.5")
        phelps_btwn <- phelps[phelps$Year_TP_F %in% phelps_time , ]
        phelps_btwn <- droplevels(phelps_btwn)
        tally(~Year_TP_F, data = phelps_btwn)
## Year_TP_F
## 2019.5 2020.5 
##     40      8
        phelps_chi_btwn_19_20 <- chisq.test(phelps_btwn$Strain, phelps_btwn$Year_TP_F, correct = TRUE,
                                            p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                            simulate.p.value = TRUE, B = 2000)
        phelps_chi_btwn_19_20$p.value
## [1] 0.0004997501
    #4) ALL THREE YEARS (first t1 to last t2)
    #_________________________________________________________________________________________________
        head(phelps)
##      Sample_Code       Lake Taxa Year Year_TP  Strain Year_TP_F Year_F
## 1243    MYR-8125 Phelps_Bay  HWM 2019  2019.5  PB-H-7    2019.5   2019
## 1244    MYR-8253 Phelps_Bay  HWM 2019  2019.5  PB-H-8    2019.5   2019
## 1245    MYR-8254 Phelps_Bay  HWM 2019  2019.5  PB-H-7    2019.5   2019
## 1246    MYR-8256 Phelps_Bay  HWM 2019  2019.5  PB-H-7    2019.5   2019
## 1247    MYR-8257 Phelps_Bay  HWM 2019  2019.5  PB-H-8    2019.5   2019
## 1248    MYR-8258 Phelps_Bay  NWM 2019  2019.5 PB-N-10    2019.5   2019
        names(phelps)[names(phelps)== "Time_Point"] <- "Year_TP_F"
        
        phelps$Strain <- as.factor(phelps$Strain)
        phelps$Year_TP_F <- as.factor(phelps$Year_TP_F)
        
        phelps_three_yr_2018 <- as.data.frame(phelps[phelps$Year_TP_F == 2019.5 , ])
        phelps_three_yr_2020 <- as.data.frame(phelps[phelps$Year_TP_F == 2020.5 , ])
        phelps_three_yr <- rbind(phelps_three_yr_2018, phelps_three_yr_2020)
        
        phelps_chi_three_yr <- chisq.test(phelps_three_yr$Strain, phelps_three_yr$Year_TP_F, correct = TRUE,
                                          p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                          simulate.p.value = TRUE, B = 2000)
        phelps_chi_three_yr
## 
##  Pearson's Chi-squared test with simulated p-value (based on 2000
##  replicates)
## 
## data:  phelps_three_yr$Strain and phelps_three_yr$Year_TP_F
## X-squared = 20.455, df = NA, p-value = 0.0009995

Analyze Smiths Bay of Lake Minnetonka

#1 Graph with y-axis as percent of total sites visited
    #_________________________________________________________________________________________________
        head(smith_geno)
##      Sample_Code       Lake Taxa Year Year_TP Strain
## 1354    MYR-6935 Smiths_Bay  EWM 2018    2018 MC-E-1
## 1355    MYR-6936 Smiths_Bay  EWM 2018    2018 MC-E-1
## 1356    MYR-6937 Smiths_Bay  EWM 2018    2018 MC-E-1
## 1357    MYR-6939 Smiths_Bay  EWM 2018    2018 MC-E-1
## 1358    MYR-6940 Smiths_Bay  EWM 2018    2018 MC-E-1
## 1359    MYR-7368 Smiths_Bay  EWM 2018    2018 MC-E-1
        smith_geno_counts <- smith_geno %>% count(Year,Strain, Taxa)
        smith_geno_counts
##    Year   Strain Taxa  n
## 1  2018   MC-E-1  EWM 14
## 2  2018 MC-H-106  HWM  4
## 3  2018 MC-H-107  HWM  3
## 4  2018 MC-H-108  HWM  3
## 5  2018  MC-H-12  HWM  2
## 6  2018 MC-H-142  HWM  1
## 7  2018   MC-H-7  HWM 19
## 8  2018   MC-H-9  HWM  2
## 9  2018 MC-N-109  NWM  1
## 10 2019   MC-E-1  EWM 14
## 11 2019 MC-H-106  HWM  5
## 12 2019 MC-H-108  HWM  9
## 13 2019  MC-H-12  HWM  7
## 14 2019 MC-H-142  HWM  3
## 15 2019   MC-H-7  HWM 44
## 16 2019 MC-N-109  NWM  1
## 17 2020   MC-E-1  EWM  9
## 18 2020 MC-H-106  HWM  7
## 19 2020 MC-H-107  HWM  1
## 20 2020 MC-H-108  HWM  7
## 21 2020  MC-H-12  HWM  3
## 22 2020 MC-H-142  HWM  1
## 23 2020   MC-H-7  HWM 29
## 24 2020   MC-H-9  HWM  6
## 25 2020   SB-H-2  HWM  2
        is.data.frame(smith_geno_counts)
## [1] TRUE
        smith_geno_counts$Percent_Ocupied <- ((smith_geno_counts$n)/127)*100
        
        smith_geno_plot_Percent_Ocupied <- smith_geno_counts %>%
          ggplot()+geom_line(aes(x=Year,y=Percent_Ocupied,col=Strain))+geom_point(aes(x=Year,y=Percent_Ocupied, col=Strain), size = 2) 
        smith_PO_annotated <- print(smith_geno_plot_Percent_Ocupied + 
                                      ggtitle("F. Smith") + 
                                      theme_light() +
                                      guides(col=guide_legend(ncol=1,byrow=TRUE)) + 
                                      labs(y="Percent of Sampled Sites (%)", x = "Year") ) 

    #2) CHI SQUARED ANALYSIS WITHIN YEAR
    #_________________________________________________________________________________________________
        #Only have data for one timepoint for each year in Smith's Bay 
        
        set.seed(1025)  
        
        head(smith_geno)
##      Sample_Code       Lake Taxa Year Year_TP Strain
## 1354    MYR-6935 Smiths_Bay  EWM 2018    2018 MC-E-1
## 1355    MYR-6936 Smiths_Bay  EWM 2018    2018 MC-E-1
## 1356    MYR-6937 Smiths_Bay  EWM 2018    2018 MC-E-1
## 1357    MYR-6939 Smiths_Bay  EWM 2018    2018 MC-E-1
## 1358    MYR-6940 Smiths_Bay  EWM 2018    2018 MC-E-1
## 1359    MYR-7368 Smiths_Bay  EWM 2018    2018 MC-E-1
        smith_geno$Strain <- as.factor(smith_geno$Strain)
        smith_geno$Year_F <- as.factor(smith_geno$Year)
        tally(~Year_F, data = smith_geno)
## Year_F
## 2018 2019 2020 
##   49   83   65
        smith_geno_2018 <- smith_geno[smith_geno$Year == 2018 , ]
        smith_geno_2019 <- smith_geno[smith_geno$Year == 2019 , ]
        smith_geno_2020 <- smith_geno[smith_geno$Year == 2020 , ]
        
    #3) CHI SQUARED ANALYSIS BTWN YEARS
    #_________________________________________________________________________________________________
        head(smith_geno)
##      Sample_Code       Lake Taxa Year Year_TP Strain Year_F
## 1354    MYR-6935 Smiths_Bay  EWM 2018    2018 MC-E-1   2018
## 1355    MYR-6936 Smiths_Bay  EWM 2018    2018 MC-E-1   2018
## 1356    MYR-6937 Smiths_Bay  EWM 2018    2018 MC-E-1   2018
## 1357    MYR-6939 Smiths_Bay  EWM 2018    2018 MC-E-1   2018
## 1358    MYR-6940 Smiths_Bay  EWM 2018    2018 MC-E-1   2018
## 1359    MYR-7368 Smiths_Bay  EWM 2018    2018 MC-E-1   2018
        tally(~Year_F, data = smith_geno)
## Year_F
## 2018 2019 2020 
##   49   83   65
        smith_geno$Strain <- as.factor(smith_geno$Strain)
        smith_geno$Year_F <- as.factor(smith_geno$Year)
        
        time_one <- c("2018", "2019", "2020")
        smith_geno_btwn <- smith_geno[smith_geno$Year_F %in% time_one , ]
        smith_geno_btwn <- droplevels(smith_geno_btwn)
        
        smith_geno_btwn_18_19 <-smith_geno_btwn[smith_geno_btwn$Year == 2018 | smith_geno_btwn$Year == 2019 , ] 
        smith_geno_btwn_18_19 <- droplevels(smith_geno_btwn_18_19)
        tally(~Year, data = smith_geno_btwn_18_19)
## Year
## 2018 2019 
##   49   83
        smith_geno_btwn_18_19$Strain <- as.factor(smith_geno_btwn_18_19$Strain)
        smith_geno_btwn_18_19$Year_F <- as.factor(smith_geno_btwn_18_19$Year)
        
        smith_geno_btwn_19_20 <-smith_geno_btwn[smith_geno_btwn$Year == 2019 | smith_geno_btwn$Year == 2020 , ] 
        smith_geno_btwn_19_20 <- droplevels(smith_geno_btwn_19_20)
        tally(~Year_F, data = smith_geno_btwn_19_20)
## Year_F
## 2019 2020 
##   83   65
        smith_geno_btwn_19_20$Strain <- as.factor(smith_geno_btwn_19_20$Strain)
        smith_geno_btwn_19_20$Year_F <- as.factor(smith_geno_btwn_19_20$Year)
        
        #CHI SQUARED COMPARING 2018 TO 2019 
        smith_geno_chi_btwn_18_19 <- chisq.test(smith_geno_btwn_18_19$Strain, smith_geno_btwn_18_19$Year_F, correct = TRUE,
                                                p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                                simulate.p.value = TRUE, B = 2000)
        smith_geno_chi_btwn_18_19$p.value
## [1] 0.06146927
        #CHI SQUARED COMPARING 2019 TO 2020
        smith_geno_chi_btwn_19_20 <- chisq.test(smith_geno_btwn_19_20$Strain, smith_geno_btwn_19_20$Year_F, correct = TRUE,
                                                p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                                simulate.p.value = TRUE, B = 2000)
        smith_geno_chi_btwn_19_20$p.value
## [1] 0.04697651
    #4) ALL THREE YEARS (first t1 to last t2)
    #_________________________________________________________________________________________________
        head(smith_geno)
##      Sample_Code       Lake Taxa Year Year_TP Strain Year_F
## 1354    MYR-6935 Smiths_Bay  EWM 2018    2018 MC-E-1   2018
## 1355    MYR-6936 Smiths_Bay  EWM 2018    2018 MC-E-1   2018
## 1356    MYR-6937 Smiths_Bay  EWM 2018    2018 MC-E-1   2018
## 1357    MYR-6939 Smiths_Bay  EWM 2018    2018 MC-E-1   2018
## 1358    MYR-6940 Smiths_Bay  EWM 2018    2018 MC-E-1   2018
## 1359    MYR-7368 Smiths_Bay  EWM 2018    2018 MC-E-1   2018
        tally(~Year, data = smith_geno)
## Year
## 2018 2019 2020 
##   49   83   65
        smith_geno$Year_TP_F <- smith_geno$Year_F
        
        smith_geno$Strain <- as.factor(smith_geno$Strain)
        smith_geno$Year_TP_F <- as.factor(smith_geno$Year_TP)
        
        smith_geno_three_yr_2018 <- as.data.frame(smith_geno[smith_geno$Year_TP_F == 2018 , ])
        smith_geno_three_yr_2020 <- as.data.frame(smith_geno[smith_geno$Year_TP_F == 2020 , ])
        smith_geno_three_yr <- rbind(smith_geno_three_yr_2018, smith_geno_three_yr_2020)
        
        smith_geno_chi_three_yr <- chisq.test(smith_geno_three_yr$Strain, smith_geno_three_yr$Year_TP_F, correct = TRUE,
                                              p = rep(1/length(x), length(x)), rescale.p = FALSE,
                                              simulate.p.value = TRUE, B = 2000)
        smith_geno_chi_three_yr  
## 
##  Pearson's Chi-squared test with simulated p-value (based on 2000
##  replicates)
## 
## data:  smith_geno_three_yr$Strain and smith_geno_three_yr$Year_TP_F
## X-squared = 9.7346, df = NA, p-value = 0.3738

The End

Session information

Note: These are the package versions used to reproduce the RMD file during curation

sessionInfo()
## R version 4.4.1 (2024-06-14)
## Platform: x86_64-apple-darwin20
## Running under: macOS Sonoma 14.4.1
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRblas.0.dylib 
## LAPACK: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## time zone: America/Chicago
## tzcode source: internal
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] writexl_1.5.0     effects_4.2-2     car_3.1-2         carData_3.0-5    
##  [5] lme4_1.1-35.3     devtools_2.4.5    usethis_2.2.3     lubridate_1.9.3  
##  [9] forcats_1.0.0     stringr_1.5.1     purrr_1.0.2       readr_2.1.5      
## [13] tidyr_1.3.1       tibble_3.2.1      tidyverse_2.0.0   readxl_1.4.3     
## [17] mosaic_1.9.1      mosaicData_0.20.4 ggformula_0.12.0  Matrix_1.7-0     
## [21] ggplot2_3.5.1     lattice_0.22-6    ape_5.8           raster_3.6-26    
## [25] sp_2.1-4          sf_1.0-16         dplyr_1.1.4      
## 
## loaded via a namespace (and not attached):
##  [1] DBI_1.2.2          remotes_2.5.0      rlang_1.1.4        magrittr_2.0.3    
##  [5] ggridges_0.5.6     e1071_1.7-14       compiler_4.4.1     vctrs_0.6.5       
##  [9] profvis_0.3.8      crayon_1.5.3       pkgconfig_2.0.3    fastmap_1.2.0     
## [13] ellipsis_0.3.2     labeling_0.4.3     utf8_1.2.4         promises_1.3.0    
## [17] rmarkdown_2.27     sessioninfo_1.2.2  tzdb_0.4.0         haven_2.5.4       
## [21] nloptr_2.0.3       bit_4.0.5          xfun_0.46          cachem_1.1.0      
## [25] labelled_2.13.0    jsonlite_1.8.8     highr_0.11         later_1.3.2       
## [29] terra_1.7-78       parallel_4.4.1     R6_2.5.1           bslib_0.7.0       
## [33] stringi_1.8.4      boot_1.3-30        pkgload_1.4.0      jquerylib_0.1.4   
## [37] cellranger_1.1.0   Rcpp_1.0.13        knitr_1.48         httpuv_1.6.15     
## [41] splines_4.4.1      nnet_7.3-19        timechange_0.3.0   tidyselect_1.2.1  
## [45] rstudioapi_0.16.0  abind_1.4-5        yaml_2.3.9         codetools_0.2-20  
## [49] miniUI_0.1.1.1     pkgbuild_1.4.4     shiny_1.8.1.1      withr_3.0.0       
## [53] evaluate_0.24.0    survival_3.6-4     survey_4.4-2       units_0.8-5       
## [57] proxy_0.4-27       urlchecker_1.0.1   pillar_1.9.0       KernSmooth_2.23-24
## [61] insight_0.19.10    generics_0.1.3     vroom_1.6.5        hms_1.1.3         
## [65] munsell_0.5.1      scales_1.3.0       minqa_1.2.6        xtable_1.8-4      
## [69] class_7.3-22       glue_1.7.0         tools_4.4.1        fs_1.6.4          
## [73] grid_4.4.1         mitools_2.4        colorspace_2.1-0   nlme_3.1-164      
## [77] cli_3.6.3          fansi_1.0.6        mosaicCore_0.9.4.0 gtable_0.3.5      
## [81] sass_0.4.9         digest_0.6.36      classInt_0.4-10    farver_2.1.2      
## [85] htmlwidgets_1.6.4  memoise_2.0.1      htmltools_0.5.8.1  lifecycle_1.0.4   
## [89] mime_0.12          bit64_4.0.5        MASS_7.3-60.2