Skip to content

Commit

Permalink
add plot_forage_index
Browse files Browse the repository at this point in the history
  • Loading branch information
andybeet committed Oct 24, 2023
1 parent 49077f0 commit 543fc4f
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 1 deletion.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
Date: 2018-10-24

Imports:
dplyr,
magrittr,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export(plot_bottom_temp_anomaly_glorys)
export(plot_bottom_temp_anomaly_space)
export(plot_bottom_temp_anomaly_survey)
export(plot_bottom_temp_anomaly_time)
export(plot_forage_index)
export(plot_sst)
export(plot_sst_anomaly)
export(plot_sst_transition_dates)
Expand Down
113 changes: 113 additions & 0 deletions R/plot_forage_index.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#' plot forage index
#'
#'@param report. Character string. Which SOE report ("G)
#' @param shadedRegion Numeric vector. Years denoting the shaded region of the plot
#' @param shade.fill Character string. Color of shaded region. (Default = "lightgrey)
#' @param shade.alpha Numeric scalar. Alpha of shaded region (Default = 0.5)
#'
#' @return ggplot object
#'
#'
#' @export
#'

plot_forage_index <- function(EPUs="MAB",
shadedRegion=c(2012,2022),
shade.fill="lightgrey",
shade.alpha=0.3) {


x.shade.min <- shadedRegion[1]
x.shade.max <- shadedRegion[2]

if (EPUs == "GB") {
filterEPUs <- c("GOM", "GB")
} else {
filterEPUs <- EPUs
}


fix<- ecodata::forage_index %>%
dplyr::filter(Var %in% c("Fall Forage Fish Biomass Estimate",
"Spring Forage Fish Biomass Estimate"),
EPU %in% filterEPUs) %>%
dplyr::group_by(EPU) %>%
dplyr::summarise(max = max(Value))

p <- ecodata::forage_index %>%
dplyr::filter(Var %in% c("Fall Forage Fish Biomass Estimate",
"Fall Forage Fish Biomass Estimate SE",
"Spring Forage Fish Biomass Estimate",
"Spring Forage Fish Biomass Estimate SE"),
EPU %in% filterEPUs) %>%
dplyr::group_by(EPU) %>%
tidyr::separate(Var, into = c("Season", "A", "B", "C", "D", "Var")) %>%
dplyr::mutate(Var = tidyr::replace_na(Var, "Mean")) %>% #,
#max = as.numeric(Value)) %>%
tidyr::pivot_wider(names_from = Var, values_from = Value) %>%
dplyr::left_join(fix) %>%
dplyr::mutate(#Value = Value/resca,
Mean = as.numeric(Mean),
#max = as.numeric(Value),
Mean = Mean/max,
SE = SE/max,
Upper = Mean + SE,
Lower = Mean - SE) %>%
ggplot2::ggplot(aes(x = Time, y = Mean, group = Season))+
ggplot2::annotate("rect", fill = shade.fill, alpha = shade.alpha,
xmin = x.shade.min , xmax = x.shade.max,
ymin = -Inf, ymax = Inf) +
ggplot2::geom_ribbon(aes(ymin = Lower, ymax = Upper, fill = Season), alpha = 0.5)+
ggplot2::geom_point()+
ggplot2::geom_line()+
ggplot2::ggtitle("")+
ggplot2::ylab(expression("Relative forage biomass"))+
ggplot2::xlab(element_blank())+
ggplot2::facet_wrap(.~EPU)+
ecodata::geom_gls()+
ecodata::theme_ts()+
ecodata::theme_facet()+
ecodata::theme_title()

if (EPUs == "GB") {
p <- p +
ggplot2::theme(legend.position = "bottom",
legend.title = element_blank())

}

return(p)

# ecodata::forage_index %>%
# dplyr::filter(Var %in% c("Fall Forage Fish Biomass Estimate",
# "Fall Forage Fish Biomass Estimate SE",
# "Spring Forage Fish Biomass Estimate",
# "Spring Forage Fish Biomass Estimate SE"),
# EPU == "MAB") %>%
# tidyr::separate(Var, into = c("Season", "A", "B", "C", "D", "Var")) %>%
# dplyr::mutate(Var = replace_na(Var, "Mean"),
# max = as.numeric(resca)) %>%
# tidyr::pivot_wider(names_from = Var, values_from = Value) %>%
# dplyr::mutate(#Value = Value/resca,
# Mean = as.numeric(Mean),
# Mean = Mean/max,
# SE = SE/max,
# Upper = Mean + SE,
# Lower = Mean - SE) %>%
# ggplot2::ggplot(aes(x = Time, y = Mean, group = Season))+
# ggplot2::annotate("rect", fill = shade.fill, alpha = shade.alpha,
# xmin = x.shade.min , xmax = x.shade.max,
# ymin = -Inf, ymax = Inf) +
# ggplot2::geom_ribbon(aes(ymin = Lower, ymax = Upper, fill = Season), alpha = 0.5)+
# ggplot2::geom_point()+
# ggplot2::geom_line()+
# ggplot2::ggtitle("Forage Biomass Index")+
# ggplot2::ylab(expression("Relative forage biomass"))+
# ggplot2::xlab(element_blank())+
# ecodata::geom_gls()+
# ecodata::theme_ts()+
# ecodata::theme_title()
#
#

}
28 changes: 28 additions & 0 deletions man/plot_forage_index.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 543fc4f

Please sign in to comment.