-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathplot_gom_salmon.R
69 lines (58 loc) · 2.32 KB
/
plot_gom_salmon.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
#' plots Gulf of Maine Salmon
#'
#' plots gom_salmon data set
#'
#' @param shadedRegion Numeric vector. Years denoting the shaded region of the plot (most recent 10)
#' @param report Character string. Which SOE report ("MidAtlantic", "NewEngland")
#' @param n Numeric scalar. Number of years used (from most recent year) to estimate short term trend . Default = 0 (No trend calculated)
#'
#' @return ggplot object
#'
#'
#' @export
#'
plot_gom_salmon <- function(shadedRegion = NULL,
report="NewEngland",
n = 0) {
# generate plot setup list (same for all plot functions)
setup <- ecodata::plot_setup(shadedRegion = shadedRegion,
report=report)
# which report? this may be bypassed for some figures
if (report == "MidAtlantic") {
filterEPUs <- c("MAB")
} else {
filterEPUs <- c("GB", "GOM")
}
# optional code to wrangle ecodata object prior to plotting
# e.g., calculate mean, max or other needed values to join below
fix<- ecodata::gom_salmon
# code for generating plot object p
# ensure that setup list objects are called as setup$...
# e.g. fill = setup$shade.fill, alpha = setup$shade.alpha,
# xmin = setup$x.shade.min , xmax = setup$x.shade.max
yaxisLabel <- fix |>
dplyr::distinct(Var,Units)
p <- fix |>
ggplot2::ggplot(ggplot2::aes(x = Time, y = Value))+
ggplot2::annotate("rect", fill = setup$shade.fill, alpha = setup$shade.alpha,
xmin = setup$x.shade.min , xmax = setup$x.shade.max,
ymin = -Inf, ymax = Inf) +
ggplot2::geom_point()+
ggplot2::geom_line()+
ggplot2::facet_wrap(~as.factor(Var),
scales="free_y",
strip.position = "left",
labeller = ggplot2::as_labeller(c(Total = yaxisLabel$Units[yaxisLabel$Var=="Total"], PSAR = yaxisLabel$Units[yaxisLabel$Var=="PSAR"]) ) )+
ggplot2::ggtitle("Atlantic Salmon")+
#ggplot2::ylab()+
ggplot2::xlab(ggplot2::element_blank())+
ggplot2::ylab(ggplot2::element_blank())+
ecodata::geom_gls()+
ecodata::geom_lm(n=n) +
ecodata::theme_ts()+
ecodata::theme_title()+
ggplot2::theme(strip.placement = "outside",
strip.background = ggplot2::element_blank())
return(p)
}
attr(plot_gom_salmon,"report") <- c("MidAtlantic","NewEngland")