-
Notifications
You must be signed in to change notification settings - Fork 0
/
WildVsFarmWrasse-PublicationPlots.R
3204 lines (2587 loc) · 174 KB
/
WildVsFarmWrasse-PublicationPlots.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
# Plots for publication
# Wild vs. farmed wrasse and acclimation paper
# Adam Brooker 9th November 2017
# Plot list
# 1a. wild vs. farmed temperature
# 1b. wild vs. farmed salinity
# 1c. wild vs. farmed DO
# 2a. acclimated vs. non-acclimated temperature
# 2b. acclimated vs. non-acclimated salinity
# 2c. acclimated vs. non-acclimated DO
# 3. Pen layout and segmentation plot
# 4. code to draw top view of pen 7 with colour-coded locations
# 5. code to draw side view of pen 7 with colour-coded locations
# 6. Locations for wild vs. farmed and acclimated vs. non-acclimated B
# 7. Hourly pen coverage night vs. day for wild vs. farmed and acclimated vs. non-acclimated B
# 8. Polar plots of headings for wild vs. farmed and acclimated vs. non acclimated B
# 9. Individual fish activity by time of day for wild, hatchery acclimated and hatchery and pen acclimated
# 10. Line plots of night and day depth and activity for non-acclimated and hatchery and pen-acclimated
# 11. Survival for wild vs. farmed and both acclimation trials
# 12. Heatmap of depth over time
# 13. Line plots of night and day depth for all three trials
# 14. Bar plots of individual fish night and day depth for all three trials
# 15. Line plots of night and day activity for all three trials
# 16. Bar plots of individual fish night and day activity for all three trials
# 17. Night and day Locations for wild vs. farmed and acclimated vs. non-acclimated B
# 18. Night and day Locations of individual fish for wild vs. farmed and acclimated vs. non-acclimated B
# 19. Examples of KUD plots for wild, farmed, non-acclimated and hatchery and pen acclimated
# 1. Environmental probe plots
library(rJava)
library(xlsxjars)
library(openxlsx)
library(dplyr)
library(ggplot2)
library(extrafont)
library(extrafontdb)
library(zoo)
library(grid)
library(reshape2)
library(cowplot)
library(data.table)
library(colorspace)
library(tidyverse)
library(adehabitat)
library(adehabitatHR)
library(pryr)
library(plyr)
# Environmental probe plots------------------------------
# LOAD ENVIRONMENTAL PROBE READINGS
masterfileloc = "H:/Data processing/AcousticTagFile_2015.xlsx" # 2015 wild vs. farmed wrasse
load.DO <- function(probename, colnums) {
pn <- probename
probename <- read.xlsx(masterfileloc, sheet = 13, startRow = 3, cols = colnums)
colnames(probename) <- c('Time', 'DO', 'Temp')
probename$Time <- as.POSIXct(strptime(probename$Time, "%m/%d/%y %I:%M:%S %p", tz = 'UTC'))
probename$Time <- probename$Time - as.difftime(1, unit = 'hours')
probename <- probename %>% mutate_at(.vars = vars(DO, Temp), .funs = funs(round(.,2)))
assign(pn, probename, envir = globalenv())
}
load.sal <- function(probename, colnums) {
pn <- probename
probename <- read.xlsx(masterfileloc, sheet = 13, startRow = 3, cols = colnums)
colnames(probename) <- c('Time', 'Sal')
probename$Time <- as.POSIXct(strptime(probename$Time, "%m/%d/%y %I:%M:%S %p", tz = 'UTC'))
probename$Time <- probename$Time - as.difftime(1, unit = 'hours')
probename <- probename %>% mutate(Sal = round(Sal, 2))
assign(pn, probename, envir = globalenv())
}
# load wild vs. farmed data
load.DO('probe.DOT1', colnums = c(1, 2, 3))
load.DO('probe.DOT4', colnums = c(6, 7, 8))
load.DO('probe.DOT8', colnums = c(11, 12, 13))
load.DO('probe.DOT12', colnums = c(16, 17, 18))
load.sal('probe.sal1', colnums = c(4, 5))
load.sal('probe.sal4', colnums = c(9, 10))
load.sal('probe.sal8', colnums = c(14, 15))
load.sal('probe.sal12', colnums = c(19, 20))
# combine all data into one data frame
probes <- cbind(probe.DOT1, probe.sal1, probe.DOT4, probe.sal4, probe.DOT8, probe.sal8, probe.DOT12, probe.sal12)
colnames(probes) <- c('do.time.1m', 'do.1m', 'temp.1m', 'sal.time.1m', 'sal.1m', 'do.time.4m', 'do.4m', 'temp.4m', 'sal.time.4m', 'sal.4m', 'do.time.8m', 'do.8m', 'temp.8m', 'sal.time.8m', 'sal.8m','do.time.12m', 'do.12m', 'temp.12m', 'sal.time.12m', 'sal.12m')
# subset for study start and end dates
probes <- subset(probes, do.time.1m > '2015-06-05 00:00:00' & do.time.1m < '2015-08-20 00:00:00')
# calculate rolling 6h-means for data
probes$rolldo1m <- c(rep(NA,23), rollapply(probes$do.1m, width = 24, FUN = mean, na.rm = T, align = 'right'))
probes$rolldo4m <- c(rep(NA,23), rollapply(probes$do.4m, width = 24, FUN = mean, na.rm = T, align = 'right'))
probes$rolldo8m <- c(rep(NA,23), rollapply(probes$do.8m, width = 24, FUN = mean, na.rm = T, align = 'right'))
probes$rolldo12m <- c(rep(NA,23), rollapply(probes$do.12m, width = 24, FUN = mean, na.rm = T, align = 'right'))
probes$rollt1m <- c(rep(NA,23), rollapply(probes$temp.1m, width = 24, FUN = mean, na.rm = T, align = 'right'))
probes$rollt4m <- c(rep(NA,23), rollapply(probes$temp.4m, width = 24, FUN = mean, na.rm = T, align = 'right'))
probes$rollt8m <- c(rep(NA,23), rollapply(probes$temp.8m, width = 24, FUN = mean, na.rm = T, align = 'right'))
probes$rollt12m <- c(rep(NA,23), rollapply(probes$temp.12m, width = 24, FUN = mean, na.rm = T, align = 'right'))
probes$rolls1m <- c(rep(NA,23), rollapply(probes$sal.1m, width = 24, FUN = mean, na.rm = T, align = 'right'))
probes$rolls4m <- c(rep(NA,23), rollapply(probes$sal.4m, width = 24, FUN = mean, na.rm = T, align = 'right'))
probes$rolls8m <- c(rep(NA,23), rollapply(probes$sal.8m, width = 24, FUN = mean, na.rm = T, align = 'right'))
probes$rolls12m <- c(rep(NA,23), rollapply(probes$sal.12m, width = 24, FUN = mean, na.rm = T, align = 'right'))
# 1a. wild vs. farmed temperature
ggplot(probes) +
scale_x_datetime('Date', limits = as.POSIXct(range(probes$do.time.1m))) +
scale_y_continuous(expression(paste('Temperature (', ~degree,'C)', sep='')), limits = c(8,15)) +
theme_classic() + theme(text = element_text(family = 'Times New Roman', size = 18), legend.position = c(0.90, 0.2)) +
#geom_line(aes(as.POSIXct(probes$do.time.1m), probes$do.1m), linetype = 'dashed') +
geom_line(aes(as.POSIXct(probes$do.time.1m), probes$rollt1m, colour = ' 1m', linetype = ' 1m')) + #, size = 0.7, color = 'gray', linetype = 'longdash') +
geom_line(aes(as.POSIXct(probes$do.time.4m), probes$rollt4m, colour = ' 4m', linetype = ' 4m')) + #, size = 0.7, color = 'gray', linetype = 'solid') +
geom_line(aes(as.POSIXct(probes$do.time.8m), probes$rollt8m, colour = ' 8m', linetype = ' 8m')) + #, size = 0.7, color = 'black', linetype = 'longdash') +
geom_line(aes(as.POSIXct(probes$do.time.12m), probes$rollt12m, colour = '12m', linetype = '12m')) + #, size = 0.7, color = 'black', linetype = 'solid') +
scale_colour_manual(name = '', values = c(' 1m' = 'gray', ' 4m' = 'gray', ' 8m' = 'black', '12m' = 'black')) +
scale_linetype_manual(name = '', values = c(' 1m' = 'longdash', ' 4m' = 'solid', ' 8m' = 'longdash', '12m' = 'solid')) +
annotation_custom(grobTree(textGrob('(a)', x = 0.05, y = 0.95, gp = gpar(fontsize = 18, fontfamily = 'Times New Roman'))))
# 1b. wild vs. farmed salinity
ggplot(probes) +
scale_x_datetime('Date', limits = as.POSIXct(range(probes$do.time.1m))) +
scale_y_continuous('Salinity (PSU)', limits = c(0,35)) +
theme_classic() + theme(text = element_text(family = 'Times New Roman', size = 18), legend.position = c(0.90, 0.2)) +
#geom_line(aes(as.POSIXct(probes$do.time.1m), probes$do.1m), linetype = 'dashed') +
geom_line(aes(as.POSIXct(probes$do.time.1m), probes$rolls1m, colour = ' 1m', linetype = ' 1m')) + #, size = 0.7, color = 'gray', linetype = 'longdash') +
geom_line(aes(as.POSIXct(probes$do.time.4m), probes$rolls4m, colour = ' 4m', linetype = ' 4m')) + #, size = 0.7, color = 'gray', linetype = 'solid') +
geom_line(aes(as.POSIXct(probes$do.time.8m), probes$rolls8m, colour = ' 8m', linetype = ' 8m')) + #, size = 0.7, color = 'black', linetype = 'longdash') +
geom_line(aes(as.POSIXct(probes$do.time.12m), probes$rolls12m, colour = '12m', linetype = '12m')) + #, size = 0.7, color = 'black', linetype = 'solid') +
scale_colour_manual(name = '', values = c(' 1m' = 'gray', ' 4m' = 'gray', ' 8m' = 'black', '12m' = 'black')) +
scale_linetype_manual(name = '', values = c(' 1m' = 'longdash', ' 4m' = 'solid', ' 8m' = 'longdash', '12m' = 'solid')) +
annotation_custom(grobTree(textGrob('(b)', x = 0.05, y = 0.95, gp = gpar(fontsize = 18, fontfamily = 'Times New Roman'))))
# 1c. wild vs. farmed DO
ggplot(probes) +
scale_x_datetime('Date', limits = as.POSIXct(range(probes$do.time.1m))) +
scale_y_continuous('Dissolved oxygen (mg/L)', limits = c(0,15)) +
theme_classic() + theme(text = element_text(family = 'Times New Roman', size = 18), legend.position = c(0.90, 0.2)) +
#geom_line(aes(as.POSIXct(probes$do.time.1m), probes$do.1m), linetype = 'dashed') +
geom_line(aes(as.POSIXct(probes$do.time.1m), probes$rolldo1m, colour = ' 1m', linetype = ' 1m')) + #, size = 0.7, color = 'gray', linetype = 'longdash') +
geom_line(aes(as.POSIXct(probes$do.time.4m), probes$rolldo4m, colour = ' 4m', linetype = ' 4m')) + #, size = 0.7, color = 'gray', linetype = 'solid') +
geom_line(aes(as.POSIXct(probes$do.time.8m), probes$rolldo8m, colour = ' 8m', linetype = ' 8m')) + #, size = 0.7, color = 'black', linetype = 'longdash') +
geom_line(aes(as.POSIXct(probes$do.time.12m), probes$rolldo12m, colour = '12m', linetype = '12m')) + #, size = 0.7, color = 'black', linetype = 'solid') +
scale_colour_manual(name = '', values = c(' 1m' = 'gray', ' 4m' = 'gray', ' 8m' = 'black', '12m' = 'black')) +
scale_linetype_manual(name = '', values = c(' 1m' = 'longdash', ' 4m' = 'solid', ' 8m' = 'longdash', '12m' = 'solid')) +
annotation_custom(grobTree(textGrob('(c)', x = 0.05, y = 0.95, gp = gpar(fontsize = 18, fontfamily = 'Times New Roman'))))
# load wrasse acclimation data
masterfileloc = "H:/Data processing/AcousticTagFile_2016.xlsx" # 2015 wild vs. farmed wrasse
load.DO('probe.DOT1', colnums = c(1, 2, 3))
load.DO('probe.DOT2', colnums = c(6, 7, 8))
load.DO('probe.DOT4', colnums = c(11, 12, 13))
load.DO('probe.DOT12', colnums = c(16, 17, 18))
load.sal('probe.sal1', colnums = c(4, 5))
load.sal('probe.sal2', colnums = c(9, 10))
load.sal('probe.sal4', colnums = c(14, 15))
load.sal('probe.sal12', colnums = c(19, 20))
# combine all data into one data frame
#probes <- cbind(probe.DOT1, probe.sal1, probe.DOT2, probe.sal2, probe.DOT4, probe.sal4, probe.DOT12, probe.sal12)
#colnames(probes) <- c('do.time.1m', 'do.1m', 'temp.1m', 'sal.time.1m', 'sal.1m', 'do.time.2m', 'do.2m', 'temp.2m', 'sal.time.2m', 'sal.2m', 'do.time.4m', 'do.4m', 'temp.4m', 'sal.time.4m', 'sal.4m','do.time.12m', 'do.12m', 'temp.12m', 'sal.time.12m', 'sal.12m')
# calculate rolling 6h-means for data
probe.DOT1$rolldo <- c(rep(NA,11), rollapply(probe.DOT1$DO, width = 12, FUN = mean, na.rm = T, align = 'right'))
probe.DOT2$rolldo <- c(rep(NA,11), rollapply(probe.DOT2$DO, width = 12, FUN = mean, na.rm = T, align = 'right'))
probe.DOT4$rolldo <- c(rep(NA,11), rollapply(probe.DOT4$DO, width = 12, FUN = mean, na.rm = T, align = 'right'))
probe.DOT12$rolldo <- c(rep(NA,11), rollapply(probe.DOT12$DO, width = 12, FUN = mean, na.rm = T, align = 'right'))
probe.DOT1$rollt <- c(rep(NA,11), rollapply(probe.DOT1$Temp, width = 12, FUN = mean, na.rm = T, align = 'right'))
probe.DOT2$rollt <- c(rep(NA,11), rollapply(probe.DOT2$Temp, width = 12, FUN = mean, na.rm = T, align = 'right'))
probe.DOT4$rollt <- c(rep(NA,11), rollapply(probe.DOT4$Temp, width = 12, FUN = mean, na.rm = T, align = 'right'))
probe.DOT12$rollt <- c(rep(NA,11), rollapply(probe.DOT12$Temp, width = 12, FUN = mean, na.rm = T, align = 'right'))
probe.sal1$rolls <- c(rep(NA,11), rollapply(probe.sal1$Sal, width = 12, FUN = mean, na.rm = T, align = 'right'))
probe.sal2$rolls <- c(rep(NA,11), rollapply(probe.sal2$Sal, width = 12, FUN = mean, na.rm = T, align = 'right'))
probe.sal4$rolls <- c(rep(NA,11), rollapply(probe.sal4$Sal, width = 12, FUN = mean, na.rm = T, align = 'right'))
probe.sal12$rolls <- c(rep(NA,11), rollapply(probe.sal12$Sal, width = 12, FUN = mean, na.rm = T, align = 'right'))
# subset for study start and end dates
trial1 <- c('2016-06-18 19:00:00', '2016-07-16 00:00:00')
trial2 <- c('2016-09-14 00:00:00', '2016-10-14 00:00:00')
#trial 1 subset
probe.DOT1 <- subset(probe.DOT1, Time > trial1[[1]] & Time < trial1[[2]])
probe.DOT2 <- subset(probe.DOT2, Time > trial1[[1]] & Time < trial1[[2]])
probe.DOT4 <- subset(probe.DOT4, Time > trial1[[1]] & Time < trial1[[2]])
probe.DOT12 <- subset(probe.DOT12, Time > trial1[[1]] & Time < trial1[[2]])
probe.sal1 <- subset(probe.sal1, Time > trial1[[1]] & Time < trial1[[2]])
probe.sal2 <- subset(probe.sal2, Time > trial1[[1]] & Time < trial1[[2]])
probe.sal4 <- subset(probe.sal4, Time > trial1[[1]] & Time < trial1[[2]])
probe.sal12 <- subset(probe.sal12, Time > trial1[[1]] & Time < trial1[[2]])
#trial 2 subset
probe.DOT1 <- subset(probe.DOT1, Time > trial2[[1]] & Time < trial2[[2]])
probe.DOT2 <- subset(probe.DOT2, Time > trial2[[1]] & Time < trial2[[2]])
probe.DOT4 <- subset(probe.DOT4, Time > trial2[[1]] & Time < trial2[[2]])
probe.DOT12 <- subset(probe.DOT12, Time > trial2[[1]] & Time < trial2[[2]])
probe.sal1 <- subset(probe.sal1, Time > trial2[[1]] & Time < trial2[[2]])
probe.sal2 <- subset(probe.sal2, Time > trial2[[1]] & Time < trial2[[2]])
probe.sal4 <- subset(probe.sal4, Time > trial2[[1]] & Time < trial2[[2]])
probe.sal12 <- subset(probe.sal12, Time > trial2[[1]] & Time < trial2[[2]])
# 2a. acclimated vs. non-acclimated temperature
ggplot() +
scale_x_datetime('Date', limits = as.POSIXct(range(probe.DOT1$Time))) +
scale_y_continuous(expression(paste('Temperature (', ~degree,'C)', sep='')), limits = c(8,15)) +
theme_classic() + theme(text = element_text(family = 'Times New Roman', size = 18), legend.position = c(0.90, 0.2)) +
#geom_line(aes(as.POSIXct(probes$do.time.1m), probes$do.1m), linetype = 'dashed') +
geom_line(aes(as.POSIXct(probe.DOT1$Time), probe.DOT1$rollt, colour = ' 1m', linetype = ' 1m')) + #, size = 0.7, color = 'gray', linetype = 'longdash') +
geom_line(aes(as.POSIXct(probe.DOT2$Time), probe.DOT2$rollt, colour = ' 2m', linetype = ' 2m')) + #, size = 0.7, color = 'gray', linetype = 'solid') +
geom_line(aes(as.POSIXct(probe.DOT4$Time), probe.DOT4$rollt, colour = ' 4m', linetype = ' 4m')) + #, size = 0.7, color = 'black', linetype = 'longdash') +
geom_line(aes(as.POSIXct(probe.DOT12$Time), probe.DOT12$rollt, colour = '12m', linetype = '12m')) + #, size = 0.7, color = 'black', linetype = 'solid') +
scale_colour_manual(name = '', values = c(' 1m' = 'gray', ' 2m' = 'gray', ' 4m' = 'black', '12m' = 'black')) +
scale_linetype_manual(name = '', values = c(' 1m' = 'longdash', ' 2m' = 'solid', ' 4m' = 'longdash', '12m' = 'solid')) +
annotation_custom(grobTree(textGrob('(a)', x = 0.05, y = 0.95, gp = gpar(fontsize = 18, fontfamily = 'Times New Roman'))))
# 2b. acclimated vs. non-acclimated salinity
ggplot() +
scale_x_datetime('Date', limits = as.POSIXct(range(probe.sal1$Time))) +
scale_y_continuous('Salinity (PSU)', limits = c(0,38)) +
theme_classic() + theme(text = element_text(family = 'Times New Roman', size = 18), legend.position = c(0.90, 0.2)) +
#geom_line(aes(as.POSIXct(probes$do.time.1m), probes$do.1m), linetype = 'dashed') +
geom_line(aes(as.POSIXct(probe.sal1$Time), probe.sal1$rolls, colour = ' 1m', linetype = ' 1m')) + #, size = 0.7, color = 'gray', linetype = 'longdash') +
geom_line(aes(as.POSIXct(probe.sal2$Time), probe.sal2$rolls, colour = ' 2m', linetype = ' 2m')) + #, size = 0.7, color = 'gray', linetype = 'solid') +
geom_line(aes(as.POSIXct(probe.sal4$Time), probe.sal4$rolls, colour = ' 4m', linetype = ' 4m')) + #, size = 0.7, color = 'black', linetype = 'longdash') +
geom_line(aes(as.POSIXct(probe.sal12$Time), probe.sal12$rolls, colour = '12m', linetype = '12m')) + #, size = 0.7, color = 'black', linetype = 'solid') +
scale_colour_manual(name = '', values = c(' 1m' = 'gray', ' 2m' = 'gray', ' 4m' = 'black', '12m' = 'black')) +
scale_linetype_manual(name = '', values = c(' 1m' = 'longdash', ' 2m' = 'solid', ' 4m' = 'longdash', '12m' = 'solid')) +
annotation_custom(grobTree(textGrob('(b)', x = 0.05, y = 0.95, gp = gpar(fontsize = 18, fontfamily = 'Times New Roman'))))
# 2c. acclimated vs. non-acclimated DO
ggplot() +
scale_x_datetime('Date', limits = as.POSIXct(range(probe.DOT1$Time))) +
scale_y_continuous('Dissolved oxygen (mg/L)', limits = c(0,15)) +
theme_classic() + theme(text = element_text(family = 'Times New Roman', size = 18), legend.position = c(0.90, 0.2)) +
#geom_line(aes(as.POSIXct(probes$do.time.1m), probes$do.1m), linetype = 'dashed') +
geom_line(aes(as.POSIXct(probe.DOT1$Time), probe.DOT1$rolldo, colour = ' 1m', linetype = ' 1m')) + #, size = 0.7, color = 'gray', linetype = 'longdash') +
geom_line(aes(as.POSIXct(probe.DOT2$Time), probe.DOT2$rolldo, colour = ' 2m', linetype = ' 2m')) + #, size = 0.7, color = 'gray', linetype = 'solid') +
geom_line(aes(as.POSIXct(probe.DOT4$Time), probe.DOT4$rolldo, colour = ' 4m', linetype = ' 4m')) + #, size = 0.7, color = 'black', linetype = 'longdash') +
geom_line(aes(as.POSIXct(probe.DOT12$Time), probe.DOT12$rolldo, colour = '12m', linetype = '12m')) + #, size = 0.7, color = 'black', linetype = 'solid') +
scale_colour_manual(name = '', values = c(' 1m' = 'gray', ' 2m' = 'gray', ' 4m' = 'black', '12m' = 'black')) +
scale_linetype_manual(name = '', values = c(' 1m' = 'longdash', ' 2m' = 'solid', ' 4m' = 'longdash', '12m' = 'solid')) +
annotation_custom(grobTree(textGrob('(c)', x = 0.05, y = 0.95, gp = gpar(fontsize = 18, fontfamily = 'Times New Roman'))))
# 3. Pen layout and segmentation plot---------------------------
#LOAD LOCATIONS CODING DATA
locations.lookup <- read.xlsx(masterfileloc, sheet = 12, startRow = 1, cols = seq(1,7)) # read in codes from Locations Coding spreadsheet
rownames(locations.lookup) <- locations.lookup$Code
pen.col <- 'black'
pen.size <- 1.5
#create hide and hydrophone location table
pen.sym <- c(x = locations.lookup['7WHNW', 'xmin']+2, y = locations.lookup['7WHNW', 'ymin']+2)
pen.sym <- rbind(pen.sym, c(x = locations.lookup['7WHSE', 'xmin']+2, y = locations.lookup['7WHSE', 'ymin']+2))
pen.sym <- rbind(pen.sym, c(x = locations.lookup['8WHSW', 'xmin']+2, y = locations.lookup['8WHSW', 'ymin']+2))
pen.sym <- rbind(pen.sym, c(x = locations.lookup['8WHNE', 'xmin']+2, y = locations.lookup['8WHNE', 'ymin']+2))
pen.sym <- rbind(pen.sym, c(x = locations.lookup['7FBSE', 'xmin']+1.5, y = locations.lookup['7FBSE', 'ymin']+1.5))
pen.sym <- rbind(pen.sym, c(x = locations.lookup['7FBNW', 'xmin']+1.5, y = locations.lookup['7FBNW', 'ymin']+1.5))
pen.sym <- rbind(pen.sym, c(x = locations.lookup['8FBSW', 'xmin']+1.5, y = locations.lookup['8FBSW', 'ymin']+1.5))
pen.sym <- rbind(pen.sym, c(x = locations.lookup['8FBNE', 'xmin']+1.5, y = locations.lookup['8FBNE', 'ymin']+1.5))
rownames(pen.sym) <- c('7WHNW', '7WHSE', '8WHSW', '8WHNE', '7FBSE', '7FBNW', '8FBSW', '8FBNE')
pen.sym <- as.data.frame(pen.sym)
pen.sym <- rbind(pen.sym, c(40, 15.7), c(66, 40), c(14.3, 14.3), c(40, 40), c(66, 14.3), c(40, 14.23), c(14.3, 40), c(40, 38.6))
pen.sym$type <- as.factor(c(rep('hide', 4), rep('feed block', 4), rep('deep hydrophone', 4), rep('shallow hydrophone', 4)))
pen.sym$type <- factor(pen.sym$type, levels = c('deep hydrophone', 'shallow hydrophone', 'hide', 'feed block'))
rownames(pen.sym) <- c('7WHNW', '7WHSE', '8WHSW', '8WHNE', '7FBSE', '7FBNW', '8FBSW', '8FBNE', 'd1', 'd2', 'd3', 'd4', 's1', 's2', 's3', 's4')
pen.sym <- as.data.frame(pen.sym)
blank <- c(rep(' ', 9)) # blank sequence for no labels on axis tick marks
ggplot() +
geom_point(aes(x = 15, y = 15), colour = 'white') + #scale_fill_gradientn(colours=plot.col, space = 'Lab', limits = c(0, pingmax), na.value = plot.col[length(plot.col)], name = 'No. pings') +
theme_classic() + theme(text = element_text(family = 'Times New Roman', size = 20), legend.position = c(0.15, 0.9), axis.title.x = element_text(size = 18, face = 'bold'), axis.title.y = element_text(size = 18, face = 'bold')) +
scale_x_continuous('x-axis (m)', limits = c(10,70), breaks = seq(10, 70, 1), labels = c('10', blank, '20', blank, '30', blank, '40', blank, '50', blank, '60', blank, '70')) +
scale_y_continuous('y-axis (m)', limits = c(10,50), breaks = seq(10, 50, 1), labels = c('10', blank, '20', blank, '30', blank, '40', blank, '50')) +
annotate('rect', xmin = locations.lookup['8CSW', 'xmin'], xmax = locations.lookup['8CSE', 'xmax'], ymin = locations.lookup['8CSW', 'ymin'], ymax = locations.lookup['8CNE', 'ymax'], size = pen.size, colour = pen.col, alpha = 0) +
annotate('rect', xmin = locations.lookup['7CSW', 'xmin'], xmax = locations.lookup['7CSE', 'xmax'], ymin = locations.lookup['7CSW', 'ymin'], ymax = locations.lookup['7CNE', 'ymax'], size = pen.size, colour = pen.col, alpha = 0) +
geom_point(data = pen.sym, mapping = aes(x = x, y = y, size = type, colour = type, fill = type, shape = type, stroke = 1)) +
annotate('text', x = 27.5, y = 27.5, label = 'Pen 7', family = 'Times New Roman', size = 6) +
annotate('text', x = 53.5, y = 27.5, label = 'Pen 8', family = 'Times New Roman', size = 6) +
scale_size_manual(name = '', values = c('hide' = 15, 'feed block' = 5, 'deep hydrophone' = 5, 'shallow hydrophone' = 5)) +
scale_shape_manual(name = '', values = c('hide' = 21, 'feed block' = 13, 'deep hydrophone' = 22, 'shallow hydrophone' = 24)) +
scale_colour_manual(name = '', values = c('hide' = 'black', 'feed block' = 'black', 'deep hydrophone' = 'black', 'shallow hydrophone' = 'black')) +
scale_fill_manual(name = '', values = c('hide' = 'grey70', 'feed block' = 'grey70', 'deep hydrophone' = 'grey35', 'shallow hydrophone' = 'grey35')) +
guides(size = guide_legend(override.aes = list(size = 5))) +
annotation_custom(grobTree(linesGrob(x = c(0.305, 0.325), y = c(0.81, 0.9), arrow = arrow(length = unit(5, 'mm')), gp = gpar(lwd = 2.5)))) +
annotation_custom(grobTree(textGrob('N', x = 0.330, y = 0.93, gp = gpar(fontsize = 18, fontfamily = 'Times New Roman'))))
# 4. code to draw top view of pen 7 with colour-coded locations---------------------------
par(mfrow=c(1,1))
plot(50, 50, xlab = 'X (m)', ylab = 'Z (m)', pch = 20, cex = 1, xlim = c(10, 45), ylim = c(10, 45), type = 'l', col = '#26b426') # tight plot
polygon(c(15, 21, 21, 15), c(15, 15, 21, 21), lty = 1, lwd = 2, col = rgb(248, 203, 173, maxColorValue = 255)) # SW corner
polygon(c(15, 21, 21, 15), c(33, 33, 39, 39), lty = 1, lwd = 2, col = rgb(255, 153, 153, maxColorValue = 255)) # NW corner
polygon(c(33, 39, 39, 33), c(15, 15, 21, 21), lty = 1, lwd = 2, col = rgb(255, 153, 153, maxColorValue = 255)) # SE corner
polygon(c(33, 39, 39, 33), c(33, 33, 39, 39), lty = 1, lwd = 2, col = rgb(248, 203, 173, maxColorValue = 255)) # NE corner
polygon(c(21, 33, 33, 21), c(15, 15, 21, 21), lty = 1, lwd = 2, col = rgb(118, 113, 113, maxColorValue = 255)) # S edge
polygon(c(33, 39, 39, 33), c(21, 21, 33, 33), lty = 1, lwd = 2, col = rgb(118, 113, 113, maxColorValue = 255)) # E edge
polygon(c(21, 33, 33, 21), c(33, 33, 39, 39), lty = 1, lwd = 2, col = rgb(118, 113, 113, maxColorValue = 255)) # N edge
polygon(c(15, 21, 21, 15), c(21, 21, 33, 33), lty = 1, lwd = 2, col = rgb(118, 113, 113, maxColorValue = 255)) # W edge
polygon(c(21, 33, 33, 21), c(21, 21, 33, 33), lty = 1, lwd = 2, col = rgb(192, 0, 0, maxColorValue = 255)) # centre
polygon(c(33.35, 37.35, 37.35, 33.35), c(15.13, 15.13, 19.13, 19.13), lty = 1, lwd = 2, col = rgb(146, 208, 80, maxColorValue = 255)) # SE hide
polygon(c(15.49, 19.49, 19.49, 15.49), c(35.10, 35.10, 39.10, 39.10), lty = 1, lwd = 2, col = rgb(146, 208, 80, maxColorValue = 255)) # NW hide
polygon(c(36, 39, 39, 36), c(13.5, 13.5, 16.5, 16.5), lty = 1, lwd = 2, col = rgb(0, 176, 240, maxColorValue = 255)) # SE feed block
polygon(c(13.5, 16.5, 16.5, 13.5), c(36, 36, 39, 39), lty = 1, lwd = 2, col = rgb(0, 176, 240, maxColorValue = 255)) # NW feed block
# 5. code to draw side view of pen 7 with colour-coded locations
par(mfrow=c(1,1))
plot(50, 50, xlab = 'X (m)', ylab = 'Z (m)', pch = 20, cex = 1, xlim = c(10, 43), ylim = c(25, -5), type = 'l', col = '#26b426') # tight plot
polygon(c(15, 21, 21, 15), c(15, 15, 0, 0), lty = 1, lwd = 2, col = rgb(248, 203, 173, maxColorValue = 255)) # left edge
polygon(c(21, 33, 33, 21), c(15, 15, 0, 0), lty = 1, lwd = 2, col = rgb(118, 113, 113, maxColorValue = 255)) # edge
polygon(c(33, 39, 39, 33), c(15, 15, 0, 0), lty = 1, lwd = 2, col = rgb(255, 153, 153, maxColorValue = 255)) # right edge
polygon(c(15, 27, 39), c(15, 20, 15), lwd = 2, col = rgb(208, 206, 206, maxColorValue = 255)) # bottom cone
polygon(c(33.35, 37.35, 37.35, 33.35), c(12, 12, 8, 8), lwd = 2, col = rgb(146, 208, 80, maxColorValue = 255)) # hide SE
#polygon(c(15.49, 19.49, 19.49, 15.49), c(9.98, 9.98, 13.9, 13.9), lty = 1, lwd = 2, col = rgb(146, 208, 80, maxColorValue = 255)) # NW hide
polygon(c(36, 39, 39, 36), c(4.5, 4.5, 7.5, 7.5), lty = 1, lwd = 2, col = rgb(0, 176, 240, maxColorValue = 255)) # SE feed block
#polygon(c(13.5, 16.5, 16.5, 13.5), c(4.5, 4.5, 7.5, 7.5), lty = 1, lwd = 2, col = rgb(0, 176, 240, maxColorValue = 255)) # NW feed block
# 6. Locations for wild vs. farmed and acclimated vs. non-acclimated B-----------------------------------
# load wild vs. farmed locations data, reorganise and recalculate as proportions
setwd('H:/Data processing/2015 Wild vs. Farmed/Cropped data/Coded Day CSV/Outputs')
wflocs <- read.csv('LocationsOutput.csv')
wflocs <- as.data.frame(wflocs)
wflocs$X <- as.character(wflocs$X)
wflocs[1,1] <- 'P7_lt15m'
wflocs[2,1] <- 'P7_gt15m'
wflocs[10,1] <- 'P8_lt15m'
wflocs[11,1] <- 'P8_gt15m'
rownames(wflocs) <- wflocs$X
wflocs$X <- NULL
colnames(wflocs) <- seq(1, 37)
wflocs <- wflocs[,1:37]
wflocs <- as.data.frame(t(wflocs))
wflocs$P7_totedge <- wflocs$P7_outer + wflocs$P7_edge
wflocs$P8_totedge <- wflocs$P8_outer + wflocs$P8_edge
wflocs$P7_hidecor_nohid <- wflocs$P7_hidecorner - wflocs$P7_hides - wflocs$P7_feedblock
wflocs$P8_hidecor_nohid <- wflocs$P8_hidecorner - wflocs$P8_hides - wflocs$P8_feedblock
#wflocs <- wflocs[c(1, 19, seq(6, 9), 21, 10, 20, seq(15, 18), 22)]
wflocs <- wflocs[c(1, 9, 8, 7, 21, 6, 19, 10, 18, 17, 16, 22, 15, 20)]
wflocs[wflocs <0] <- 0
wflocs$P7_tot <- wflocs[,1] + wflocs[,2] + wflocs[,3] + wflocs[,4] + wflocs[,5] + wflocs[,6] + wflocs[,7]
wflocs$P8_tot <- wflocs[,8] + wflocs[,9] + wflocs[,10] + wflocs[,11] + wflocs[,12] + wflocs[,13] + wflocs[,14]
wflocs$P7_lt15m <- (wflocs$P7_lt15m / wflocs$P7_tot)*100
wflocs$P7_totedge <- (wflocs$P7_totedge / wflocs$P7_tot)*100
wflocs$P7_emptycorner <- (wflocs$P7_emptycorner / wflocs$P7_tot)*100
wflocs$P7_centre <- (wflocs$P7_centre / wflocs$P7_tot)*100
wflocs$P7_hides <- (wflocs$P7_hides / wflocs$P7_tot)*100
wflocs$P7_feedblock <- (wflocs$P7_feedblock / wflocs$P7_tot)*100
wflocs$P7_hidecor_nohid <- (wflocs$P7_hidecor_nohid / wflocs$P7_tot)*100
wflocs$P8_lt15m <- (wflocs$P8_lt15m / wflocs$P8_tot)*100
wflocs$P8_totedge <- (wflocs$P8_totedge / wflocs$P8_tot)*100
wflocs$P8_emptycorner <- (wflocs$P8_emptycorner / wflocs$P8_tot)*100
wflocs$P8_centre <- (wflocs$P8_centre / wflocs$P8_tot)*100
wflocs$P8_hides <- (wflocs$P8_hides / wflocs$P8_tot)*100
wflocs$P8_feedblock <- (wflocs$P8_feedblock / wflocs$P8_tot)*100
wflocs$P8_hidecor_nohid <- (wflocs$P8_hidecor_nohid / wflocs$P8_tot)*100
wlocs <- wflocs[c(1:7)]
flocs <- wflocs[c(8:14)]
wlocs <- melt(wlocs, variable.name = 'locs', value.name = 'props')
wlocs$day <- c(seq(1, 14), seq(19, 26), seq(29, 43))
flocs <- melt(flocs, variable.name = 'locs', value.name = 'props')
flocs$day <- c(seq(1, 14), seq(19, 26), seq(29, 43))
# load acclimated vs. non-acclimated locations data, reorganise and recalculate as proportions
setwd('H:/Data processing/2016 Conditioning study B/Filtered Data/Recoded Day CSV/Outputs')
aclocs <- read.csv('LocationsOutput.csv')
aclocs <- as.data.frame(aclocs)
aclocs$X <- as.character(aclocs$X)
aclocs[1,1] <- 'P7_lt15m'
aclocs[2,1] <- 'P7_gt15m'
aclocs[10,1] <- 'P8_lt15m'
aclocs[11,1] <- 'P8_gt15m'
rownames(aclocs) <- aclocs$X
aclocs$X <- NULL
colnames(aclocs) <- seq(1, 30)
#wflocs <- wflocs[,1:37]
aclocs <- as.data.frame(t(aclocs))
aclocs$P7_totedge <- aclocs$P7_outer + aclocs$P7_edge
aclocs$P8_totedge <- aclocs$P8_outer + aclocs$P8_edge
aclocs$P7_hidecor_nohid <- aclocs$P7_hidecorner - aclocs$P7_hides - aclocs$P7_feedblock
aclocs$P8_hidecor_nohid <- aclocs$P8_hidecorner - aclocs$P8_hides - aclocs$P8_feedblock
#wflocs <- wflocs[c(1, 19, seq(6, 9), 21, 10, 20, seq(15, 18), 22)]
aclocs <- aclocs[c(1, 9, 8, 7, 21, 6, 19, 10, 18, 17, 16, 22, 15, 20)]
aclocs[aclocs <0] <- 0
aclocs$P7_tot <- aclocs[,1] + aclocs[,2] + aclocs[,3] + aclocs[,4] + aclocs[,5] + aclocs[,6] + aclocs[,7]
aclocs$P8_tot <- aclocs[,8] + aclocs[,9] + aclocs[,10] + aclocs[,11] + aclocs[,12] + aclocs[,13] + aclocs[,14]
aclocs$P7_lt15m <- (aclocs$P7_lt15m / aclocs$P7_tot)*100
aclocs$P7_totedge <- (aclocs$P7_totedge / aclocs$P7_tot)*100
aclocs$P7_emptycorner <- (aclocs$P7_emptycorner / aclocs$P7_tot)*100
aclocs$P7_centre <- (aclocs$P7_centre / aclocs$P7_tot)*100
aclocs$P7_hides <- (aclocs$P7_hides / aclocs$P7_tot)*100
aclocs$P7_feedblock <- (aclocs$P7_feedblock / aclocs$P7_tot)*100
aclocs$P7_hidecor_nohid <- (aclocs$P7_hidecor_nohid / aclocs$P7_tot)*100
aclocs$P8_lt15m <- (aclocs$P8_lt15m / aclocs$P8_tot)*100
aclocs$P8_totedge <- (aclocs$P8_totedge / aclocs$P8_tot)*100
aclocs$P8_emptycorner <- (aclocs$P8_emptycorner / aclocs$P8_tot)*100
aclocs$P8_centre <- (aclocs$P8_centre / aclocs$P8_tot)*100
aclocs$P8_hides <- (aclocs$P8_hides / aclocs$P8_tot)*100
aclocs$P8_feedblock <- (aclocs$P8_feedblock / aclocs$P8_tot)*100
aclocs$P8_hidecor_nohid <- (aclocs$P8_hidecor_nohid / aclocs$P8_tot)*100
nalocs <- aclocs[c(8:14)]
aclocs <- aclocs[c(1:7)]
aclocs <- melt(aclocs, variable.name = 'locs', value.name = 'props')
aclocs$day <- c(seq(1, 30))
nalocs <- melt(nalocs, variable.name = 'locs', value.name = 'props')
nalocs$day <- c(seq(1, 30))
# draw stacked bar plots of wild vs. farmed
plotfont <- 'Arial'
wplot <- ggplot(wlocs, aes(x = day, y = props, fill = locs))
wplot <- wplot + theme_classic() + theme(text = element_text(family = plotfont, size = 14), legend.position = 'none', plot.margin = margin(10, 5, 10, 1, 'pt'))
wplot <- wplot + geom_bar(stat = 'identity') +
scale_fill_manual(guide = guide_legend(title = NULL, label.theme = element_text(size = 14, angle = 0, family = plotfont)), labels = c('below 15m', 'feed block', 'hides', 'centre', 'hide corners', 'empty corners', 'edge'), values = c('P7_lt15m' = 'gray90', 'P7_feedblock' = 'gray35', 'P7_hides' = 'gray50', 'P7_centre' = 'gray0', 'P7_hidecor_nohid' = 'gray70', 'P7_emptycorner' = 'gray80', 'P7_totedge' = 'gray20'))
wplot <- wplot + scale_y_continuous(name = 'Time (%)', expand = c(0,0), breaks = seq(0, 100, 10)) + scale_x_discrete(name = 'Exp. day', expand = c(0,0), limits = seq(0, 43, 1), labels = c('5', '10', '15', '20', '25', '30', '35', '40'), breaks = seq(5, 40, 5))
wplot <- wplot + theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14))
wplot
fplot <- ggplot(flocs, aes(x = day, y = props, fill = locs))
fplot <- fplot + theme_classic() + theme(text = element_text(family = plotfont, size = 14), legend.position = 'none', plot.margin = margin(10, 5, 10, 1, 'pt'))
fplot <- fplot + geom_bar(stat = 'identity') +
scale_fill_manual(guide = guide_legend(title = NULL, label.theme = element_text(size = 14, angle = 0, family = plotfont)), labels = c('below 15m', 'feed block', 'hides', 'centre', 'hide corners', 'empty corners', 'edge'), values = c('P8_lt15m' = 'gray90', 'P8_feedblock' = 'gray35', 'P8_hides' = 'gray50', 'P8_centre' = 'gray0', 'P8_hidecor_nohid' = 'gray70', 'P8_emptycorner' = 'gray80', 'P8_totedge' = 'gray20'))
fplot <- fplot + scale_y_continuous(name = 'Time (%)', expand = c(0,0), breaks = seq(0, 100, 10)) + scale_x_discrete(name = 'Exp. day', expand = c(0,0), limits = seq(0, 43, 1), labels = c('5', '10', '15', '20', '25', '30', '35', '40'), breaks = seq(5, 40, 5))
fplot <- fplot + theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14))
fplot
# draw stacked bar plots of acclimated vs. non-acclimated
acplot <- ggplot(aclocs, aes(x = day, y = props, fill = locs))
acplot <- acplot + theme_classic() + theme(text = element_text(family = plotfont, size = 14), plot.margin = margin(10, 1, 10, 10, 'pt'))
acplot <- acplot + geom_bar(stat = 'identity') +
scale_fill_manual(guide = guide_legend(title = NULL, label.theme = element_text(size = 14, angle = 0, family = plotfont)), labels = c('below 15m', 'feed block', 'hides', 'centre', 'hide corners', 'empty corners', 'edge'), values = c('P7_lt15m' = 'gray90', 'P7_feedblock' = 'gray35', 'P7_hides' = 'gray50', 'P7_centre' = 'gray0', 'P7_hidecor_nohid' = 'gray70', 'P7_emptycorner' = 'gray80', 'P7_totedge' = 'gray20'))
acplot <- acplot + scale_y_continuous(name = 'Time (%)', expand = c(0,0), breaks = seq(0, 100, 10)) + scale_x_discrete(name = 'Exp. day', expand = c(0,0), limits = seq(0, 30, 1), labels = c('5', '10', '15', '20', '25', '30'), breaks = seq(5, 30, 5))
acplot <- acplot + theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14))
acplot
naplot <- ggplot(nalocs, aes(x = day, y = props, fill = locs))
naplot <- naplot + theme_classic() + theme(text = element_text(family = plotfont, size = 14), legend.position = 'none', plot.margin = margin(10, 132, 10, 10, 'pt'))
naplot <- naplot + geom_bar(stat = 'identity') +
scale_fill_manual(guide = guide_legend(title = NULL, label.theme = element_text(size = 14, angle = 0, family = plotfont)), labels = c('below 15m', 'feed block', 'hides', 'centre', 'hide corners', 'empty corners', 'edge'), values = c('P8_lt15m' = 'gray90', 'P8_feedblock' = 'gray35', 'P8_hides' = 'gray50', 'P8_centre' = 'gray0', 'P8_hidecor_nohid' = 'gray70', 'P8_emptycorner' = 'gray80', 'P8_totedge' = 'gray20'))
naplot <- naplot + scale_y_continuous(name = 'Time (%)', expand = c(0,0), breaks = seq(0, 100, 10)) + scale_x_discrete(name = 'Exp. day', expand = c(0,0), limits = seq(0, 30, 1), labels = c('5', '10', '15', '20', '25', '30'), breaks = seq(5, 30, 5))
naplot <- naplot + theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14))
naplot
plot_grid(wplot, acplot, fplot, naplot, labels = c('(a)', '(c)', '(b)', '(d)'), rel_widths = c(1,1), hjust = c(-0.0, -0.5, -0.0, -0.5))
# 7. Hourly pen coverage night vs. day for wild vs. farmed and acclimated vs. non-acclimated----------------------
# load wild vs. farmed hourly coverage data
wildn <- 16
farmedn <- 10
accn <- 10
naccn <- 14
setwd('H:/Data processing/2015 Wild vs. Farmed/Cropped data/Coded Fish CSV/Outputs')
covday <- read.csv('CoverageOutput_hmeanperfish_day.csv')
covday <- as.data.frame(covday)
covday <- covday[,-c(1, 2, 4,5)]
#covday$ID <- as.character(covday$ID)
#rownames(covday) <- covday$ID
#covday$ID <- NULL
#covday <- covday[,c(2, seq(3, 76, 2))]
#colnames(covday) <- c('pen', seq(1, 37))
#covday <- do.call(data.frame, aggregate(.~pen, data = covday, FUN = function(x) c(mn = mean(x), sd = sd(x))))
covday <- do.call(data.frame, aggregate(.~pen, data = covday, FUN = function(x) c(mn = mean(x))))
covday <- cbind(as.data.frame(t(covday[,seq(2, 75, 2)])), as.data.frame(t(covday[,seq(3, 75, 2)])))
colnames(covday) <- c('wild_cov_day', 'farmed_cov_day', 'wild_day_sd', 'farmed_day_sd')
covday$day <- c(seq(1, 14), seq(19, 26), seq(29, 43))
rownames(covday) <- seq(1, 37, 1)
covnight <- read.csv('CoverageOutput_hmeanperfish_night.csv')
covnight <- as.data.frame(covnight)
covnight[,c(1, 2, 4,5)] <- NULL
#covnight$ID <- as.character(covnight$ID)
#rownames(covnight) <- covnight$ID
#covnight$ID <- NULL
#covnight <- covnight[,c(2, seq(3, 74, 2))]
#colnames(covnight) <- c('pen', seq(1, 36))
#covnight <- do.call(data.frame, aggregate(.~pen, data = covnight, FUN = function(x) c(mn = mean(x), sd = sd(x))))
covnight <- do.call(data.frame, aggregate(.~pen, data = covnight, FUN = function(x) c(mn = mean(x)), na.action = na.omit))
covnight[,seq(3, 74, 2)] <- NA
covnight <- cbind(as.data.frame(t(covnight[,seq(2, 73, 2)])), as.data.frame(t(covnight[,seq(3, 73, 2)])))
colnames(covnight) <- c('wild_cov_night', 'farmed_cov_night', 'wild_night_sd', 'farmed_night_sd')
covnight <- covnight[-c(14, 22),]
covnight$day <- c(seq(2, 14), seq(20, 26), seq(30, 43))
rownames(covnight) <- seq(1, 34, 1)
coverage <- left_join(covday, covnight, by = 'day')
wcov <- coverage[c(5, 1, 3, 6, 8)]
colnames(wcov) <- c('day', 'day_cov', 'day_sd', 'night_cov', 'night_sd')
fcov <- coverage[c(5, 2, 4, 7, 9)]
colnames(fcov) <- c('day', 'day_cov', 'day_sd', 'night_cov', 'night_sd')
covs <- melt(wcov[,c('day', 'day_cov', 'night_cov')], measure.vars = c('day_cov', 'night_cov'), variable.name = 'time', value.name = 'cov')
csd <- melt(wcov[,c('day', 'day_sd', 'night_sd')], measure.vars = c('day_sd', 'night_sd'), variable.name = 'time', value.name = 'sd')
csd <- csd[,3]
csd <- csd/wildn # divide sd by n of fish
wcov <- cbind(covs, csd)
wcov[,c(3, 4)] <- wcov[,c(3, 4)]*100
#wcov[38:74,4] <- NA
rm(covs, csd)
covs <- melt(fcov[,c('day', 'day_cov', 'night_cov')], measure.vars = c('day_cov', 'night_cov'), variable.name = 'time', value.name = 'cov')
csd <- melt(fcov[,c('day', 'day_sd', 'night_sd')], measure.vars = c('day_sd', 'night_sd'), variable.name = 'time', value.name = 'sd')
csd <- csd[,3]
csd <- csd/farmedn # divide sd by n of fish
fcov <- cbind(covs, csd)
fcov[,c(3, 4)] <- fcov[,c(3, 4)]*100
rm(covs, csd)
# load acclimated vs. non-acclimated hourly coverage data
setwd('H:/Data processing/2016 Conditioning study B/Filtered Data/Recoded Day CSV/Outputs')
covday <- read.csv('CoverageOutput_hmeanperfish_day.csv')
covday <- as.data.frame(covday)
#covday$ID <- as.character(covday$ID)
#rownames(covday) <- covday$ID
#covday$ID <- NULL
#colnames(covday) <- seq(1, 30)
covday[,c(1, 2)] <- NULL
covday <- do.call(data.frame, aggregate(.~pen, data = covday, FUN = function(x) c(mn = mean(x)), na.action = na.omit))
covday <- cbind(as.data.frame(t(covday[,seq(2, 61, 2)])), as.data.frame(t(covday[,seq(3, 61, 2)])))
#covday <- as.data.frame(t(covday))
colnames(covday) <- c('acc_cov_day', 'naacc_cov_day', 'acc_day_sd', 'nacc_day_sd')
covday$day <- seq(1, 30)
rownames(covday) <- seq(1, 30, 1)
covnight <- read.csv('CoverageOutput_hmeanperfish_night.csv')
covnight <- as.data.frame(covnight)
#covnight$ID <- as.character(covnight$ID)
#rownames(covnight) <- covnight$ID
#covnight$ID <- NULL
#colnames(covnight) <- seq(1, 30)
covnight[,c(1, 2)] <- NULL
covnight <- do.call(data.frame, aggregate(.~pen, data = covnight, FUN = function(x) c(mn = mean(x)), na.action = na.omit))
covnight <- cbind(as.data.frame(t(covnight[,seq(2, 61, 2)])), as.data.frame(t(covnight[,seq(3, 61, 2)])))
#covnight <- as.data.frame(t(covnight))
colnames(covnight) <- c('acc_cov_night', 'nacc_cov_night', 'acc_night_sd', 'nacc_night_sd')
covnight$day <- seq(1, 30)
covnight <- covnight[-c(1, 18),]
rownames(covnight) <- seq(1, 28, 1)
coverage <- left_join(covday, covnight, by = 'day')
acov <- coverage[c(5, 1, 2, 6, 7)]
colnames(acov) <- c('day', 'day_cov', 'day_sd', 'night_cov', 'night_sd')
nacov <- coverage[c(5, 3, 4, 8, 9)]
colnames(nacov) <- c('day', 'day_cov', 'day_sd', 'night_cov', 'night_sd')
covs <- melt(acov[,c('day', 'day_cov', 'night_cov')], measure.vars = c('day_cov', 'night_cov'), variable.name = 'time', value.name = 'cov')
csd <- melt(acov[,c('day', 'day_sd', 'night_sd')], measure.vars = c('day_sd', 'night_sd'), variable.name = 'time', value.name = 'sd')
csd <- csd[,3]
csd <- csd/accn # divide sd by n of fish
acov <- cbind(covs, csd)
acov[,c(3, 4)] <- acov[,c(3, 4)]*100
#acov[38:74,4] <- NA
rm(covs, csd)
covs <- melt(nacov[,c('day', 'day_cov', 'night_cov')], measure.vars = c('day_cov', 'night_cov'), variable.name = 'time', value.name = 'cov')
csd <- melt(nacov[,c('day', 'day_sd', 'night_sd')], measure.vars = c('day_sd', 'night_sd'), variable.name = 'time', value.name = 'sd')
csd <- csd[,3]
csd <- csd/naccn # divide sd by n of fish
nacov <- cbind(covs, csd)
nacov[,c(3, 4)] <- nacov[,c(3, 4)]*100
rm(covs, csd)
# draw bar plots of wild vs. farmed hourly coverage
plotfont <- 'Arial'
wplot <- ggplot(wcov, aes(x = day, y = cov, fill = time))
wplot <- wplot + theme_classic() + theme(text = element_text(family = plotfont, size = 14), legend.position = 'none', plot.margin = margin(10, 5, 10, 1, 'pt'))
wplot <- wplot + geom_bar(stat = 'identity', position = 'dodge') + geom_errorbar(aes(ymin = cov-csd, ymax = cov+csd), width = 0.4, position = position_dodge(1)) +
scale_fill_manual(guide = guide_legend(title = NULL, label.theme = element_text(size = 14, angle = 0, family = plotfont)), labels = c('Day', 'Night'), values = c('day_cov' = 'gray60', 'night_cov' = 'gray30'))
wplot <- wplot + scale_y_continuous(name = 'Coverage (%)', expand = c(0,0), limits = c(0, 4), breaks = seq(0, 4, 0.5)) + scale_x_discrete(name = 'Exp. day', expand = c(0,0), limits = seq(0, 43, 1), labels = c('5', '10', '15', '20', '25', '30', '35', '40'), breaks = seq(5, 40, 5))
wplot <- wplot + theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14))
wplot
fplot <- ggplot(fcov, aes(x = day, y = cov, fill = time))
fplot <- fplot + theme_classic() + theme(text = element_text(family = plotfont, size = 14), legend.position = 'none', plot.margin = margin(10, 5, 10, 1, 'pt'))
fplot <- fplot + geom_bar(stat = 'identity', position = 'dodge') + geom_errorbar(aes(ymin = cov-csd, ymax = cov+csd), width = 0.4, position = position_dodge(1)) +
scale_fill_manual(guide = guide_legend(title = NULL, label.theme = element_text(size = 14, angle = 0, family = plotfont)), labels = c('Day', 'Night'), values = c('day_cov' = 'gray60', 'night_cov' = 'gray30'))
fplot <- fplot + scale_y_continuous(name = 'Coverage (%)', expand = c(0,0), limits = c(0, 4), breaks = seq(0, 4, 0.5)) + scale_x_discrete(name = 'Exp. day', expand = c(0,0), limits = seq(0, 43, 1), labels = c('5', '10', '15', '20', '25', '30', '35', '40'), breaks = seq(5, 40, 5))
fplot <- fplot + theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14))
fplot
acplot <- ggplot(acov, aes(x = day, y = cov, fill = time))
acplot <- acplot + theme_classic() + theme(text = element_text(family = plotfont, size = 14), legend.position = c(0.9, 0.9), plot.margin = margin(10, 1, 10, 10, 'pt'))
acplot <- acplot + geom_bar(stat = 'identity', position = 'dodge') + geom_errorbar(aes(ymin = cov-csd, ymax = cov+csd), width = 0.4, position = position_dodge(1)) +
scale_fill_manual(guide = guide_legend(title = NULL, label.theme = element_text(size = 14, angle = 0, family = plotfont)), labels = c('Day', 'Night'), values = c('day_cov' = 'gray60', 'night_cov' = 'gray30'))
acplot <- acplot + scale_y_continuous(name = 'Coverage (%)', expand = c(0,0), limits = c(0, 4), breaks = seq(0, 4, 0.5)) + scale_x_discrete(name = 'Exp. day', expand = c(0,0), limits = seq(0, 30, 1), labels = c('5', '10', '15', '20', '25', '30'), breaks = seq(5, 30, 5))
acplot <- acplot + theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14))
acplot
naplot <- ggplot(nacov, aes(x = day, y = cov, fill = time))
naplot <- naplot + theme_classic() + theme(text = element_text(family = plotfont, size = 14), legend.position = 'none', plot.margin = margin(10, 1, 10, 10, 'pt'))
naplot <- naplot + geom_bar(stat = 'identity', position = 'dodge') + geom_errorbar(aes(ymin = cov-csd, ymax = cov+csd), width = 0.4, position = position_dodge(1)) +
scale_fill_manual(guide = guide_legend(title = NULL, label.theme = element_text(size = 14, angle = 0, family = plotfont)), labels = c('Day', 'Night'), values = c('day_cov' = 'gray60', 'night_cov' = 'gray30'))
naplot <- naplot + scale_y_continuous(name = 'Coverage (%)', expand = c(0,0), limits = c(0, 4), breaks = seq(0, 4, 0.5)) + scale_x_discrete(name = 'Exp. day', expand = c(0,0), limits = seq(0, 30, 1), labels = c('5', '10', '15', '20', '25', '30'), breaks = seq(5, 30, 5))
naplot <- naplot + theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14))
naplot
plot_grid(wplot, acplot, fplot, naplot, labels = c('(a)', '(c)', '(b)', '(d)'), rel_widths = c(1,1), hjust = c(-3, -3.5, -3, -3.5))
# 8. Polar plots of headings-------------------------------------
# load wild vs. farmed dataset
#new dayfile classes
dayfile.classes <- c('NULL', 'numeric', 'factor', 'factor', 'POSIXct', 'double', 'double',
'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'factor',
'factor', 'factor', 'factor', 'factor', 'factor', 'factor', 'factor',
'double', 'double', 'double', 'double', 'double', 'double', 'double',
'double', 'double', 'double', 'double', 'double', 'double', 'double',
'factor', 'factor', 'factor', 'factor', 'factor', 'factor', 'factor',
'factor', 'factor', 'factor', 'factor', 'factor', 'factor', 'factor', 'factor', 'factor',
'factor', 'factor', 'double', 'double', 'double', 'double', 'double',
'double', 'double', 'double', 'double', 'double', 'double', 'double', 'factor'
)
# Load wild vs. farmed data
workingdir <- ifelse(Sys.info()['user'] == 'Laptop', 'H:/Acoustic tag - Wild vs. Farmed/Data processing/Cropped data/Coded Day CSV', '/Volumes/My Book/Acoustic datasets/Wild vs Farmed') # change to location of data
setwd(workingdir)
files <- list.files(path = workingdir, pattern = '*.csv', all.files = FALSE, recursive = FALSE)
dayfile <- data.frame()
for(i in 1:length(files)){
daytemp <- fread(files[[i]])
#daytemp <- read.csv(files[[i]], header = TRUE, sep = ",", colClasses = dayfile.classes)
dayfile <- rbind(dayfile, daytemp)
}
dayfile$EchoTime <- as.POSIXct(dayfile$EchoTime)
dayfile$V1 <- NULL
wfdata <- dayfile[,c(1, 3, 4, 10, 12, 13, 47, 48)] %>%
filter(Period != 8711) %>%
filter(Period != 8347)
hadjconst <- 24.88
# readjust headings from local to global coordinates
wfdata$HEAD <- ifelse(wfdata$HEAD-hadjconst <0, 360-(hadjconst-wfdata$HEAD), wfdata$HEAD-hadjconst)
wfdata$HEIGHT <- as.factor(wfdata$HEIGHT)
wfdata$HEIGHT <- factor(wfdata$HEIGHT, levels(wfdata$HEIGHT)[c(2, 1, 3)]) # reorder factor levels
threshold <- 1
whead <- subset(wfdata, PEN == 7 & BLSEC >= threshold)
whead <- subset(whead, HEIGHT == 'S' | HEIGHT == 'N')
fhead <- subset(wfdata, PEN == 8 & BLSEC >= threshold)
fhead <- subset(fhead, HEIGHT == 'S' | HEIGHT == 'N')
# Load acclimated vs. non-acclimated data
#workingdir <- 'H:/Data processing/2016 Conditioning study B/Filtered Data/Recoded Day CSV'
workingdir <- ifelse(Sys.info()['user'] == 'Laptop', 'H:/Acoustic tag - Preconditioning B/Data processing/Filtered Data/Recoded Day CSV', '/Volumes/My Book/Acoustic datasets/Precon B') # change to location of data
setwd(workingdir)
files <- list.files(path = workingdir, pattern = '*.csv', all.files = FALSE, recursive = FALSE)
dayfile <- data.frame()
for(i in 1:length(files)){
#daytemp <- read.csv(files[[i]], header = TRUE, sep = ",", colClasses = dayfile.classes)
daytemp <- fread(files[[i]])
dayfile <- rbind(dayfile, daytemp)
}
dayfile$EchoTime <- as.POSIXct(dayfile$EchoTime)
dayfile$V1 <- NULL
accdata <- dayfile[,c(1, 3, 4, 10, 12, 13, 47, 48)]
hadjconst <- 24.88
# readjust headings from local to global coordinates
accdata$HEAD <- ifelse(accdata$HEAD-hadjconst <0, 360-(hadjconst-accdata$HEAD), accdata$HEAD-hadjconst)
accdata$HEIGHT <- as.factor(accdata$HEIGHT)
accdata$HEIGHT <- factor(accdata$HEIGHT, levels(accdata$HEIGHT)[c(2, 1, 3)]) # reorder factor levels
threshold <- 1
ahead <- subset(accdata, PEN == 7 & BLSEC >= threshold)
ahead <- subset(ahead, HEIGHT == 'S' | HEIGHT == 'N')
nahead <- subset(accdata, PEN == 8 & BLSEC >= threshold)
nahead <- subset(nahead, HEIGHT == 'S' | HEIGHT == 'N')
# polar plots of wild and farmed fish
plotfont <- 'Arial'
pplotw <- ggplot(whead, aes(x = HEAD, fill = HEIGHT)) +
geom_histogram(breaks = seq(0, 360, 10), size = 0.5, closed = 'left', color = 'black') + #, alpha = 0) +
theme_minimal() + theme(axis.text.y = element_blank(), axis.title.y = element_blank(), legend.key.size = unit(1.5, 'lines'), legend.key.height = unit(1.5, 'lines')) +
theme(text = element_text(family = plotfont, size = 14), plot.margin = margin(0, 0, 0, 0, 'pt'), legend.position = c(1.1, 0.0)) +
scale_x_continuous('', limits = c(0, 360), expand = c(0, 0), breaks = seq(0, 330, 30), labels = c('0', '30', '60', '90', '120', '150', '180', '210', '240', '270', '300', '330'), minor_breaks = seq(0, 360, 10)) +
scale_fill_manual(guide = guide_legend(title = 'Tide', label.theme = element_text(size = 14, angle = 0, family = plotfont)), labels = c('Spring', 'Neap'), values = c('S' = 'gray70', 'N' = 'gray40')) +
scale_y_continuous('', breaks = seq(0, 11000, 2500) , limits = c(0, 11000)) +
theme(axis.text.x = element_text(size = 14)) +
coord_polar(theta = 'x', start = 0)
pplotf <- ggplot(fhead, aes(x = HEAD, fill = HEIGHT)) +
geom_histogram(breaks = seq(0, 360, 10), size = 0.5, closed = 'left', color = 'black') + #, alpha = 0) +
theme_minimal() + theme(axis.text.y = element_blank(), axis.title.y = element_blank()) +
theme(text = element_text(family = plotfont, size = 14), plot.margin = margin(0, 0, 0, 0, 'pt'), legend.position = 'none') +
scale_x_continuous('', limits = c(0, 360), expand = c(0, 0), breaks = seq(0, 330, 30), labels = c('0', '30', '60', '90', '120', '150', '180', '210', '240', '270', '300', '330'), minor_breaks = seq(0, 360, 10)) +
scale_fill_manual(guide = guide_legend(title = 'Tide', label.theme = element_text(size = 14, angle = 0, family = plotfont)), labels = c('Spring', 'Neap'), values = c('S' = 'gray70', 'N' = 'gray40')) +
scale_y_continuous('', breaks = seq(0, 11000, 2500) , limits = c(0, 11000)) +
theme(axis.text.x = element_text(size = 14)) +
coord_polar(theta = 'x', start = 0)
# polar plots of acclimated and non-acclimated fish
pplota <- ggplot(ahead, aes(x = HEAD, fill = HEIGHT)) +
geom_histogram(breaks = seq(0, 360, 10), size = 0.5, closed = 'left', color = 'black') + #, alpha = 0) +
theme_minimal() + theme(axis.text.y = element_blank(), axis.title.y = element_blank()) +
theme(text = element_text(family = plotfont, size = 14), plot.margin = margin(0, 0, 0, 0, 'pt'), legend.position = 'none') +
scale_x_continuous('', limits = c(0, 360), expand = c(0, 0), breaks = seq(0, 330, 30), labels = c('0', '30', '60', '90', '120', '150', '180', '210', '240', '270', '300', '330'), minor_breaks = seq(0, 360, 10)) +
scale_fill_manual(guide = guide_legend(title = 'Tide', label.theme = element_text(size = 14, angle = 0, family = plotfont)), labels = c('Spring', 'Neap'), values = c('S' = 'gray70', 'N' = 'gray40')) +
scale_y_continuous('', breaks = seq(0, 11000, 2500) , limits = c(0, 11000), expand = c(0, 0)) +
theme(axis.text.x = element_text(size = 14)) +
coord_polar(theta = 'x', start = 0)
pplotna <- ggplot(nahead, aes(x = HEAD, fill = HEIGHT)) +
geom_histogram(breaks = seq(0, 360, 10), size = 0.5, closed = 'left', color = 'black') + #, alpha = 0) +
theme_minimal() + theme(axis.text.y = element_blank(), axis.title.y = element_blank()) +
theme(text = element_text(family = plotfont, size = 14), plot.margin = margin(0, 0, 0, 0, 'pt'), legend.position = 'none') +
scale_x_continuous('', limits = c(0, 360), expand = c(0, 0), breaks = seq(0, 330, 30), labels = c('0', '30', '60', '90', '120', '150', '180', '210', '240', '270', '300', '330'), minor_breaks = seq(0, 360, 10)) +
scale_fill_manual(guide = guide_legend(title = 'Tide', label.theme = element_text(size = 14, angle = 0, family = plotfont)), labels = c('Spring', 'Neap'), values = c('S' = 'gray70', 'N' = 'gray40')) +
scale_y_continuous('', breaks = seq(0, 25000, 2500), limits = c(0, 25000)) +
theme(axis.text.x = element_text(size = 14)) +
coord_polar(theta = 'x', start = 0)
# plot four polar plots and label
plot_grid(pplotw, pplotf, pplota, pplotna, labels = c('(a)', '(b)', '(c)', '(d)'), rel_widths = c(1,1), hjust = c(-2, -2, -2, -2), vjust = c(5, 5, 5, 5))
#plot_grid(pplotw, pplotf, labels = c('(a)', '(b)'), rel_widths = c(1,1), hjust = c(-2, -2), vjust = c(5, 5))
# extract data from histograms and make table
headextract <- function(inputdata){
hdata <- ggplot_build(ggplot(inputdata, aes(x = HEAD, fill = HEIGHT)) +
geom_histogram(breaks = c(0, seq(11.25, 348.75, 22.5), 360)))
hdata <- hdata$data[[1]]
hdata <- hdata[,c(3, 5, 6, 11)]
hdata <- spread(hdata, group, count)
colnames(hdata) <- c('xmin', 'xmax', 'spring', 'neap')
hdata$spring <- round((hdata$spring/sum(hdata$spring))*100, 2)
hdata$neap <- round((hdata$neap/sum(hdata$neap))*100, 2)
hdata$range <- paste0(hdata$xmin, '-', hdata$xmax)
hdata[,c(1, 2)] <- NULL
hdata <- hdata[,c(3, 1, 2)]
hdata <<- hdata
}
write.csv(headextract(whead), 'wildheadings.csv')
write.csv(headextract(fhead), 'farmedheadings.csv')
write.csv(headextract(ahead), 'acclimatedheadings.csv')
write.csv(headextract(nahead), 'nonacclimatedheadings.csv')
# 9. Activity by time of day for wild, hatchery acclimated and hatchery and pen acclimated-----------------
# Read in wild vs. farmed activity data
detach('package:xlsx')
library(openxlsx)
setwd('H:/Data processing/2015 Wild vs. Farmed/Cropped data/Coded Fish CSV/Outputs')
wfact <- read.xlsx('ActivityTotOutput2.xlsx', sheet = 1)
rownames(wfact) <- wfact$ID
wfact$ID <- NULL
wfact <- t(wfact)
wact <- wfact[,1:8]
fact <- wfact[,9:16]
wact <- as.data.frame(wact[!(rowSums(is.na(wact))),])
fact <- as.data.frame(fact[!(rowSums(is.na(fact))),])
wact <- setDT(wact, keep.rownames = T)[]
colnames(wact)[1] <- 'fishID'
fact <- setDT(fact, keep.rownames = T)[]
colnames(fact)[1] <- 'fishID'
wact <- wact[order(P7_day_mean),]
wact$fishID <- as.factor(wact$fishID)
flevels <- wact$fishID
wact$fishID <- factor(wact$fishID, levels = flevels)
# Read in acclimated A activity data
setwd('H:/Data analysis/Acoustic tag - Preconditioning A/Filtered Data')
hacact <- read.xlsx('PreconA_analysisbyfish_filtered.xlsx', sheet = 4, rows = seq(2, 10, 1), cols = seq(1, 14, 1), colNames = T, rowNames = T)
hacact <- as.data.frame(t(hacact))
hacact <- setDT(hacact, keep.rownames = T)[]
colnames(hacact)[1] <- 'fishID'
hacact <- hacact[order(Day_mean),]
hacact$fishID <- as.factor(hacact$fishID)
flevels <- hacact$fishID
hacact$fishID <- factor(hacact$fishID, levels = flevels)
colnames(wact) <- colnames(hacact)
colnames(fact) <- colnames(hacact)
# Read in acclimated B activity data
setwd('H:/Data analysis/Acoustic tag - Preconditioning B/Filtered Data')
hpacact <- read.xlsx('PreconB_analysisbyfish_filtered.xlsx', sheet = 4, rows = seq(2, 10, 1), cols = seq(1, 11, 1), colNames = T, rowNames = T)
hpacact <- as.data.frame(t(hpacact))
hpacact <- setDT(hpacact, keep.rownames = T)[]
colnames(hpacact)[1] <- 'fishID'
hpacact <- hpacact[order(Day_mean),]
hpacact$fishID <- as.factor(hpacact$fishID)
flevels <- hpacact$fishID
hpacact$fishID <- factor(hpacact$fishID, levels = flevels)
mact <- melt(wact[,c('fishID', 'Dawn_mean', 'Day_mean', 'Dusk_mean', 'Night_mean')], measure.vars = c('Dawn_mean', 'Day_mean', 'Dusk_mean', 'Night_mean'), variable.name = 'time', value.name = 'act')
actse <- melt(wact[,c('fishID', 'Dawn_se', 'Day_se', 'Dusk_se', 'Night_se')], measure.vars = c('Dawn_se', 'Day_se', 'Dusk_se', 'Night_se'), variable.name = 'time', value.name = 'se')
actse <- actse[,3]
wact <- cbind(mact, actse)
rm(mact, actse)
mact <- melt(hacact[,c('fishID', 'Dawn_mean', 'Day_mean', 'Dusk_mean', 'Night_mean')], measure.vars = c('Dawn_mean', 'Day_mean', 'Dusk_mean', 'Night_mean'), variable.name = 'time', value.name = 'act')
actse <- melt(hacact[,c('fishID', 'Dawn_se', 'Day_se', 'Dusk_se', 'Night_se')], measure.vars = c('Dawn_se', 'Day_se', 'Dusk_se', 'Night_se'), variable.name = 'time', value.name = 'se')
actse <- actse[,3]
hacact <- cbind(mact, actse)
rm(mact, actse)
mact <- melt(hpacact[,c('fishID', 'Dawn_mean', 'Day_mean', 'Dusk_mean', 'Night_mean')], measure.vars = c('Dawn_mean', 'Day_mean', 'Dusk_mean', 'Night_mean'), variable.name = 'time', value.name = 'act')
actse <- melt(hpacact[,c('fishID', 'Dawn_se', 'Day_se', 'Dusk_se', 'Night_se')], measure.vars = c('Dawn_se', 'Day_se', 'Dusk_se', 'Night_se'), variable.name = 'time', value.name = 'se')
actse <- actse[,3]
hpacact <- cbind(mact, actse)
rm(mact, actse)
# hpacact <- as.data.frame(hpacact)
# Create dataframes of significance levels
hpacsig <- data.frame(fishID = unique(hpacact$fishID), act = c(0.48, 0.5, 0.6, 0.61, 0.75, 0.82, 0.9, 0.99, 1.06, 1.05))
wsig <- data.frame(fishID = unique(wact$fishID), act = c(0.31, 0.42, 0.43, 0.43, 0.44, 0.45, 0.45, 0.45, 0.47, 0.49, 0.5, 0.58, 0.59, 0.59))
hacsig <- data.frame(fishID = unique(hacact$fishID), act = c(0.6, 0.6, 0.61, 0.63, 0.64, 0.64, 0.64, 0.7, 0.7, 0.72, 0.85, 0.85, 1.01))
# Draw barplots of activity
plotfont <- 'Arial'
wpact <- ggplot(wact, aes(x = fishID, y = act)) +
theme_classic() +
theme(text = element_text(family = plotfont, size = 14), legend.position = c(0.2, 0.9), plot.margin = margin(10, 5, 10, 1, 'pt')) +
geom_bar(aes(fill = time), stat = 'identity', position = 'dodge') +
geom_errorbar(aes(ymin = act-se, ymax = act+se, fill = time), width = 0.4, position = position_dodge(1)) +
scale_fill_manual(guide = guide_legend(title = NULL, label.theme = element_text(size = 14, angle = 0, family = plotfont)), labels = c('Dawn', 'Day', 'Dusk', 'Night'), values = c('Dawn_mean' = 'gray40', 'Day_mean' = 'gray80', 'Dusk_mean' = 'gray60', 'Night_mean' = 'gray20')) +
scale_y_continuous(name = 'Activity (BL/s)', expand = c(0,0), limits = c(0, 1.1), breaks = seq(0, 1.1, 0.1)) +
scale_x_discrete(name = 'fish ID', expand = c(0,0)) +
theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14)) +
geom_text(data = wsig, label = c(' ', '*', '*', '**', '*', '*', '*', '*', '*', '*', '*', '**', '*', '**'), size = 5, hjust = 'centre')
wpact
hacpact <- ggplot(hacact, aes(x = fishID, y = act)) +
theme_classic() +
theme(text = element_text(family = plotfont, size = 14), legend.position = 'none', plot.margin = margin(10, 5, 10, 1, 'pt')) +
geom_bar(aes(fill = time), stat = 'identity', position = 'dodge') +
geom_errorbar(aes(ymin = act-se, ymax = act+se, fill = time), width = 0.4, position = position_dodge(1)) +
scale_fill_manual(guide = guide_legend(title = NULL, label.theme = element_text(size = 14, angle = 0, family = plotfont)), labels = c('Dawn', 'Day', 'Dusk', 'Night'), values = c('Dawn_mean' = 'gray40', 'Day_mean' = 'gray80', 'Dusk_mean' = 'gray60', 'Night_mean' = 'gray20')) +
scale_y_continuous(name = 'Activity (BL/s)', expand = c(0,0), limits = c(0, 1.1), breaks = seq(0, 1.1, 0.1)) +
scale_x_discrete(name = 'fish ID', expand = c(0,0)) +
theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14)) +
geom_text(data = hacsig, label = c(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*'), size = 5, hjust = 'centre')
hacpact
hpacpact <- ggplot(hpacact, aes(x = fishID, y = act)) + #, fill = time)) +
theme_classic() +
theme(text = element_text(family = plotfont, size = 14), legend.position = 'none', plot.margin = margin(10, 5, 10, 1, 'pt')) +
geom_bar(aes(fill = time), stat = 'identity', position = 'dodge') +
geom_errorbar(aes(ymin = act-se, ymax = act+se, fill = time), width = 0.4, position = position_dodge(1)) +
scale_fill_manual(guide = guide_legend(title = NULL, label.theme = element_text(size = 14, angle = 0, family = plotfont)), labels = c('Dawn', 'Day', 'Dusk', 'Night'), values = c('Dawn_mean' = 'gray40', 'Day_mean' = 'gray80', 'Dusk_mean' = 'gray60', 'Night_mean' = 'gray20')) +
scale_y_continuous(name = 'Activity (BL/s)', expand = c(0,0), limits = c(0, 1.1), breaks = seq(0, 1.1, 0.1)) +
scale_x_discrete(name = 'fish ID', expand = c(0,0)) +
theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14)) +
geom_text(data = hpacsig, label = c(' ', ' ', ' ', ' ', '*', ' ', '*', '*', '*', '**'), size = 5, hjust = 'centre')
hpacpact
actleg <- get_legend(wpact)
wpact <- wpact + theme(legend.position = 'none')
plot_grid(wpact, actleg, hacpact, hpacpact, labels = c('(a)', ' ', '(b)', '(c)'), rel_widths = c(1,1), hjust = c(-4, -4, -4, -4), vjust = c(3, 3, 3, 3))
plot_grid(plot_grid(wpact, actleg, labels = c('(a)', ' '), hjust = c(-4, -4), vjust = c(3, 3), rel_widths = c(1.2, 0.8), scale = c(1, 0)), plot_grid(hacpact, hpacpact, labels = c('(b)', '(c)'), hjust = c(-4, -4), vjust = c(3, 3), rel_widths = c(1.13, 0.87)), nrow = 2, ncol = 1)
# 10. Line plots of night and day depth and activity for non-acclimated and hatchery and pen-acclimated-------------------
detach('package:xlsx')
library(openxlsx)
library(data.table)
library(ggplot2)
library(extrafont)
library(extrafontdb)
library(cowplot)
# Read and modify depth data
setwd('H:/Data processing/2016 Conditioning study B/Filtered Data/Recoded Day CSV')
mdepth <- read.xlsx('DepthTotOutput.xlsx', sheet = 1, rows = seq(1, 17, 1), cols = seq(2, 32, 1), colNames = T, rowNames = T)
mdepth <- as.data.frame(t(mdepth))
mdepth <- setDT(mdepth, keep.rownames = T)[]
colnames(mdepth)[1] <- 'Day'
mdepth$Day <- as.numeric(mdepth$Day)
accdepth <- mdepth[,c(1, 4, 5, 8, 9)]
#accdepth$P7_day_mean <- as.numeric(levels(accdepth$P7_day_mean))[accdepth$P7_day_mean]
#accdepth$P7_day_se <- as.numeric(levels(accdepth$P7_day_se))[accdepth$P7_day_se]
#accdepth$P7_night_mean <- as.numeric(levels(accdepth$P7_night_mean))[accdepth$P7_night_mean]
#accdepth$P7_night_se <- as.numeric(levels(accdepth$P7_night_se))[accdepth$P7_night_se]
mdep <- melt(accdepth[,c('Day', 'P7_day_mean', 'P7_night_mean')], measure.vars = c('P7_day_mean', 'P7_night_mean'), variable.name = 'time', value.name = 'mean')
sedep <- melt(accdepth[,c('Day', 'P7_day_se', 'P7_night_se')], measure.vars = c('P7_day_se', 'P7_night_se'), variable.name = 'time', value.name = 'se')
sedep <- sedep[,3]
accdepth <- cbind(mdep, sedep)
rm(mdep, sedep)
colnames(accdepth) <- c('daynum', 'tod', 'mdepth', 'se')
#accdepth$daynum <- as.factor(accdepth$daynum)
naccdepth <- mdepth[,c(1, 12, 13, 16, 17)]
#naccdepth$P8_day_mean <- as.numeric(levels(naccdepth$P8_day_mean))[naccdepth$P8_day_mean]
#naccdepth$P8_day_se <- as.numeric(levels(naccdepth$P8_day_se))[naccdepth$P8_day_se]
#naccdepth$P8_night_mean <- as.numeric(levels(naccdepth$P8_night_mean))[naccdepth$P8_night_mean]
#naccdepth$P8_night_se <- as.numeric(levels(naccdepth$P8_night_se))[naccdepth$P8_night_se]
mdep <- melt(naccdepth[,c('Day', 'P8_day_mean', 'P8_night_mean')], measure.vars = c('P8_day_mean', 'P8_night_mean'), variable.name = 'time', value.name = 'mean')
sedep <- melt(naccdepth[,c('Day', 'P8_day_se', 'P8_night_se')], measure.vars = c('P8_day_se', 'P8_night_se'), variable.name = 'time', value.name = 'se')
sedep <- sedep[,3]
naccdepth <- cbind(mdep, sedep)
colnames(naccdepth) <- c('daynum', 'tod', 'mdepth', 'se')
rm(mdep, sedep)
# read and modify activity data for non-acclimated and hatchery and pen-acclimated
setwd('H:/Data processing/2016 Conditioning study B/Filtered Data/Recoded Day CSV')
mact <- read.xlsx('ActivityTotOutput.xlsx', sheet = 1, rows = seq(1, 17, 1), cols = seq(2, 32, 1), colNames = T, rowNames = T)
mact <- as.data.frame(t(mact))
mact <- setDT(mact, keep.rownames = T)[]
colnames(mact)[1] <- 'Day'
mact$Day <- as.numeric(mact$Day)