-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSturgeonDrift2020Autocorr.r
3082 lines (2190 loc) · 121 KB
/
SturgeonDrift2020Autocorr.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
############
##Import Step
###########
library(vegan)
library(MASS)
library(ggplot2)
library(plyr)
library(dplyr)
library(magrittr)
library(scales)
library(grid)
library(reshape2)
library(phyloseq)
library(randomForest)
library(knitr)
library(ggpubr)
library(multcompView)
library(lmerTest)
library(lme4)
library(tiff)
library(glmmTMB)
library(bbmle)
library(GGally)
library(nlme)
library(DHARMa)
library(patchwork)
set.seed(45682)
#DRIFT FILES all taxa
otufull=read.table("DataClean\\SturgeonDriftInvertAbundanceMatrix8.15.19.txt",header=TRUE)
#head(otufull)
metadata=read.csv("DataClean\\SturgeonDriftMetadata10.28.2020.csv",header=TRUE)
metadata<-subset(metadata,Ninverts!=0) #Remove sample dates where inverts were not collected
metadata$PercentRiverDischargeSampled<-metadata$DischargeSampledByNight/metadata$Q*100
metadata$InvertsByDischargeSampled<-metadata$Ninverts100/metadata$DischargeSampledByNight
metadata$InvertsByRiverDischarge<-metadata$Ninverts100/metadata$Q
metadata$BiomassByRiverDischarge<- metadata$InvertBiomass100/metadata$Q
metadata$BiomassByDischargeSampled<-metadata$InvertBiomass100/metadata$DischargeSampledByNight
metadata$DriftInvertConc<-((metadata$Ninverts100*100)/(60*4*60*metadata$AreaSampled.m2.*metadata$AverageNetFlowByNight)) #Calculate inverts/ 100 m3 water (N*100(final vol )/time in sec*flow*area sampled)
metadata$DriftBiomassConc<-((metadata$InvertBiomass100*100)/(60*4*60*metadata$AreaSampled.m2.*metadata$AverageNetFlowByNight)) #Calculate biomass/ 100 m3 water
metadata$SturgeonConc<-((metadata$Nsturgeon*100)/(60*4*60*metadata$AreaSampled.m2.*metadata$AverageNetFlowByNight)) #Calculate sturgeon larvae/ 100 m3 water
metadata$SuckerConc<-((metadata$Nsuckers100*100)/(60*4*60*metadata$AreaSampled.m2.*metadata$AverageNetFlowByNight)) #Calculate sturgeon larvae/ 100 m3 water
#
# HistDischarge<-ggplot(metadata,aes(x=DischargeSampledByNight))+geom_histogram(fill="grey",color="black")+xlab(expression(Discharge~(m^3/sec)~Sampled))+ylab("Frequency")#+facet_wrap(~Year)
# HistDischarge
# theme_set(theme_bw(base_size = 12)+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()))
# mean(metadata$DischargeSampledByNight,na.rm=T)
# sd(metadata$DischargeSampledByNight,na.rm=T)
#
# dev.off()
# tiff("Figures/Discharge_Sampled.tiff", width = 3.3, height = 3.3, units = 'in', res = 800)
# HistDischarge
# dev.off()
#
#
# HistQ<-ggplot(metadata,aes(x=Q))+geom_histogram(fill="grey",color="black")+xlab(expression(River~Discharge~(m^3/sec)))+ylab("Frequency")#+facet_wrap(~Year)
# HistQ
# theme_set(theme_bw(base_size = 12)+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()))
#
# dev.off()
# tiff("Figures/Discharge_Q.tiff", width = 3.3, height = 3.3, units = 'in', res = 800)
# HistQ
# dev.off()
#discharge sampled sd = 0.407179 mean = 0.9361
#metadataOutliers
taxmatrixfull=as.matrix(read.table("DataClean\\SturgeonDriftInvertTaxNames8.15.19.txt"))
#head(taxmatrixfull)
cbPalette <- c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#000000","#CC79A7")
theme_set(theme_bw(base_size = 12)+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()))
#sets the plotting theme
OTU=otu_table(otufull, taxa_are_rows=TRUE)
#OTU
TAX=tax_table(taxmatrixfull)
colnames(TAX)=("Family")
sampdat=sample_data(metadata)
sample_names(sampdat)=sampdat$SampleID
#head(sampdat)
taxa_names(TAX)=row.names(OTU)
physeq=phyloseq(OTU,TAX,sampdat)#joins together OTU,TAX, and metadata
physeq
levels(sample_data(physeq)$MoonPhase)
sample_data(physeq)$MoonPhase = factor(sample_data(physeq)$MoonPhase, levels = c("New Moon","Waxing Crescent","First Quarter","Waxing Gibbous","Full Moon","Waning Gibbous","Last Quarter","Waning Crescent"))
#levels(sample_data(physeq)$CODE)=c("NM","WXC","FQ","WXG","FM","WAG","LQ","WNC")
Richness=plot_richness(physeq, x="DPFS", measures=c("Shannon"))#+geom_boxplot(aes(x=DPFS, y=value, color=DPFS), alpha=0.05)
#Richness$data
write.csv(Richness$data, "SturgeonMetadataWDiversity.csv")
ShannonRichness<-read.csv("SturgeonMetadataWDiversity.csv",header=T)
#####################
#General Result info
####################
AllData<-metadata
AllData$Date2<-as.Date(AllData$Date,format= "%d-%B")
head(AllData)
AllData$Year
SamplesByYear <- ddply(AllData, c("Year"), summarise,
N = length(SampleID),
Sturgeon = sum(Nsturgeon),
Inverts5 = sum(Ninverts),
Inverts100 = sum(Ninverts100),
Catostomidae = sum(Nsuckers100)
)
SamplesByYear
mean(SamplesByYear$N) #Average number of days per year= 30
sum(SamplesByYear$N) #Total number of sampling days= 240
sum(AllData$Ninverts) #Number of invertebrates IDed = 21356
sum(AllData$Ninverts100) #100% numbers for inverts = 427,120
sum(AllData$Nsturgeon) #Total number of sturgeon larvae collected = 108,674
sum(AllData$Nsuckers100)#number of catostomidae larvae = 1,619,320
mean(AllData$percillum) #48.96%
min(AllData$percillum) #0
max(AllData$percillum) #100
mean(AllData$DPFS) #36.425
median(AllData$DPFS) #36
min(AllData$DPFS) #min 15
max(AllData$DPFS) #max 68
mean(AllData$Ninverts100) #1779.66
min(AllData$Ninverts100) #40
max(AllData$Ninverts100) #12340
sd = sd(AllData$Ninverts100) #
sd
sd(AllData$Ninverts100) #1574.3
sd / sqrt(length(AllData$Ninverts100))
se #101.62
mean(AllData$Nsturgeon) #452.8
min(AllData$Nsturgeon) #0
max(AllData$Nsturgeon) #16,897
sd = sd(AllData$Nsturgeon) #
sd(AllData$Nsturgeon)
sd / sqrt(length(AllData$Nsturgeon)) #101,6
mean(AllData$Nsuckers100) #6747.16
min(AllData$Nsuckers100) #0
max(AllData$Nsuckers100)# 185,380
sd = sd(AllData$Nsuckers100) #
sd / sqrt(length(AllData$Nsuckers100)) #1261.7
head(AllData)
mean(AllData$InvertBiomass100) #96.4
min(AllData$InvertBiomass100) #0.59
max(AllData$InvertBiomass100)#85.52
#RiverQ
AllDataQ<-subset(AllData,Q!= "NA") #Remove sample dates where no flow data was collected (to calc se correctly using length)
sd(metadata$PercentRiverDischargeSampled,na.rm=T)
mean(AllDataQ$Q,na.rm=T) #8.165 m3/sec
min(AllDataQ$Q,na.rm=T) #4.035 m3/sec
max(AllDataQ$Q,na.rm=T) #16.83 m3/sec
sd = sd(AllDataQ$Q,na.rm=T)
se = sd / sqrt(length(AllDataQ$Q))
sd #2.22
se # 0.152
hist(AllDataQ$Q,xlab = "River Discharge (m3/sec)")
RiverDischargePlot<-ggplot(AllDataQ,aes(x=Q))+geom_histogram(binwidth = 1,fill="grey",color="black")+xlab(expression(River~Discharge~(m^3/~sec)))+ylab("Frequency")
dev.off()
tiff("Figures/RiverDischarge.tiff", width = 74, height = 74, units = 'mm', res = 1000)
RiverDischargePlot
dev.off()
AllDataTemp<-subset(AllData,Temp!= "NA") #Remove sample dates where no temp data was collected (to calc se correctly using length)
mean(AllDataTemp$Temp,na.rm=T) #19.03
min(AllDataTemp$Temp,na.rm=T) #12.22
max(AllDataTemp$Temp,na.rm=T) #23.34
sd = sd(AllDataTemp$Temp,na.rm=T)
se = sd / sqrt(length(AllDataTemp$Temp))
sd #2.53
se #0.165
#Day of year sampled
min(AllData$DayOfYear) #130 April 17
max(AllData$DayOfYear) #186 May 9th
#Percent River discharge sampled
AllDataPercent<-subset(AllData,PercentRiverDischargeSampled!= "NA") #Remove sample dates where no flow data was collected (to calc se correctly using length)
mean(AllDataPercent$PercentRiverDischargeSampled,na.rm=T) #12.44
min(AllDataPercent$PercentRiverDischargeSampled,na.rm=T) #4.89
max(AllDataPercent$PercentRiverDischargeSampled,na.rm=T) #45.31
sd= sd(AllDataPercent$PercentRiverDischargeSampled, na.rm=T)
se = sd / sqrt(length(AllDataPercent$PercentRiverDischargeSampled))
sd #6.16
se #0.433
head(AllData)
ggplot(AllData,aes(x=Date,y=InvertBiomass100))+geom_point()+geom_smooth()+ylab("Inverts Biomass (g)")+xlab("Percent Illumination")
ggplot(AllData,aes(x=Q,y=Ninverts100))+geom_point()+facet_wrap(~Year)+xlab("River Discharge (m3/sec)")
ggplot(AllData,aes(x=Q,y=Ninverts100))+geom_point()+facet_wrap(~Year)+geom_smooth()+xlab("River Discharge (m3/sec)")
ggplot(AllData,aes(x=Q,y=Ninverts100))+geom_point()+xlab("River Discharge (m3/sec)")
ggplot(AllData,aes(x=DischargeSampledByNight,y=Ninverts100))+geom_point()+xlab("Discharge Sampled (m3/sec)")+facet_wrap(~Year)
ggplot(AllData,aes(x=DischargeSampledByNight,y=InvertBiomass100))+geom_point()+xlab("Discharge Sampled (m3/sec)")+geom_smooth()
ggplot(AllData,aes(x=DPFS,y=DischargeSampledByNight))+geom_point()+facet_wrap(~Year)
theme_set(theme_bw(base_size = 10)+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()))
AllDataGaps=read.csv("DataClean\\SturgeonDriftMetadata5.6.2020WGAPS.csv",header=TRUE)#USE THIS FILE INSTEAD OF METADATA TO ADD BREAKS TO DISCHARGE LINE FOR GAPS IN DRIFT STURGEON COLLECTIONS
SturgeonCTU<-ggplot(AllDataGaps,aes(x=CTUSturgeon))+geom_point(size=0.75,aes(y=Nsturgeon),shape=19)+geom_line(aes(y=Q/0.002),color="blue")+scale_y_continuous(sec.axis = sec_axis(~.*0.002,name=expression(River~Discharge~(m^3/sec))))+xlab("Cumulative Thermal Units from First Spawn")+facet_wrap(~Year,scale="free_y")+ylab("Lake Sturgeon Larvae")
SturgeonCTU
dev.off()
tiff("Figures/SturgeonCTU.tiff", width = 84, height = 84, units = 'mm', res = 1200)
SturgeonCTU
dev.off()
ggplot(AllData,aes(x=CTUSturgeon,y=Nsuckers100))+geom_point()+xlab("Cumulative Thermal Units")+facet_wrap(~Year)+ylab("Sucker Larvae")
min(AllData$Nsturgeon,na.rm=T)
max(AllData$Nsturgeon,na.rm=T)
min(AllData$Q,na.rm=T)
max(AllData$Q,na.rm=T)
cor(AllData$DayOfYear,AllData$percillum,method="pearson")
cor(AllData$DayOfYear,AllData$CTUSturgeon,method="pearson")
ggplot(AllData,aes(x=Date2,y=Ninverts100))+geom_bar(stat="identity")+xlab("Date")
ggplot(AllData,aes(x=DayOfYear,y=log(Ninverts100)))+geom_point()+xlab("Day of Year")#+facet_wrap(~Year)
ggplot(AllData,aes(x=Date2,y=DayOfYear))+geom_point()+ facet_wrap(~Year)#geom_jitter()
ggplot(AllData,aes(x=DayOfYear,y=LunarDay))+geom_point()+ facet_wrap(~Year)#geom_jitter()
AllData$MoonPhase = factor(AllData$MoonPhase, levels = c("New Moon","Waxing Crescent","First Quarter","Waxing Gibbous","Full Moon","Waning Gibbous","Last Quarter","Waning Crescent"))
ggplot(AllData,aes(x=MoonPhase,y=percillum))+geom_point()+ facet_wrap(~Year)#geom_jitter()
LightDate<-ggplot(AllData,aes(x=Date2,y=percillum))+geom_point()+ facet_wrap(~Year)+xlab("Date")+ylab("Lunar Illumination (%)")#geom_jitter()
LightDate
LightCTU<-ggplot(AllData,aes(x=CTUSturgeon,y=percillum))+geom_point()+ facet_wrap(~Year)+xlab("Cumulative Temperature Units (CTU)")+ylab("Lunar Illumination (%)")#geom_jitter()
LightCTU
AllData$Ctu
ggplot(AllData,aes(x=Date2,y=CTUSturgeon))+geom_point()+facet_wrap(~Year)
dev.off()
tiff("Figures/IllumByDate.tiff", width = 174, height = 174, units = 'mm', res = 1200)
LightDate
dev.off()
################
#Total Abu graphs
#################
SturgeonDataFrame<-data.frame("Sturgeon",ShannonRichness$DayOfYear, ShannonRichness$CTUSturgeon,ShannonRichness$Year,ShannonRichness$Nsturgeon,ShannonRichness$InvertsByDischargeSampled)
colnames(SturgeonDataFrame)<-c("Taxa","DayOfYear","CTUSturgeon","Year","Abundance","Conc")
SuckerDataFrame<-data.frame("Catostomidae",ShannonRichness$DayOfYear, ShannonRichness$CTUSturgeon,ShannonRichness$Year,ShannonRichness$Nsuckers100,ShannonRichness$SuckerConc)
colnames(SuckerDataFrame)<-c("Taxa","DayOfYear","CTUSturgeon","Year","Abundance","Conc")
InvertDataFrame<-data.frame("Invertebrate",ShannonRichness$DayOfYear,ShannonRichness$CTUSturgeon,ShannonRichness$Year,ShannonRichness$Ninverts100, ShannonRichness$SturgeonConc)
colnames(InvertDataFrame)<-c("Taxa","DayOfYear","CTUSturgeon","Year","Abundance","Conc")
PlottingDataframe<-rbind(SturgeonDataFrame,SuckerDataFrame,InvertDataFrame)
PlottingDataframe[is.na(PlottingDataframe)] <- 0 #Change NA values to 0 as no taxa were observed on those dates but sampling occured
head(PlottingDataframe)
PlottingDataframe$Taxa = factor(PlottingDataframe$Taxa, levels = c("Invertebrate","Sturgeon","Catostomidae"))
theme_set(theme_bw(base_size = 8)+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()))
TotalAbuAllPlot<-ggplot(PlottingDataframe, aes(x=DayOfYear, y= Abundance))+facet_grid(Taxa~.,scales = "free_y")+geom_point(size=1)+
theme(legend.justification=c(1,0), legend.position=c(1,-0.01))+ylab(expression(Abundance~Per~100~m^3~Drift))+xlab("Calendar Date")+
scale_fill_manual(values=cbPalette)+scale_color_manual(values=cbPalette)+theme(legend.text = element_text(size = 7),legend.title = element_blank())+
theme(legend.background=element_blank())+ guides(shape = guide_legend(override.aes = list(size=2)))#+geom_line()
TotalAbuAllPlot
#######
########Data by quantile ranks
#######
AllDataDPFS= mutate(AllData, quantile_rank = ntile(AllData$percillum,4))
head(AllDataDPFS)
Trtdata <- ddply(AllDataDPFS, c("quantile_rank"), summarise,
N = length(Ninverts100),
meanInverts = mean(Ninverts100),
sd = sd(Ninverts100),
se = sd / sqrt(N)
)
ggplot(Trtdata,aes(x=quantile_rank,y=meanInverts))+geom_point()+xlab("Percent Illumination Quartiles")+
geom_errorbar(aes(ymin=meanInverts-se,ymax=meanInverts+se))+ylab("Invertebrates Per Night (+/- SE)")
ShannonRichnessDischargeSampled = mutate(AllData, quantile_rank = ntile(AllData$DischargeSampledByNight,4))
head(ShannonRichnessDischargeSampled)
Trtdata <- ddply(ShannonRichnessDischargeSampled, c("quantile_rank"), summarise,
N = length(Ninverts100),
meanInverts = mean(Ninverts100),
sd = sd(Ninverts100),
se = sd / sqrt(N)
)
ggplot(Trtdata,aes(x=quantile_rank,y=meanInverts))+geom_point()+xlab("Discharge Sampled Quartiles")+
geom_errorbar(aes(ymin=meanInverts-sd,ymax=meanInverts+sd))+ylab("Invertebrates Per Night (+/- 1 SD)")
Trtdata <- ddply(ShannonRichnessDischargeSampled, c("quantile_rank"), summarise,
N = length(InvertBiomass100),
meanInverts = mean(InvertBiomass100),
sd = sd(InvertBiomass100),
se = sd / sqrt(N)
)
ggplot(Trtdata,aes(x=quantile_rank,y=meanInverts))+geom_point()+xlab("Discharge Sampled Quartiles")+
geom_errorbar(aes(ymin=meanInverts-sd,ymax=meanInverts+sd))+ylab("Invertebrate Biomass Per Night (+/- 1 SD)")
############
#Combined Summary plots
###########
AllData<-metadata
SamplesByYear <- ddply(AllData, c("Year"), summarise,
N = length(SampleID),
Sturgeon = sum(Nsturgeon),
SturgeonByNight = mean(Nsturgeon),
sdSturgeonByNight = sd(Nsturgeon),
seSturgeonByNight = sdSturgeonByNight/sqrt(N),
Inverts5 = sum(Ninverts),
Inverts100 = sum(Ninverts100),
InvertsByNight = mean(Ninverts100),
sdInvertsByNight = sd(Ninverts100),
seInvertsByNight = sdInvertsByNight/sqrt(N),
CatostomidaeByNight = mean(Nsuckers100),
sdSuckers = sd(Nsuckers100),
seSuckers = sdSuckers/sqrt(N)
)
SamplesByYear
SturgeonByYearByNight<- ggplot(SamplesByYear, aes(x=Year,y=SturgeonByNight))+geom_bar(stat="identity",color="black",fill = "grey")+ylab("Sturgeon Per Night (SE)")+
geom_errorbar(aes(ymin=SturgeonByNight-seSturgeonByNight,ymax=SturgeonByNight+seSturgeonByNight))
InvertsByYearByNight<-ggplot(SamplesByYear, aes(x=Year,y=InvertsByNight))+geom_bar(stat="identity",color="black",fill = "grey")+ylab("Invertebrates Per Night (SE)")+
geom_errorbar(aes(ymin=InvertsByNight-seInvertsByNight,ymax=InvertsByNight+seInvertsByNight))
SuckersByYearByNight<-ggplot(SamplesByYear, aes(x=Year,y=CatostomidaeByNight))+geom_bar(stat="identity",color="black",fill = "grey")+ylab("Catostomidae larvae Per Night (SE)")+
geom_errorbar(aes(ymin=CatostomidaeByNight-seSuckers,ymax=CatostomidaeByNight+seSuckers))
SturgeonByYearByNight
InvertsByYearByNight
SuckersByYearByNight
SturgeonByYear<- ggplot(SamplesByYear, aes(x=Year,y=Sturgeon))+geom_bar(stat="identity",color="black",fill = "grey")+ylab("Sturgeon larvae")
SturgeonByYear
InvertsByYear<-ggplot(SamplesByYear, aes(x=Year,y=Inverts100))+geom_bar(stat="identity",color="black",fill = "grey")+ylab("Invertebrates collected")
theme_set(theme_bw(base_size = 14)+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()))
dev.off()
tiff("Figures/TotalsByYearCombined.tiff", width = 6.85, height = 6.85, units = 'in', res = 300)
ggarrange(SturgeonByYear,InvertsByYear,SturgeonByYearByNight,InvertsByYearByNight,
labels = c("a", "b","c","d"),
ncol = 2, nrow = 2)
dev.off()
theme_set(theme_bw(base_size = 12)+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()))
#Sucker abu by day and year
Trtdata <- ddply(AllData, c("DPFS","Year"), summarise,
N = length(Nsuckers100),
meanSuckers = mean(Nsuckers100)
)
#Trtdata
SuckersByDPFS<-ggplot(Trtdata, aes(x=DPFS,y=meanSuckers))+geom_bar(colour="black", stat="identity")+xlab("Days Post First Spawning")+ylab("Catostomidae Abundance")+
theme(axis.text.x = element_text(angle = 0, hjust = 0.5))+facet_grid(Year~.)#+scale_fill_manual(values=cbPalette)
SuckersByDPFS
theme_set(theme_bw(base_size = 10)+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()))
dev.off()
tiff("Figures/SuckerAbundanceSupplementalFig.tiff", width = 6.85, height = 4, units = 'in', res = 800)
ggarrange(SuckersByYearByNight,SuckersByDPFS,
labels = c("a", "b"),
ncol = 2, nrow = 1)
dev.off()
#Sturgeon abu by day and year
Trtdata <- ddply(AllData, c("DPFS","Year"), summarise,
N = length(Nsuckers100),
meanSturgeon = mean(Nsturgeon)
)
#Trtdata
SturgeonByDPFS<-ggplot(Trtdata, aes(x=DPFS,y=meanSturgeon))+geom_bar(colour="black", stat="identity")+xlab("Days Post First Spawning")+ylab("Larval Sturgeon Abundance")+
theme(axis.text.x = element_text(angle = 0, hjust = 0.5))+facet_grid(Year~.)#+scale_fill_manual(values=cbPalette)
SturgeonByDPFS
#Invertebrate abu by day and year
Trtdata <- ddply(AllData, c("DPFS","Year"), summarise,
N = length(Ninverts100),
meanInvert = mean(Ninverts100)
)
#Trtdata
InvertByDPFS<-ggplot(Trtdata, aes(x=DPFS,y=meanInvert))+geom_bar(colour="black", stat="identity")+xlab("Days Post First Spawning")+ylab("Invertebrate Abundance")+
theme(axis.text.x = element_text(angle = 0, hjust = 0.5))+facet_grid(Year~.)#+scale_fill_manual(values=cbPalette)
InvertByDPFS
theme_set(theme_bw(base_size = 9)+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()))
dev.off()
tiff("Figures/SturgeonInvertByDPFSByYear.tiff", width = 174, height = 174, units = 'mm', res = 1000)
ggarrange(SturgeonByYearByNight,InvertsByYearByNight,SturgeonByDPFS, InvertByDPFS,
labels = c("a", "b","c","d"),
ncol = 2, nrow = 2)
dev.off()
#Sucker supplemental figure
dev.off()
tiff("Figures/SuckersCombinedByYear.tiff", width = 174, height = 84, units = 'mm', res = 1000)
ggarrange(SuckersByYearByNight,SuckersByDPFS,
labels = c("a", "b"),
ncol = 2, nrow = 1)
dev.off()
theme_set(theme_bw(base_size = 12)+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()))
#####################
#Alpha diversity
####################
#Shannon Richness
head(sample_data(physeq))
Richness=plot_richness(physeq, x="DPFS", measures=c("Shannon"))#+geom_boxplot(aes(x=DPFS, y=value, color=DPFS), alpha=0.05)
Richness+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())+xlab("DPFS")
#Richness$data
write.csv(Richness$data, "SturgeonMetadataWDiversity.csv")
ShannonRichness<-read.csv("SturgeonMetadataWDiversity.csv",header=T)
head(ShannonRichness)
levels(ShannonRichness$MoonPhase)
levels(metadata$MoonPhase)
#Days post first spawn
Trtdata <- ddply(ShannonRichness, c("DPFS"), summarise,
N = length(value),
meanShannon = mean(value),
sd = sd(value),
se = sd / sqrt(N)
)
#Trtdata
theme_set(theme_bw(base_size = 12)+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()))
ggplot(Trtdata, aes(x=DPFS,y=meanShannon))+geom_bar(aes(),colour="black", stat="identity")+xlab("Days post first spawn")+ylab("Shannon (SEM)")+
geom_errorbar(aes(ymin=meanShannon-se,ymax=meanShannon+se))
hist(ShannonRichness$percillum)
hist(log(ShannonRichness$Ninverts100))
hist((ShannonRichness$Ninverts100))
#ShannonSubset$percillum
hist(ShannonRichness$Ninverts100)
m1 = glmer(Ninverts100~1+(1|Year),data=ShannonRichness,family = poisson)
m2 = glmer(Ninverts100~percillum+(1|Year),data=ShannonRichness,family = poisson)
#m3 = glmer.nb(Ninverts100~DPFS+percillum+(1|Year),data=ShannonSubset)
m1=glm(Ninverts100~percillum,data=ShannonRichness,family=poisson)
summary(m1)
head(ShannonRichness)
AIC(m1,m2)
summary(m2)
plot(Ninverts100~percillum,data=ShannonRichness)
lines(predict(m2) ~ ShannonRichness$percillum)
ShannonRichness$MoonPhase = factor(ShannonRichness$MoonPhase, levels = c("New Moon","Waxing Crescent","First Quarter","Waxing Gibbous","Full Moon","Waning Gibbous","Last Quarter","Waning Crescent"))
levels(ShannonRichness$MoonPhase)
AbuBoxplot<-ggplot(ShannonRichness, aes(x=MoonPhase,y=Ninverts100))+geom_boxplot()+scale_x_discrete(labels=c("New","WXC","FQ","WXG","Full","WAG","LQ","WNC"))+
theme(axis.text.x = element_text(angle = 45, hjust = 1))+ylab("Total Invertebrates Per Night")+xlab("Moon Phase")
dev.off()
tiff("Figures/AbuBoxplotByMoonPhase.tiff", width = 3.3, height = 3.3, units = 'in', res = 800)
AbuBoxplot
dev.off()
AbuDotplotDPFS<-ggplot(ShannonRichness, aes(x=DPFS,y=Ninverts100))+geom_point()+
theme(axis.text.x = element_text(angle = 0, hjust = 0.5))+ylab("Total Invertebrates Per Night")+xlab("Days Post First Spawning")
AbuDotplotDPFS
dev.off()
tiff("Figures/AbuDotplotByMoonPhase.tiff", width = 3.3, height = 3.3, units = 'in', res = 800)
AbuDotplotDPFS
dev.off()
#By calendar date
Trtdata <- ddply(ShannonRichness, c("DayOfYear"), summarise,
N = length(value),
meanShannon = mean(value),
sd = sd(value),
se = sd / sqrt(N)
)
ggplot(Trtdata, aes(x=DayOfYear,y=meanShannon))+geom_bar(colour="black", stat="identity")+xlab("Calendar date")+ylab("Shannon (SEM)")+
geom_errorbar(aes(ymin=meanShannon-se,ymax=meanShannon+se))+ theme(axis.text.x = element_text(angle = 45, hjust = 1))
#Moon phase
Trtdata <- ddply(ShannonRichness, c("MoonPhase"), summarise,
N = length(value),
meanShannon = mean(value),
sd = sd(value),
se = sd / sqrt(N)
)
Trtdata
ggplot(Trtdata, aes(x=MoonPhase,y=meanShannon))+geom_bar(aes(fill = MoonPhase),colour="black", stat="identity")
ggplot(Trtdata, aes(x=MoonPhase,y=meanShannon))+geom_bar(aes(fill = MoonPhase),colour="black", stat="identity")+xlab("Moon Phase")+ylab("Shannon Diversity (SEM)")+
geom_errorbar(aes(ymin=meanShannon-se,ymax=meanShannon+se))+ theme(axis.text.x = element_text(angle = 45, hjust = 1))+scale_fill_manual(values=cbPalette)+ theme(legend.position = "none")+
geom_text(x=6.5,y=2,label="KW, Chi2=10.5, p= 0.158")
kruskal.test(value~MoonPhase,data=ShannonRichness)
hist(ShannonRichness$value)
ggplot(ShannonRichness,aes(x=LunarDay,y=value))+geom_point()
#Temperature
ggplot(ShannonRichness, aes(x=Temp,y=value))+geom_point()+xlab("Calendar date")+ylab("Shannon (SEM)")+ theme(axis.text.x = element_text(angle = 45, hjust = 1))+
geom_smooth()
Temps<-subset(ShannonRichness, Temp!= "NA")
Temps
head(Temps)
mean(Temps$Temp)
Temps$temp_centered = Temps$Temp - mean(Temps$Temp)
plot(Temps$value~Temps$temp_centered,xlab="Change from mean temp (19.027)", ylab="Shannon diversity")+abline(1.504,0.02275)
m = glm(value~ temp_centered, data=Temps)
summary(m)
m2 = lmer(value~temp_centered+(1|Year),data=Temps)
m1 = lmer(value~1+(1|Year),data=Temps)
anova(m1,m2,test='Chisq')
confint(m2)
summary(m2)
m4 = lmer(value~temp_centered*MoonPhase+(1|Year),data=Temps)
m5 = lmer(value~temp_centered+MoonPhase+(1|Year),data=Temps)
summary(m2)
AIC(m1,m3,m4,m5)
m1=glm(value~temp_centered+Year,data=Temps)
plot(residuals(m1)~Temp,data=Temps)
plot(resid(m1) ~ predict(m1))
m2 = lmer(value~DPFS+(1|Year),data=ShannonRichness,family)
m1 = lmer(value~1+(1|Year),data=ShannonRichness)
m1<-glm(value~temp_centered+percillum,data=Temps)
anova(m1,m2,test='Chisq')
confint(m2)
summary(m2)
head(Temps)
Percillum<-subset(ShannonRichness, percillum!= "#VALUE!")
Percillum$ni
plot(Ninverts100~percillum,data=Percillum)
Percillum$percillum<-as.numeric(Percillum$percillum)
m2<-(glm(value~percillum+Q,data=Percillum))
m2
plot(residuals(m2)~percillum,data=Percillum)
confint(m2)
hist(Percillum$percillum)
Percillum$percillum
#Total abundance percent illum test
m4 = glmer(Ninverts100~percillum+(1|Year),data=Percillum,family="poisson")
m5 = glmer(Ninverts100~1+(1|Year),data=Percillum,family="poisson")
anova(m4,m5,test='chisq')
confint(m4)
exp(.01)
m5 = glmer(value~temp_centered+MoonPhase+(1|Year),data=Temps,family="poisson")
summary(m4)
confint(m4)
summary(glm(Ninverts100~percillum,data=Percillum))
#By discharge
ShannonRichnessQ = mutate(ShannonRichness, quantile_rank = ntile(ShannonRichness$Q,4))
head(ShannonRichnessQ)
Trtdata <- ddply(ShannonRichnessQ, c("quantile_rank"), summarise,
N = length(value),
meanShannon = mean(value),
sd = sd(value),
se = sd / sqrt(N)
)
#Trtdata
theme_set(theme_bw(base_size = 12)+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()))
ggplot(Trtdata, aes(x=quantile_rank,y=meanShannon))+geom_bar(aes(),colour="black", stat="identity")+xlab("Shannon Quartile")+ylab("Shannon (SEM)")+
geom_errorbar(aes(ymin=meanShannon-se,ymax=meanShannon+se))
hist(ShannonRichnessQ$value)
####################
##Total Abundance larval fish
####################
#Sturgeon
ggplot(ShannonRichness,aes(x=CTUSturgeon,y=Nsturgeon))+geom_point()#+geom_bar(aes(fill=DPFS),stat = "identity")
SubsetCTU<-subset(ShannonRichness, CTUSturgeon < 500&CTUSturgeon>250)
sum(SubsetCTU$Nsturgeon)/sum(ShannonRichness$Nsturgeon)*100
max(ShannonRichness$CTUSturgeon)
SubsetDrift<-subset(ShannonRichness,Nsturgeon>0)
SubsetDrift$Nsturgeon
min(SubsetDrift$CTUSturgeon)
Trtdata <- ddply(ShannonRichness, c("DPFS","Year"), summarise,
N = length(Nsturgeon),
meanSturgeon = mean(Nsturgeon),
sd = sd(Nsturgeon),
se = sd / sqrt(N)
)
Trtdata
#Subset<-subset(Trtdata,Year=="2018"|Year=="2017"|Year=="2016")
SturgeonByDPFS<-ggplot(Trtdata, aes(x=DPFS,y=meanSturgeon))+geom_bar(colour="black", stat="identity")+xlab("Days Post First Spawning")+ylab("Larval Sturgeon Abundance")+
geom_errorbar(aes(ymin=meanSturgeon-se,ymax=meanSturgeon+se))+ theme(axis.text.x = element_text(angle = 45, hjust = 1))+facet_grid(Year~.)#+scale_fill_manual(values=cbPalette)
dev.off()
tiff("Figures/SturgeonByDPFSYear.tiff", width = 3.3, height = 3.3, units = 'in', res = 300)
SturgeonByDPFS
dev.off()
#SturgeonByMoonPhase
SturgeonLarvaeSubset<-subset(ShannonRichness,Nsturgeon>0)
Trtdata <- ddply(SturgeonLarvaeSubset, c("DayOfYear","Year","MoonPhase"), summarise,
N = length(Nsturgeon),
meanSturgeon = mean(Nsturgeon),
sd = sd(Nsturgeon),
se = sd / sqrt(N)
)
Trtdata
ggplot(Trtdata, aes(x=MoonPhase,y=meanSturgeon,color=MoonPhase))+geom_point()+xlab("DoY")+ylab("Larval Sturgeon Abundance (SEM)")+
geom_errorbar(aes(ymin=meanSturgeon-se,ymax=meanSturgeon+se))+ theme(axis.text.x = element_text(angle = 45, hjust = 1))#+facet_grid(~Year)#+scale_fill_manual(values=cbPalette)
ggplot(ShannonRichness, aes(x=CTUSturgeon,y=SturgeonConc))+geom_point()+xlab("DoY")+ylab("Larval Sturgeon Abundance (SEM)")#+
geom_errorbar(aes(ymin=meanSturgeon-se,ymax=meanSturgeon+se))+ theme(axis.text.x = element_text(angle = 45, hjust = 1))+geom_boxplot()#+facet_grid(~Year)#+scale_fill_manual(values=cbPalette)
ggplot(ShannonRichness, aes(x=CTUSturgeon,y=Nsuckers100))+geom_point()
ggplot(ShannonRichness, aes(x=Temp,y=Nsturgeon))+geom_point()
ggplot(ShannonRichness, aes(x=Temp,y=Ninverts100))+geom_point()
head(ShannonRichness)
gam_y <- gam(log(Nsuckers100+10e-5) ~ s(CTUSturgeon)+s(percillum)+s(Q)+s(Year,bs="re"), method = "REML",data=ShannonRichness)
gam_x <- gam(log(Nsuckers100+10e-5) ~ s(CTUSturgeon)+s(Year,bs="re")+s(percillum)+s(DischargeSampledByNight), method = "REML",data=ShannonRichness)
#gam.check(gam_y)
summary(gam_y)
gam.check(gam_y)
acf(resid(gam_y), lag.max = 36, main = "ACF")
library(mgcViz)
plot(gam_y)
dat <- gamSim(6,n=200,scale=.2,dist="poisson")
b2 <- gamm(y~s(x0)+s(x1)+s(x2),family=poisson,
data=dat,random=list(fac=~1))
fac <- dat$fac
ShannonCatGamSubset<-subset(ShannonRichness, CTUSturgeon!="NA")
head(ShannonCatGamSubset)
fac<-ShannonRichness$Year
ShannonRichness$Nsuckers100
SuckerGAM<-ggplot(ShannonRichness, aes(CTUSturgeon, (log(Nsuckers100)) )) + geom_point(color="grey") +stat_smooth(method = "gam", formula = y ~ s(x),se=FALSE,color="black")+
stat_smooth(method = "gam", formula = (y) ~ s(x),geom="ribbon",linetype="dashed",fill=NA,color="black",level = 0.95)+ylab("log(Larval Catostomidae Abundance)")+xlab("Cumulative Temperature Units")
SuckerGAM$layers
ShannonRichness$CTUSturgeon
SuckerAbuGamma <- gamm(((Nsuckers100+10e-5))~ s(CTUSturgeon), data = ShannonRichness, method = "REML",correlation=corAR1(form = ~DayOfYear|Year),family= Gamma(link = "log"))
summary(SuckerAbuGamma$gam)
gam.check(SuckerAbuGamma$gam)
fac<-ShannonRichness$Year
hist(log(ShannonRichness$Nsuckers100))
ShannonRichness$Year<-as.factor(ShannonRichness$Year)
SuckerAbuLog <- gam(log(Nsuckers100+10e-5)~ s(CTUSturgeon)+s(Year,bs="re"), data = ShannonRichness, method = "REML",correlation=corAR1(form = ~DayOfYear|Year))
summary(SuckerAbuLog)
gam.check(SuckerAbuLog)#default K doing ok no k significance, model residuals mostly ok around zero but a couple outliers around -10 to -15 (<5)
appraise(SuckerAbuLog)
response1 <- predict(SuckerAbuLog, type="response", se.fit=T)
head(response1)
plot(0,type="n",xlim=c(150,800),ylim=c(-10,500))
lines((smooth.spline(SuckerAbuLog$model$CTUSturgeon,response1$fit)),col="red")
data<-smooth.spline(SuckerAbuLog$model$CTUSturgeon,response1$fit)
head(data)
GAMConfints<-confint(SuckerAbuLog,parm="CTUSturgeon",type="confidence",nsim=1000)
head(GAMConfints)
PredictedDataFrame<-data.frame(exp(GAMConfints$est),GAMMConfints$CTUSturgeon,exp(GAMMConfints$upper),exp(GAMMConfints$lower))
colnames(PredictedDataFrame)<-c("Nsuckers100","CTUSturgeon","UpperCI","LowerCI")
head(PredictedDataFrame)
plot(SuckerAbuLog)
observed_fitted_plot(
SuckerAbuLog,
ylab = NULL,
xlab = NULL,
title = NULL,
subtitle = NULL,
caption = NULL
)
library(mgcViz)
Random<-ranef(SuckerAbuLog$lme)
Random$fac
newCTUDataata<-seq(min(ShannonRichness$CTUSturgeon, max(ShannonRichness$CTUSturgeon,1000)))
predict(SuckerAbuLog,newCTUDataata)
plot(SuckerAbuLog$gam)
AICctab(SuckerAbuLog$lme,SuckerAbuGamma$lme)
summary(SuckerAbuLog$gam)
new.CTU = seq(min(ShannonRichness$CTUSturgeon),max(ShannonRichness$CTUSturgeon),length= 10000)
SuckerAbuLog <- gam(log(Nsuckers100+10e-5)~ s(CTUSturgeon), data = ShannonRichness, method = "REML")
predict(SuckerAbuLog,newdata=new.CTU,type="response",se.fit=T)
newCTUData<-seq(min(ShannonRichness$CTUSturgeon, max(ShannonRichness$CTUSturgeon,length=1000)))
min(ShannonRichness$CTUSturgeon)
head(newCTUData)
fac<-ShannonRichness$Year
library(mgcViz)
library(gratia)
SuckerAbuLogViz <- gammV(log(Nsuckers100+10e-5)~ s(CTUSturgeon),random=list(fac=~1), data = ShannonRichness, method = "REML")
summary(SuckerAbuLogViz)
SuckerAbuLog <- gamm((log(Nsuckers100+10e-5))~ s(CTUSturgeon), data = ShannonRichness, method = "REML")
GAMMConfints<-confint(SuckerAbuGamma,parm="CTUSturgeon",type="confidence",nsim=1000)
head(GAMMConfints)
PredictedDataFrame<-data.frame(exp(GAMMConfints$est-10e-5),GAMMConfints$CTUSturgeon,exp(GAMMConfints$upper),exp(GAMMConfints$lower))
colnames(PredictedDataFrame)<-c("Nsuckers100","CTUSturgeon","UpperCI","LowerCI")
head(PredictedDataFrame)
GAMMSucker<-ggplot(ShannonRichness,aes(CTUSturgeon,Nsuckers100))+geom_point(color="darkgrey")+geom_line(data=PredictedDataFrame,size=1.5)#+
geom_line(data = PredictedDataFrame, aes(y = LowerCI), size = .75,linetype="dashed")+geom_line(data = PredictedDataFrame,aes(y=UpperCI),size=0.75,linetype="dashed")+
xlab(expression(Discharge~(m^3/sec)~Sampled))+ylab("Shannon Diversity")#+ theme(axis.title.y = element_text(size = 9))
GAMMSucker
ShannonSuckerSubset<-subset(ShannonRichness, Nsuckers100< 150000)
SuckerAbuGamma <- gam((Nsuckers100+10e-5)~ s(CTUSturgeon)+s(Year,bs="re"), data = ShannonRichness, method = "REML",correlation=corAR1(form = ~DayOfYear|Year),family= Gamma(link = "log"))
appraise(SuckerAbuGamma)
SuckerAbuGamma$residuals
SuckerAbuGamma$aic
hist(ShannonRichness$Nsuckers100)
###########
#Total InvertN By Moon Phase Normalized
############
Model<-aov(log(DriftInvertConc)~MoonPhase,data=ShannonRichness)
summary(Model)
hist(resid(Model))
kruskal.test(DriftInvertConc~MoonPhase, data=ShannonRichness)
Tukey<-TukeyHSD(Model,"MoonPhase")
Tukey
difference<-Tukey$MoonPhase[,"p adj"]
Letters<-multcompLetters(difference)
Letters
#
#
# compare_means(DriftInvertConc ~ MoonPhase, data = ShannonRichness, p.adjust.method = "fdr",method="wilcox.test")
#
# Means=compare_means(DriftInvertConc ~ MoonPhase, data = ShannonRichness, p.adjust.method = "fdr",method="wilcox.test")
#
# Hyphenated<-as.character(paste0(Means$group1,"-",Means$group2))
# difference<-Means$p.adj
# names(difference)<-Hyphenated
# Letters<-multcompLetters(difference)
# Letters
# Letters$Letters
# #manually renamed due to some weirdness with plotting where new moon donsn't start with a
LettersRearranged<-c("bc","abc","abc","a","ab","ab","ab","c")
DriftPlotNAsRemoved<-subset(ShannonRichness, DriftInvertConc!="NA")
DriftPlotNAsRemoved
Trtdata <- ddply(DriftPlotNAsRemoved, c("MoonPhase"), summarise,
N = length(DriftInvertConc),
meanSturgeon = mean(DriftInvertConc),
sd = sd(DriftInvertConc),
se = sd / sqrt(N),na.rm =T
)
Trtdata
Trtdata$MoonPhase = factor(Trtdata$MoonPhase, levels = c("New Moon","Waxing Crescent","First Quarter","Waxing Gibbous","Full Moon","Waning Gibbous","Last Quarter","Waning Crescent"))
TotalInvertAbuMoonPhase<-ggplot(Trtdata, aes(x=MoonPhase,y=meanSturgeon))+geom_bar(aes(fill=MoonPhase),stat="identity")+xlab("Moon Phase")+ylab(expression(Invertebrates~Per~100~m^3~Drift~(SE)))+
geom_errorbar(aes(ymin=meanSturgeon-se,ymax=meanSturgeon+se))+ theme(axis.text.x = element_text(angle = 0, hjust = 0.5),axis.title.y = element_text(size = 10))+scale_fill_manual(values=cbPalette)+
geom_text(aes(x=MoonPhase, y=meanSturgeon+se+1,label=LettersRearranged))+theme(legend.position = "none")+geom_text(aes(x=5,y=25,label= "ANOVA, F = 5.99, P < 0.001"),size=4)+
scale_x_discrete(labels=c("New","WXC","FQ","WXG","Full","WAG","LQ","WNC"))
TotalInvertAbuMoonPhase
theme_set(theme_bw(base_size = 12)+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()))
dev.off()
tiff("Figures/TotalInvertebrateAbuByPhaseNormalized.tiff", width = 74, height = 74, units = 'mm', res = 1200)
TotalInvertAbuMoonPhase
dev.off()
####################
#Total invert biomass By Moon Phase
#####################
head(ShannonRichness)
TotalInvertBiomass<-subset(ShannonRichness, DriftBiomassConc!="NA")
head(TotalInvertBiomass)
Trtdata <- ddply(TotalInvertBiomass, c("MoonPhase"), summarise,
N = length(DriftBiomassConc),
meanSturgeon = mean(DriftBiomassConc),
sd = sd(DriftBiomassConc),
se = sd / sqrt(N)
)
head(Trtdata)
Trtdata
Trtdata$MoonPhase = factor(Trtdata$MoonPhase, levels = c("New Moon","Waxing Crescent","First Quarter","Waxing Gibbous","Full Moon","Waning Gibbous","Last Quarter","Waning Crescent"))
kruskal.test(DriftBiomassConc~MoonPhase, data=ShannonRichness)
compare_means(DriftBiomassConc ~ MoonPhase, data = ShannonRichness, p.adjust.method = "fdr",method="wilcox.test")
Means=compare_means(DriftBiomassConc ~ MoonPhase, data = ShannonRichness, p.adjust.method = "fdr",method="wilcox.test")
Hyphenated<-as.character(paste0(Means$group1,"-",Means$group2))
difference<-Means$p.adj
names(difference)<-Hyphenated
Letters<-multcompLetters(difference)
Letters
Trtdata
vector<-c("bc","bc","abc","a","ab","b","ab","c")
DriftTotalInvertBiomass<-ggplot(Trtdata, aes(x=MoonPhase,y=meanSturgeon))+geom_bar(aes(fill=MoonPhase),stat="identity")+xlab("Moon Phase")+ylab(expression(Invertebrate~Biomass~(g)~Per~100~m^3~Drift~(SE)))+#Invertebrate Biomass (g) per 100 m3 drift (SEM)
geom_errorbar(aes(ymin=meanSturgeon-se,ymax=meanSturgeon+se))+ theme(axis.text.x = element_text(angle = 0, hjust = 0.5),axis.title.y = element_text(size = 8))+scale_fill_manual(values=cbPalette)+theme(legend.position = "none")+
geom_text(aes(x=MoonPhase, y=meanSturgeon+se+.08,label=vector))+geom_text(aes(x=5,y=1.5,label= "KW, chi-squared = 49.3, P < 0.001"),size=3)+
scale_x_discrete(labels=c("New","WXC","FQ","WXG","Full","WAG","LQ","WNC"))
DriftTotalInvertBiomass
theme_set(theme_bw(base_size = 12)+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()))
dev.off()
tiff("Figures/BiomassByPhase100m3.tiff", width = 3.3, height = 3.3, units = 'in', res = 800)
DriftTotalInvertBiomass
dev.off()
ShannonRichness
###############
#Relative abundance invert families by moon phase
######
RelTaxa3Per = transform_sample_counts(physeq, function(x) x / sum(x) ) #transform samples based on relative abundance
RelTaxa3Per = filter_taxa(RelTaxa3Per, function(x) mean(x) > 3e-2, TRUE) #filter out any taxa lower tha 0.1%
df <- psmelt(RelTaxa3Per)
df$Abundance<-df$Abundance*100
head(df)
Trtdata <- ddply(df, c("MoonPhase","Family"), summarise,
N = length(Abundance),
mean = mean(Abundance),
sd = sd(Abundance),
se = sd / sqrt(N)
)
Trtdata
SubsetTotalAbuFamilies<-subset(Trtdata,Family=="Chironomidae"|Family=="Crayfish"|Family=="Ephemerillidae"|Family=="Heptageniidae"|Family=="Hydropsychidae"|Family=="Isonychiidae"|Family=="Leptoceridae")
SubsetTotalAbuFamilies
write.csv(SubsetTotalAbuFamilies,file="FamilyLevelTotalAbundanceMoonPhase.csv") #Write in other category sum to 100
Trtdata<-read.csv("FamilyLevelTotalAbundanceMoonPhase.csv", header=T)
head(Trtdata)
Trtdata$MoonPhase = factor(Trtdata$MoonPhase, levels = c("New Moon","Waxing Crescent","First Quarter","Waxing Gibbous","Full Moon","Waning Gibbous","Last Quarter","Waning Crescent"))
#Trtdata
compare_means(Abundance ~ MoonPhase, data = df, group.by = "Family", p.adjust.method = "fdr",method="kruskal.test")
Means<-compare_means(Abundance ~ MoonPhase, data = df, group.by = "Family", p.adjust.method = "fdr",method="wilcox.test")
SigList<-length(unique(Trtdata$Family))
for (i in levels(Means$Family)){
Tax<-i
TaxAbundance<-subset(Means,Family==i )
Hyphenated<-as.character(paste0(TaxAbundance$group1,"-",TaxAbundance$group2))
difference<-TaxAbundance$p.adj
names(difference)<-Hyphenated
Letters<-multcompLetters(difference)
#print(Letters)
SigList[i]<-Letters
}
vec<-unlist(SigList)
vec<-vec[-1]
(vec)
#For unadjusted p values
# vector<-c("","","","","","","","",
# "a","ab","ab","b","b","ab","a","a",
# "","","","","","","","",
# "abc","ab","abc","a","abc","c","bc","bc",
# "","","","","","","","",
# "a","ab","cd","c","bcd","d","abd","a",
# "","","","","","","","")
# length(vec)
# length(vector)
TrtdataSorted<-Trtdata[order(Trtdata$Family),]
head(TrtdataSorted)
KruskalLabel<- c("Kruskal-Wallis,\n P-adj = 0.45","KW, P-adj = 0.04","KW, P-adj = 1", "KW, P-adj = 0.016","KW, P-adj = 0.5"," P-adj <0.001","KW, P-adj = 0.62")
FamilyRelativeAbu=ggplot(TrtdataSorted, aes(x=MoonPhase,y=mean))+geom_bar(aes(fill = Family),colour="black", stat="identity")+xlab("Moon Phase")+
ylab("Relative Invertebrate Abundance (%, SEM)") + theme(axis.text.x = element_text(angle = 45, hjust = 1))+geom_errorbar(aes(ymin=mean-se,ymax=mean+se))+
facet_wrap(Family~.)+scale_fill_manual(values=cbPalette)+theme(legend.position = "none")+ annotate("text", label = KruskalLabel, size = 1.75, x = 4, y = 50)+
scale_x_discrete(labels=c("New","WXC","FQ","WXG","Full","WAG","LQ","WNC"))
FamilyRelativeAbu
theme_set(theme_bw(base_size = 8)+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()))
dev.off()
tiff("Figures/FamiyLevelRelAbu.tiff", width = 84, height = 84, units = 'mm', res = 1200)
FamilyRelativeAbu
dev.off()
############
#Total Abundance Family by Moon phase
############
DriftDataCombined<-read.csv("DataClean\\AllDriftDataCombined2011-2018FamilyRichness.csv",header=T)
head(DriftDataCombined)
#Isonychiidae
kruskal.test(Isonychiidae~MoonPhase,data=DriftDataCombined)
Means<-compare_means(Isonychiidae ~ MoonPhase, data = DriftDataCombined, p.adjust.method = "fdr")
Means