-
Notifications
You must be signed in to change notification settings - Fork 0
/
SOE-VASTBenthosIndices.R
87 lines (68 loc) · 3.19 KB
/
SOE-VASTBenthosIndices.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
# create rds for ecodata input
# aim for similar structure to other ecodata datasets
library(dplyr)
library(ggplot2)
library(tidyr)
SOEinputs <- function(infile, season, taxa, outfile) {
splitoutput <- read.csv(infile)
# warning, hardcoded. obviously
stratlook <- data.frame(Stratum = c("Stratum_1",
"Stratum_2",
"Stratum_3",
"Stratum_4",
"Stratum_5"),
Region = c("AllEPU",
"MAB",
"GB",
"GOM",
"SS"))
benthosindex <- splitoutput %>%
left_join(stratlook) %>%
dplyr::select(Time,
EPU = Region,
"Biomass Index Estimate" = Estimate,
"Biomass Index Estimate SE" = Std..Error.for.Estimate) %>%
tidyr::pivot_longer(c("Biomass Index Estimate", "Biomass Index Estimate SE"),
names_to = "Var", values_to = "Value") %>%
dplyr::filter(EPU %in% c("MAB", "GB", "GOM", "AllEPU")) %>%
dplyr::mutate(Units = "relative grams per stomach") %>%
dplyr::select(Time, Var, Value, EPU, Units)
benthosindex$Var <- stringr::str_c(season, taxa, benthosindex$Var, sep = " ")
saveRDS(benthosindex, outfile)
}
# make data files
SOEinputs(infile = "pyindex/macrobenthos_fall_500_cov/Index.csv",
season = "Fall",
taxa = "Macrobenthos",
outfile = "pyindex/fallmacrobenthosindex.rds")
SOEinputs(infile = "pyindex/macrobenthos_spring_500_cov/Index.csv",
season = "Spring",
taxa = "Macrobenthos",
outfile = "pyindex/springmacrobenthosindex.rds")
SOEinputs(infile = "pyindex/megabenthos_fall_500_cov/Index.csv",
season = "Fall",
taxa = "Megabenthos",
outfile = "pyindex/fallmegabenthosindex.rds")
SOEinputs(infile = "pyindex/megabenthos_spring_500_cov/Index.csv",
season = "Spring",
taxa = "Megabenthos",
outfile = "pyindex/springmegabenthosindex.rds")
# test plot
# foragewide <- forageindex %>%
# pivot_wider(names_from = Var, values_from = Value)
#
#
# ggplot(foragewide, aes(x=Time, y=`Forage Fish Biomass Estimate`, colour = EPU)) +
# geom_errorbar(aes(ymin=`Forage Fish Biomass Estimate`+`Forage Fish Biomass Estimate SE`,
# ymax=`Forage Fish Biomass Estimate`-`Forage Fish Biomass Estimate SE`))+
# geom_point()+
# geom_line()
macrowide <- fallmacrobenthosindex |> tidyr::pivot_wider(names_from = Var, values_from = Value)
ggplot2::ggplot(macrowide, ggplot2::aes(x=Time, y=`Fall Macrobenthos Biomass Index Estimate`, colour=EPU)) +
ggplot2::geom_ribbon(ggplot2::aes(ymin=`Fall Macrobenthos Biomass Index Estimate`-`Fall Macrobenthos Biomass Index Estimate SE`,
ymax=`Fall Macrobenthos Biomass Index Estimate`+`Fall Macrobenthos Biomass Index Estimate SE`,
fill=EPU),
alpha=0.5)+
ggplot2::geom_point()+
ggplot2::geom_line() #+
#ggplot2::facet_wrap(~EPU)