-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_fuegian_sprat_ELS.R
4207 lines (3482 loc) · 141 KB
/
script_fuegian_sprat_ELS.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
rm(list=ls())
# Packages employed ----
library(rnaturalearth)
library(rnaturalearthdata)
library(rnaturalearthhires)
library(sf)
library(marmap) #getNOAA.bathy()
library(ggspatial) #annotation_north_arrow(), annotation_scale()
library(rworldmap) #getMap()
library(maptools) #nowrapRecenter()
library(reshape2) #melt()
library(mapview) #npts()-counts number of points in sf object
library(lwgeom) #st_geod_area()
library(units) #set_units()-from m2 to km2 in spatial data
library(nlme) #gls()
library(car) #leveneTest()
library(fishmethods) #growth()
library(ggpubr) #theme_transparent()
library(ggforce) #facet_col()
library(viridis)
library(patchwork) #arrange multiple plots
library(lubridate) #ymd()-convert dates
library(gganimate) #animate(), transition_reveal()
library(ggExtra) #ggMarginal()
library(tidyverse)
# Additional base steps ----
#colors employed by zone
mis_colores <- c("#fce436ff","#fca636ff","#b12a90ff","#0d0887ff")
#colors employed by zone for simulations
mis_colores2 <- c("#0d0887ff","#fca636ff","#fce436ff")
#colors for density plots
color_cor <- c("#F17720","#0474BA")
#to solve problems with latest version of sf for st_as_sf()
sf_use_s2(FALSE)
# Data ----
## Abundances ----
abundancias <-
#load data
read.csv(file = "tabla_abundancias_final.csv", header = TRUE)%>%
#remove blank lines
filter(!is.na(ano)) %>% # Remove blank lines
#rename and re-level surveys
mutate(camp = factor(camp,
levels=c('pdmar14','pdbur2014',
'tangofeb2015','bbtdfdic2015',
'bbbabr2016','pdbbdic16',
'pdbbabr17'),
labels = c('Autumn-2014','Spring-2014',
'Summer-2015','Spring-2015',
'Autumn-2016','Spring-2016',
'Autumn-2017'))) %>%
#rename and relevel zones
mutate(zona = factor(zona,
levels=c('costa','isla_est','medio','banco'),
labels = c('TDF','IE','WBB','BB'))) %>%
#rename and relevel seasons
mutate(season = factor(season,
levels=c('spring','summer','autumn'),
labels=c('Spring','Summer','Autumn'))) %>%
#new column according to net employed
mutate(camp_red = case_when(camp == 'Autumn-2017' & red == "ikmt" ~
"Autumn-2017 (IKMT)", #condition 1
camp == 'Autumn-2017' & red == "bgo_300um" ~
"Autumn-2017 (Bongo)", #condition 2
TRUE ~ as.character(camp)) %>% #all other cases
fct_relevel('Autumn-2014','Spring-2014','Summer-2015',
'Spring-2015','Autumn-2016','Spring-2016',
'Autumn-2017 (Bongo)','Autumn-2017 (IKMT)'))
## Standard lengths (SL) and otolith microestructure ----
tallas <-
#load data
read.csv(file = "tabla_tallas_final.csv", header = TRUE) %>%
#cleaning
filter(!is.na(ano))%>% #remove na rows
select_if(~sum(!is.na(.)) > 0)%>% #remove na columns
filter(!is.na(talla_cor_mm2))%>% #remove lines without SL
filter(!estadio=="")%>% #remove lines without developmental stage
mutate(fecha = ymd(fecha))%>% #convert survey dates
mutate(eclosion = ymd(eclosion))%>% #convert hatching dates
mutate(mes_eclosion = month(eclosion, label = T))%>% #hatching month
mutate(desove = ymd(desove))%>% #convert spawning dates
mutate(mes_desove = month(desove, label = T))%>% #spawning month
mutate(fijador2= as_factor(fijador2)) %>% #fixation as factor
droplevels() %>%
#rename and relevel surveys
mutate(camp = factor(camp,
levels=c('pdmar14','pdbur2014',
'tangofeb2015','bbtdfdic2015',
'bbbabr2016','pdbbdic16',
'pdbbabr17'),
labels = c('Autumn-2014','Spring-2014',
'Summer-2015','Spring-2015',
'Autumn-2016','Spring-2016',
'Autumn-2017'))) %>%
#rename and relevel zones
mutate(zona = factor(zona,
levels=c('costa','isla_est','medio','banco'),
labels = c('TDF','IE','WBB','BB'))) %>%
#rename and relevel spawning months
mutate(mes_desove = factor(mes_desove,
levels=c('sep','oct','nov','dic',
'ene','feb','mar','may'),
labels=c('sep','oct','nov','dec',
'jan','feb','mar','may'))) %>%
#rename and relevel developmental stages
mutate(estadio = factor(estadio,
levels=c('vitelina','preflexion','flexion',
'postflexion','metamorfosis','juvenil'),
labels=c('Yolk-sac','Preflexion','Flexion',
'Postflexion','Metamorphosis','Juvenile'))) %>%
#rename and relevel seasons
mutate(season = factor(season,
levels=c('spring','summer','autumn'),
labels=c('Spring','Summer','Autumn'))) %>%
#new column according to net employed
mutate(camp_red = case_when(camp == 'Autumn-2017' & red == "ikmt" ~
"Autumn-2017 (IKMT)", #condition 1
camp == 'Autumn-2017' & red == "bgo_300um" ~
"Autumn-2017 (Bongo)", #condition 2
TRUE ~ as.character(camp)) %>% #all other cases
fct_relevel('Autumn-2014','Spring-2014','Summer-2015',
'Spring-2015','Autumn-2016','Spring-2016',
'Autumn-2017 (Bongo)','Autumn-2017 (IKMT)')) %>%
#cohorts
mutate(p_desove = case_when(camp=='Autumn-2014'~"2013-2014",
camp=='Spring-2014'|camp=='Summer-2015'~"2014-2015",
camp=='Spring-2015'|camp=='Autumn-2016'~"2015-2016",
camp=='Spring-2016'|camp=='Autumn-2017'~"2016-2017") %>%
fct_relevel("2013-2014","2014-2015","2015-2016","2016-2017"))
# Larvae
tallas_larvas <- tallas %>%
filter(!estadio %in% c("Metamorphosis","Juvenile"))%>%
droplevels()
# Post-larvae
tallas_post_larvas <- tallas %>%
filter(estadio %in% c("Metamorphosis","Juvenile"))%>%
droplevels()
# Maps ----
## Bathymetry ----
#download and save data
#data is heavy! choose just beyond the limits needed.
# bathy <- getNOAA.bathy(lon1=-95, lon2=-48,
# lat1=-58.5, lat2=-28,
# resolution=1, #resolution in minutes
# keep=T) #saves data
#prepare data
bathy <- read.csv(file = "bati_-80;-58.5;-48;-28_res_1.csv",
header = TRUE) %>%
as.bathy() %>%
fortify.bathy() %>% #extract bathymetric values
mutate(z = as.numeric(z))
str(bathy)
#subset for south america
bati_sa<-bathy%>%
filter(z<=-1 & between(x, -78, -50) & between(y, -58.5, -30))
#subset for study area
bati_ae<-bathy%>%
filter(z<=-1 & between(x, -70, -55) & between(y, -56, -52))
## Base worldmap ----
#worldmap
world <- ne_countries(scale = "large", type = "countries", returnclass = "sf")
## Basemap for study area ----
mapa1<-
ggplot(data = st_crop(world,
c(xmin=-70, xmax=-55,
ymin=-56, ymax=-52))) +
geom_sf(fill= "#999999ff", color="white")+
geom_contour(data = bati_ae, aes(x=x, y=y, z=z),
breaks=c(-200), size=0.5, colour="grey44")+
coord_sf(xlim = c(-70, -55), ylim = c(-56, -52), expand = F)+
scale_x_continuous(breaks = seq(from=-68, to=-56, by=4)) +
scale_y_continuous(breaks = seq(from=-55, to=-53, by=2))+
annotation_scale(location = "br",
width_hint = 0.2) +
annotation_north_arrow(location = "tr",
which_north = T)+
labs(x="", y="")+
annotate("text", x = -58.65, y = -52.5,
label = "-200m", size = 3, angle=45)+
guides(alpha=NULL)+
theme_bw()+
theme(axis.text.y=element_text(angle = 90, hjust = 0.5),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
plot.background = element_rect(fill = "transparent", colour = NA),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text=element_text(size=10)
)
# Figure 1. Southamerica and study area ----
## A. Southamerica ----
### Round map ----
#based on:
#https://notpeerreviewed.netlify.app/2020/03/mapping-nz-with-an-orthographic-projection/
# download world data and use the nowrapRecenter function to center map
# on 180 degrees. This is important for aligning our polygons later
worldMap <- getMap() %>%
nowrapRecenter()
# converts data to a dataframe
world.points <- fortify(worldMap)
# basic manipulation
world.points$region <- world.points$id
world.df <- world.points[,c("long","lat","group", "region")]
# plot
ggplot() +
geom_polygon(data = world.df, aes(x = long, y = lat, group = group),
fill = "black") +
scale_y_continuous(breaks = (-4:4) * 15) +
scale_x_continuous(breaks = (0:12) * 30) +
coord_map("ortho", orientation=c(-25, -70, -5)) + #(lat, long, angle)
theme(panel.grid.major = element_line(color = "grey", size = 0.25,
linetype = 1, lineend = "butt"),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
panel.ontop = TRUE, # this places the chart panel on the top to give us our graticules
panel.background = element_blank(), # this removes the background so the map shows through
legend.position = "none")
### Zoom to Southamerica ----
mapa_sa <-
ggplot(data = world) +
geom_sf(fill= "grey20", colour="white")+
coord_sf(xlim = c(-78.000, -50.00),
ylim = c(-58.5, -30.000), expand = F)+
geom_contour(data = bati_sa, aes(x=x, y=y, z=z),
breaks=c(-200), size=0.5, colour="grey44")+
labs(x="", y="")+
ggpubr::theme_transparent()
## B. Zoom at SPS ----
mapa_corrientes <-
ggplot(data = world) +
scale_x_continuous(breaks = seq(from=-70, to=-54, by=4)) +
scale_y_continuous(breaks = seq(from=-57, to=-49, by=2))+
geom_raster(data=bati_sa, aes(x=x, y=y, fill=z))+
scale_fill_continuous(low="#253582ff",high="white")+
geom_sf(fill= "grey20", colour="white")+
coord_sf(xlim = c(-71, -54), ylim = c(-58, -48), expand = F)+
geom_contour(data = bati_sa, aes(x=x, y=y, z=z),
breaks=c(-200), size=0.5, colour="grey44")+
annotation_scale(location = "br", text_cex = 1, width_hint = 0.1) +
annotation_north_arrow(location = "tr", which_north = "true")+
labs(x="", y="", fill="Depth (m)")+
annotate("text", x = -58.65, y = -52.5, label = "-200m", size = 3, angle=45)+
guides(alpha="none")+
theme_bw()+
theme(axis.text.y=element_text(angle = 90, hjust = 0.5),
plot.background = element_rect(fill = "transparent", colour = NA),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text=element_text(size=10))
# Figure 2. Zones along the longitudinal gradient ----
## A. Oceanographic stations ----
#filter stations (remove duplicate ikmt and bongo stations)
abundancias_camp <- abundancias %>%
filter(red != "ikmt") %>%
droplevels()
#plot
mapa1+
# longitudinal limits
# geom_vline(xintercept=c(-64.90, -63.3,-62), colour = "grey50")+
geom_point(data = abundancias_camp, aes(x = long, y = lat, color=zona), size = 2) +
scale_color_manual(values= mis_colores)+
labs(color="Zones")+
theme(axis.text.y=element_text(angle = 90, hjust = 0.5),
plot.background = element_rect(fill = "transparent", colour = NA),
panel.grid.major = element_blank(),
strip.background = element_blank(),
strip.text = element_text(face = "bold",hjust = 0),
panel.grid.minor = element_blank())
## B. T-S diagram ----
abundancias_camp%>%
filter(!is.na(t_10m)) %>%
filter(!is.na(s_10m)) %>%
droplevels() %>%
ggplot(aes(x=s_10m, y=t_10m))+
geom_point(aes(color=zona), size=2, alpha=0.75)+
scale_color_manual(values= mis_colores)+
theme_bw()+
labs(x="Salinity", y="Temperature (°C)", color=NULL)+
theme(axis.text = element_text(size=10),
strip.background = element_blank(),
strip.text = element_text(face = "bold",hjust = 0),
plot.background = element_rect(fill = "transparent", colour = NA),
legend.position = "top")
# GLS comparing IKMT and an Bongo nets in 2017 ----
#filter data employed in the model
larvas_o17_red<- abundancias %>%
filter(camp %in% c("Autumn-2017")) %>%
filter(zona %in% c("BB")) %>%
droplevels()
#GLS
m0_larvas_o17_red<-gls(abund_larvas_100m3 ~ camp_red,
data=larvas_o17_red, na.action=na.exclude)
summary(m0_larvas_o17_red)
#check assumptions
res_larvas_o17_red<-residuals(m0_larvas_o17_red,type="pearson")
pred_larvas_o17_red<-fitted(m0_larvas_o17_red)
plot(pred_larvas_o17_red, res_larvas_o17_red, xlab="Pred", ylab="Res_est")
abline(0,0)
qqnorm(res_larvas_o17_red)
#heterocedasticity is seen so this assumptions are not complied
#GLS with modelled heterosceastity
m1_larvas_o17_red<-gls(abund_larvas_100m3 ~
camp_red, weights=varIdent(form=~1|camp_red),
data=larvas_o17_red, na.action=na.exclude)
summary(m1_larvas_o17_red)
#check assumptions
res_larvas_o17_red<-residuals(m1_larvas_o17_red,type="pearson")
pred_larvas_o17_red<-fitted(m1_larvas_o17_red)
plot(pred_larvas_o17_red, res_larvas_o17_red, xlab="Pred", ylab="Res_est")
abline(0,0)
leveneTest(abund_larvas_100m3 ~ camp_red, weights=varIdent(form=~1|camp_red), data=larvas_o17_red)
qqnorm(res_larvas_o17_red) #LM are robust to lack of normality of the data
anova(m1_larvas_o17_red)
#assumptions were complied
#there are no statistical differences (p=0.12)
# Figure 3. Release quadrants ----
## Areas where more than 200 eggs/m2 were registered ----
print.data.frame(abundancias %>%
filter(abud_huevos_m2 >= 200) %>%
group_by(zona) %>%
summarise(min_lat= min(lat),
max_lat=max(lat),
min_lon=min(long),
max_lon=max(long)))
## Gridpoints ----
### TDF ----
#load release data
lanz_tdf<-read.csv("release_sardina_fueguina_Elbio_costa.csv", header = F) %>%
#set names and set days as factor
setNames(c("lonm","latm","depthm", "dia"))%>%
mutate(dia = as.factor(dia))%>%
mutate(particula = as.factor(seq(1:nrow(.))))
#create new object with release position (day=0)
lanz_tdf0<-lanz_tdf%>%
filter(dia=="0")
#check release points
mapa1+
coord_sf(xlim = c(-66.5, -64.5), ylim = c(-55.25, -54.75), expand = F)+
geom_point(data=lanz_tdf0, aes(x= lonm, y= latm), size= 0.01, color="red")
#estimate area in km2
lon_tdf = c(-66.908, -65.828)
lat_tdf = c(-55.100, -54.973)
# create a data frame for the lat long extension
data.frame(lon_tdf, lat_tdf) %>%
#convert spatial object to simple feature objects
st_as_sf(coords = c("lon_tdf", "lat_tdf"),
crs = 4326) %>%
#return bounding of a simple feature
st_bbox() %>%
#convert spatial object to geometry
st_as_sfc() %>%
#estimate area if x in degrees lon/lat (else st_area())
st_geod_area() %>%
#set unit to km2 instead of m2
set_units(km^2)
### IE ----
#load release data
lanz_ie<-read.csv("release_sardina_fueguina_Elbio_IE_total.csv", header = F) %>%
#set names and set days as factor
setNames(c("lonm","latm","depthm", "dia"))%>%
mutate(dia = as.factor(dia)) %>%
mutate(particula = as.factor(seq(1:nrow(.))))
#create new object with release position (day=0)
lanz_ie0<-lanz_ie%>%
filter(dia=="0")
#check release points
mapa1+
coord_sf(xlim = c(-65, -63), ylim = c(-55.5, -54), expand = F)+
geom_point(data=lanz_ie0, aes(x= lonm, y= latm), size= 0.01, color="red")
#estimate area in km2
lon_ie = c(-64.373, -63.442)
lat_ie = c(-55.003, -54.568)
data.frame(lon_ie, lat_ie) %>%
st_as_sf(coords = c("lon_ie", "lat_ie"),
crs = 4326) %>%
st_bbox() %>%
st_as_sfc() %>%
st_geod_area() %>%
set_units(km^2)
### BB ----
#load release data
lanz_bb<-read.csv("release_sardina_fueguina_Elbio_BB.csv", header = F) %>%
#set names and set days as factor
setNames(c("lonm","latm","depthm", "dia"))%>%
mutate(dia = as.factor(dia)) %>%
mutate(particula = as.factor(seq(1:nrow(.))))
#create new object with release position (day=0)
lanz_bb0<-lanz_bb%>%
filter(dia=="0")
#check release points
mapa1+
coord_sf(xlim = c(-62, -57), ylim = c(-55.5, -53.5), expand = F)+
geom_point(data=lanz_bb0, aes(x= lonm, y= latm), size= 0.01, color="red")
#estimate area in km2
lon_bb = c(-60.687, -58.386)
lat_bb = c(-54.509, -54.418)
data.frame(lon_bb, lat_bb) %>%
st_as_sf(coords = c("lon_bb", "lat_bb"),
crs = 4326) %>%
st_bbox() %>%
st_as_sfc() %>%
st_geod_area() %>%
set_units(km^2)
## Plot with grids and gridpoints ----
mapa1+
# set limits of study area
coord_sf(xlim = c(-67, -58.2), ylim = c(-55.15, -54.25), expand = F)+
# TDF
geom_rect(xmin = -66.908, xmax = -65.828, ymin = -55.100, ymax = -54.973,
fill = NA, colour = "#fce436ff", linetype= "solid", size = 1) +
# IE
geom_rect(xmin = -64.373, xmax = -63.442, ymin = -55.003, ymax = -54.568,
fill = NA, colour = "#fca636ff", linetype= "solid", size = 1) +
# BB
geom_rect(xmin = -60.687, xmax = -58.386, ymin = -54.509, ymax = -54.418,
fill = NA, colour = "#0d0887ff", linetype= "solid", size = 1)+
# to add points of release
geom_point(data=lanz_tdf0, aes(x= lonm, y= latm), size= 0.01, color="grey50")+
geom_point(data=lanz_ie0, aes(x= lonm, y= latm), size= 0.01, color="grey50")+
geom_point(data=lanz_bb0, aes(x= lonm, y= latm), size= 0.01, color="grey50")
# Figure 4. Eggs ----
## Data ----
#subset data
abundancias_huevos<- abundancias %>%
filter(camp == "Spring-2014" |
camp == "Spring-2015" |
camp == "Spring-2016" ) %>%
droplevels()
#general information
print.data.frame(abundancias_huevos %>%
summarize(
total_huevos = sum(huevos_sf),
eg_con = sum(abud_huevos_m2 != 0),
n = n(),
porcentaje_pres = (eg_con/n)*100,
mean = round(mean(abud_huevos_m2),2),
min = min(abud_huevos_m2),
max = max(abud_huevos_m2),
sd = round(sd(abud_huevos_m2, na.rm=TRUE),2),
se = round(sd / sqrt(n),2)))
#information by survey
print.data.frame(abundancias_huevos %>%
group_by(camp,zona) %>%
summarize(
N = n(),
Min = min(abud_huevos_m2),
Max = max(abud_huevos_m2),
Promedio = round(mean(abud_huevos_m2),2),
sd = round(sd(abud_huevos_m2, na.rm=TRUE),2),
se = round(sd / sqrt(N),2)))
## Map -----
mapa1+
geom_point(data = subset(abundancias_huevos, abud_huevos_m2==0),
aes(x = long, y = lat), pch=3, size=2, stroke = 1.25, colour="grey") +
geom_point(data = subset(abundancias_huevos, abud_huevos_m2!=0),
aes(x = long, y = lat,
alpha = 0.75,
size = abud_huevos_m2,
color = zona)) +
scale_size_continuous(limits = c(0.01,2600), range=c(4,16),
breaks = c(1, 50, 200, 500, 1500, 2600),
name = expression(Eggs/m^{2}))+
scale_color_manual(values= mis_colores)+
theme(axis.text.y=element_text(angle = 90, hjust = 0.5),
plot.background = element_rect(fill = "transparent", colour = NA),
panel.grid.major = element_blank(),
strip.background = element_blank(),
strip.text = element_text(face = "bold",hjust = 0),
legend.position = "bottom",
legend.margin=margin(-1,0,0,0),
legend.box.margin=margin(-10,0,0,0),
panel.grid.minor = element_blank())+
guides(color="none",
alpha="none",
size = guide_legend(label.position = "bottom",
title.position = "top",
title.hjust = 0.5,
nrow = 1))
# Figure 5. Sprat ----
## Data ----
#we must first estimate mean abundances per station
#for the survey of 2017 where 2 nets are considered
abundancias_sprat <- abundancias %>%
#create new variable of eg_survey
mutate(eg_camp = with(., interaction(eg, camp, sep="_",drop = T ))) %>%
#group by that variable
group_by(eg_camp) %>%
#create new variable of mean abundance per eg_survey
mutate(sf_eg_camp = mean(abund_sf_100m3)) %>%
ungroup() %>%
#keep only one value per station
distinct(eg_camp, .keep_all = TRUE)
#general information
print.data.frame(abundancias_sprat %>%
summarize(
total_larvas = sum(sf_eg_camp),
eg_con = sum(sf_eg_camp != 0),
n = n(),
porcentaje_pres = (eg_con/n)*100,
mean = round(mean(sf_eg_camp),2),
min = min(sf_eg_camp),
max = max(sf_eg_camp),
sd = round(sd(sf_eg_camp, na.rm=TRUE),2),
se = round(sd / sqrt(n),2)))
#by season
print.data.frame(abundancias_sprat %>%
group_by(season) %>%
summarize(
total_larvas = sum(sf_eg_camp),
eg_con = sum(sf_eg_camp != 0),
n = n(),
porcentaje_pres = (eg_con/n)*100,
mean = round(mean(sf_eg_camp),2),
min = min(sf_eg_camp),
max = max(sf_eg_camp),
sd = round(sd(sf_eg_camp, na.rm=TRUE),2),
se = round(sd / sqrt(n),2)))
#by survey and zone
print.data.frame(abundancias_sprat %>%
group_by(camp, zona) %>%
summarize(
total_larvas = sum(sf_eg_camp),
eg_con = sum(sf_eg_camp != 0),
n = n(),
porcentaje_pres = (eg_con/n)*100,
mean = round(mean(sf_eg_camp),2),
min = min(sf_eg_camp),
max = max(sf_eg_camp),
sd = round(sd(sf_eg_camp, na.rm=TRUE),2),
se = round(sd / sqrt(n),2)))
## A. Maps ----
mapa1+
geom_point(data = subset(abundancias_sprat, sf_eg_camp==0),
aes(x = long, y = lat), pch=3, size=2, stroke = 1.25, colour="grey") +
geom_point(data = subset(abundancias_sprat, sf_eg_camp!=0),
aes(x = long, y = lat,
alpha = 0.75,
size = sf_eg_camp,
color = zona)) +
scale_size_continuous(limits = c(0.01,1500), range=c(4,16),
breaks = c(1, 50, 200, 500, 1000, 1500),
name = expression(Sprat/100~m^{3}))+
scale_color_manual(values= mis_colores)+
facet_wrap(~ season, ncol=1)+
theme(axis.text.y=element_text(angle = 90, hjust = 0.5),
plot.background = element_rect(fill = "transparent", colour = NA),
panel.grid.major = element_blank(),
strip.background = element_blank(),
strip.text = element_text(face = "bold",hjust = 0),
legend.position = "bottom",
legend.margin=margin(-5,0,0,0),
legend.box.margin=margin(-10,0,0,0),
panel.grid.minor = element_blank())+
guides(color="none",
alpha="none",
size = guide_legend(label.position = "bottom",
title.position = "top",
title.hjust = 0.5,
nrow = 1))
## B. Developmental stages ----
estadios_porc <- tallas %>%
group_by(season, zona) %>%
count(estadio) %>%
mutate(porc = (n/sum(n))*100)
print.table(estadios_porc)
ggplot(data = estadios_porc, aes(x = "", y = porc, fill = estadio )) +
geom_bar(stat = "identity", position = position_fill()) +
geom_text(aes(label = paste(round(porc),"%")),
position = position_fill(vjust = 0.5),colour="white") +
coord_polar(theta = "y") +
facet_grid(zona ~ season, switch = "y") +
scale_y_continuous(labels = scales::percent,expand = c(0,0))+
scale_fill_viridis(discrete=T) +
labs(fill= "Developmental stage")+
theme_bw()+
theme(plot.background = element_rect(fill = "transparent", colour = NA),
panel.grid = element_blank(),
legend.justification = "top",
strip.background = element_blank(),
strip.text = element_text(face = "bold"),
strip.text.y.left = element_text(angle = 0),
axis.title=element_blank(),
panel.border = element_blank(),
axis.ticks = element_blank(),
axis.text = element_blank(),
axis.line = element_blank())
# Figure 6. Spawning months ----
## Data ----
#clean data to fit growth models
curvas_crec<-tallas%>%
#filter cases with ages
filter(!is.na(edad))%>%
#remove outliers
filter(!id %in% c(432, # larvae
1492, # juvenile
1495))%>% #juvenile
#identify larvae from post-larvae
mutate(larv_o_juv=case_when(estadio=='Preflexion'|estadio=='Flexion'|estadio=='Postflexion'~"Larvae",
estadio=='Metamorphosis'|estadio== "Juvenile" ~ "Post-Larvae"))
## Von Bertalanffy parameter calculations ----
# This model had the least residual sum-of-squares in almost all cases
# use dev.off() in the console after making the graphs!!!!
### TDF ----
# Larvae
# TDF all
tdf_total<-curvas_crec %>%
filter(zona=="TDF") %>%
filter(larv_o_juv=="Larvae")
growth(intype=1,unit=1,size=tdf_total$talla_cor_mm2,age=tdf_total$edad,
calctype=1,wgtby=1,se2=NULL,error=1,
specwgt=0.0001,Sinf=33,K=0.01,t0=0,B=3,graph=TRUE,
control=list(maxiter=10000,minFactor=1/1024,tol=1e-5))
# model: size ~ Sinf * (1 - exp(-(K * (age - t0))))
# Sinf K t0
# 33.50529 0.01456 -10.52337
# residual sum-of-squares: 174.5
# TDF 14_16
tdf_14_16<-curvas_crec %>%
filter(zona=="TDF") %>%
filter(larv_o_juv=="Larvae") %>%
filter(ano=="2014"|ano=="2016")
growth(intype=1,unit=1,size=tdf_14_16$talla_cor_mm2,age=tdf_14_16$edad,
calctype=1,wgtby=1,se2=NULL,error=1,
specwgt=0.0001,Sinf=33,K=0.01,t0=0,B=3,graph=TRUE,
control=list(maxiter=10000,minFactor=1/1024,tol=1e-5))
# model: size ~ Sinf * (1 - exp(-(K * (age - t0))))
# Sinf K t0
# 30.79195 0.01569 -11.07067
# residual sum-of-squares: 117.1
# TDF 14_17
tdf_14_17<-curvas_crec %>%
filter(zona=="TDF") %>%
filter(larv_o_juv=="Larvae") %>%
filter(ano=="2014"|ano=="2017")
growth(intype=1,unit=1,size=tdf_14_17$talla_cor_mm2,age=tdf_14_17$edad,
calctype=1,wgtby=1,se2=NULL,error=1,
specwgt=0.0001,Sinf=33,K=0.01,t0=0,B=3,graph=TRUE,
control=list(maxiter=10000,minFactor=1/1024,tol=1e-5))
# model: size ~ Sinf * (1 - exp(-(K * (age - t0))))
# Sinf K t0
# 29.57570 0.02347 -4.62964
# residual sum-of-squares: 77.15
dev.off()
# TDF post-larvae
tdf_juv<-curvas_crec %>%
filter(zona=="TDF") %>%
filter(estadio=="Metamorphosis")
#preliminary plot shows linear relation
curvas_crec %>%
filter(larv_o_juv=="Post-Larvae") %>%
ggplot(aes(x=edad, y=talla_cor_mm2))+
geom_point()
#we adjust a linear model
nls(talla_cor_mm2~a+b*edad, start=list(a=10, b=0.5),data=tdf_juv)
curvas_crec %>%
filter(larv_o_juv=="Post-Larvae") %>%
ggplot(aes(x=edad, y=talla_cor_mm2))+
geom_point()+
stat_function(fun = function(x) -7.074+(0.277*x), colour="red", size=1)
### BB ----
# BB all
bb_total<-curvas_crec %>%
filter(zona=="BB")
growth(intype=1,unit=1,size=bb_total$talla_cor_mm2,age=bb_total$edad,
calctype=1,wgtby=1,se2=NULL,error=1,
specwgt=0.0001,Sinf=33,K=0.01,t0=0,B=3,graph=TRUE,
control=list(maxiter=10000,minFactor=1/1024,tol=1e-5))
# model: size ~ Sinf * (1 - exp(-(K * (age - t0))))
# Sinf K t0
# 28.76768 0.02331 -7.28352
# residual sum-of-squares: 680.7
# BB 14_16
bb_14_16<-curvas_crec %>%
filter(zona=="BB") %>%
filter(ano=="2014"|ano=="2016")
growth(intype=1,unit=1,size=bb_14_16$talla_cor_mm2,age=bb_14_16$edad,
calctype=1,wgtby=1,se2=NULL,error=1,
specwgt=0.0001,Sinf=33,K=0.01,t0=0,B=3,graph=TRUE,
control=list(maxiter=10000,minFactor=1/1024,tol=1e-5))
# model: size ~ Sinf * (1 - exp(-(K * (age - t0))))
# Sinf K t0
# 40.436847 0.009899 -20.041391
# residual sum-of-squares: 286.7
# BB 14_17
bb_14_17<-curvas_crec %>%
filter(zona=="BB") %>%
filter(ano=="2014"|ano=="2017")
growth(intype=1,unit=1,size=bb_14_17$talla_cor_mm2,age=bb_14_17$edad,
calctype=1,wgtby=1,se2=NULL,error=1,
specwgt=0.0001,Sinf=33,K=0.01,t0=0,B=3,graph=TRUE,
control=list(maxiter=10000,minFactor=1/1024,tol=1e-5))
# model: size ~ Sinf * (1 - exp(-(K * (age - t0))))
# Sinf K t0
# 40.239690 0.006236 -29.698854
# residual sum-of-squares: 43
dev.off()
### Age estimations according to growth models ----
# age back-calculation for Von Bertalanffy model
# t = ((-1/K)*(log(1-(Lt/Linf))))+t0
a<-
tallas %>%
#filter and organize data
filter(is.na(edad)) %>%
filter(zona %in% c("TDF","BB")) %>%
filter(!p_desove=="2013-2014") %>%
mutate(larv_o_juv=case_when(estadio=='Preflexion'|estadio=='Flexion'|estadio=='Postflexion'~"Larvae",
estadio=='Metamorphosis'|estadio== "Juvenile" ~ "Post-Larvae")) %>%
#create an empty column
mutate(edad_vb=NA) %>%
#fill the new column according to the correct model
mutate(edad_vb=ifelse(zona=="TDF"&
larv_o_juv=="Larvae"&
p_desove=="2014-2015",
(((-1/0.015)*(log(1-(talla_cor_mm2/33.505))))-10.523),edad_vb))%>%
mutate(edad_vb=ifelse(zona=="TDF"&
larv_o_juv=="Larvae"&
p_desove=="2015-2016",
(((-1/0.016)*(log(1-(talla_cor_mm2/30.792))))-11.071),edad_vb))%>%
mutate(edad_vb=ifelse(zona=="TDF"&
larv_o_juv=="Larvae"&
p_desove=="2016-2017",
(((-1/0.023)*(log(1-(talla_cor_mm2/29.576))))-4.630),edad_vb))%>%
mutate(edad_vb=ifelse(zona=="TDF"&
estadio=="Metamorphosis",
((talla_cor_mm2+7.074)/0.277),edad_vb))%>%
mutate(edad_vb=ifelse(zona=="BB"&
p_desove=="2014-2015",
(((-1/0.010)*(log(1-(talla_cor_mm2/40.437))))-20.041),edad_vb))%>%
mutate(edad_vb=ifelse(zona=="BB"&
p_desove=="2015-2016",
(((-1/0.010)*(log(1-(talla_cor_mm2/40.437))))-20.041),edad_vb))%>%
mutate(edad_vb=ifelse(zona=="BB"&
p_desove=="2016-2017",
(((-1/0.006)*(log(1-(talla_cor_mm2/40.240))))-29.699),edad_vb))%>%
mutate(edad_vb=ifelse(id==432,8,edad_vb)) %>%
mutate(edad_vb=ifelse(id==1475,106,edad_vb))
#further cleaning and spawning estimations
c<-
a %>%
#round values to all estimated ages different to NA
mutate(edad_vb = ifelse(is.nan(edad_vb),NA,round(edad_vb, digits = 0))) %>%
#Yolk-sac age: 0-6 days -> 3 to all yolk-sac larvae
mutate(edad_vb = ifelse(estadio=="Yolk-sac",3,edad_vb)) %>%
#0 days to "negative" ages
dplyr::select(id,edad_vb) %>%
mutate(edad_vb = ifelse(edad_vb <=0, 0, edad_vb)) %>%
droplevels()
#unite estimated data with empirical data
tallas_des2<-
tallas %>%
select(id,zona,camp,season,estadio,talla_cor_mm2,
fecha,incrementos,edad,desove,mes_desove,p_desove)%>%
left_join(c, by="id") %>%
#keep estimated age if there are no age data
mutate(edad_2 = ifelse(is.na(edad),edad_vb,edad)) %>%
#set as NA juvenile data which will not be used
mutate(edad_2=ifelse(estadio=="Juvenile",NA,edad_2))%>%
#estimate spawning of combined data
# mutate(desove_2 = ifelse(is.na(edad_2), NA, (fecha-(edad_2+7)))) %>%
mutate(desove_2 =
ifelse(zona=="BB" & !is.na(edad_2), (fecha-(edad_2+7)),
ifelse(zona=="TDF" & !is.na(edad_2), (fecha-(edad_2+5)),NA)))%>%
#change date format
mutate(mes_desove_2 = month(lubridate::as_date(desove_2), label = T)) %>%
droplevels() %>%
#reorder months
mutate(mes_desove_2 = factor(mes_desove_2,
levels=c('sep','oct','nov','dic',
'ene','feb','mar'),
labels=c('sep','oct','nov','dec',
'jan','feb','mar')))
## Plot ----
#number of observations per zone
tallas_des2 %>%
filter(zona %in% c("TDF","BB") &
!is.na(mes_desove_2) &
p_desove!="2013-2014") %>%
group_by(zona) %>%
count()
#plot
tallas_des2 %>%
filter(zona %in% c("TDF","BB") & !is.na(mes_desove_2) & p_desove!="2013-2014") %>%
ggplot(aes(x=mes_desove_2,fill=estadio))+
facet_grid(zona~., scales = "free_x", space = "free_x")+
geom_bar(aes(y=(..count..)/tapply(..count..,..PANEL..,sum)[..PANEL..], position = "stack"))+
scale_fill_viridis(discrete = T, begin = 0, end = 0.8)+
scale_y_continuous(labels = scales::percent,expand = c(0.05,0))+
labs(x="Month of spawning", fill="Developmental stages", y="Spawning frequency (%)")+
theme_bw()+
theme(plot.background = element_rect(fill = "transparent", colour = NA),
panel.grid = element_blank(),
legend.position = "top",
legend.justification = "center",
strip.background = element_blank(),
strip.text = element_text(face = "bold", hjust = 0),
axis.line = element_blank())+
guides(fill=guide_legend(nrow=2, byrow=TRUE))
# Figures 7, 8 and 9. Particle tracking simulations ----
## Simulation results by zone ----
### IE Kh0 ----
#load simulation data
disp_ie0 <- read.csv("ie_kh0.csv", header = T) %>%