Skip to content

Commit

Permalink
Merge pull request #182 from NOAA-EDAB/andy_newplots
Browse files Browse the repository at this point in the history
New index plots + chl_pp
  • Loading branch information
BBeltz1 authored Dec 30, 2024
2 parents 8222238 + 7a6e676 commit aaaae6a
Show file tree
Hide file tree
Showing 28 changed files with 556 additions and 154 deletions.
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export(plot_aggregate_biomass)
export(plot_annual_chl_pp)
export(plot_aquaculture)
export(plot_bennet)
export(plot_benthos_index)
export(plot_blue_runner)
export(plot_bottom_temp_glorys)
export(plot_bottom_temp_insitu)
Expand Down Expand Up @@ -54,7 +55,6 @@ export(plot_nao)
export(plot_narw)
export(plot_ne_inshore_survey)
export(plot_observed_sharks)
export(plot_phyto_size)
export(plot_ppr)
export(plot_productivity_anomaly)
export(plot_rec_hms)
Expand Down Expand Up @@ -88,6 +88,7 @@ export(plot_zoo_abundance_anom)
export(plot_zoo_diversity)
export(plot_zoo_regime)
export(plot_zoo_strat_abun)
export(plot_zooplankton_index)
export(theme_facet)
export(theme_map)
export(theme_title)
Expand Down
17 changes: 17 additions & 0 deletions R/benthos_index.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#' Benthos Index
#'
#' Data include Megabenthos and Macrobenthos biomass and center of gravity indices from predator diet data from NEFSC bottom trawl survey.
#'
#'
#' @format n rows and 5 columns.
#'
#' \itemize{
#' \item Value: Value of variable \code{Var}.
#' \item Var: Variable calculated.
#' \item Time: Year.
#' \item EPU: Ecological Production Unit (EPU) where sampling occurred.
#' \item Units: grams per stomach.
#' }
#'
#' @details Methods used to calculate data are available at \url{https://noaa-edab.github.io/tech-doc/benthos_index.html}.
"benthos_index"
4 changes: 2 additions & 2 deletions R/chl_pp.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Chlorophyll \emph{a} and primary production
#' Chlorophyll \emph{a} and primary production and phytoplankton size class
#'
#' These data are time series of remotely sensed chlorophyll \emph{a} (CHL) and primary production (PP) data from the Northeast Continental Shelf.
#' Included are median and anomaly CHL and PP estimates for Ecological Production Units, along with subsets for CHL and PP by
Expand All @@ -17,7 +17,7 @@
#' \item EPU: Ecological Production Unit (EPU) where sampling occurred.
#' }
#'
#' @details Methods used to calculate median and anomaly data are available at \url{https://noaa-edab.github.io/tech-doc/chl-pp.html}. Methods
#' @details Methods used to calculate median and anomaly data are available at \url{https://noaa-edab.github.io/tech-doc/chl_pp.html}. Methods
#' used to find phytoplankton size-class information are forthcoming.
#'
"chl_pp"
2 changes: 1 addition & 1 deletion R/forage_index.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
#' \item Units: grams per stomach.
#' }
#'
#' @details Methods used to calculate data are available at \url{https://noaa-edab.github.io/tech-doc/forage-fish-biomass-indices.html}.
#' @details Methods used to calculate data are available at \url{https://noaa-edab.github.io/tech-doc/forage_index.html}.
"forage_index"
17 changes: 0 additions & 17 deletions R/phyto_size.R

This file was deleted.

3 changes: 1 addition & 2 deletions R/plot_aggregate_biomass.R
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ plot_aggregate_biomass <- function(shadedRegion = NULL,

### Planktivore
p3<-agg_bio |>
dplyr::filter(stringr::str_detect(Var,"Planktivore"),
Time <= 2023) |>
dplyr::filter(stringr::str_detect(Var,"Planktivore")) |>
dplyr::mutate(Mean = dplyr::case_when(Mean >80 ~ 90,
TRUE ~ Mean)) |>

Expand Down
134 changes: 134 additions & 0 deletions R/plot_benthos_index.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#' plot benthos index
#'
#' Description should be here. This needs to be reworked to uncouple GB and GOM
#'
#' @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 varName Character string. Benthos group name ("Macrobenthos", "Megabenthos")
#' @param plottype Character string. Benthos biomass index by region, or coastwide center of gravity ("index", "cog")
#' @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_benthos_index <- function(shadedRegion = NULL,
report="MidAtlantic",
varName = "Macrobenthos",
plottype = "index",
n = 0) {

setup <- ecodata::plot_setup(shadedRegion = shadedRegion,
report=report)

# convert to leading capital
varName <- stringr::str_to_sentence(varName)
if (!(varName %in% c("Megabenthos","Macrobenthos"))){
stop("varName should be either Megabenthos or Macrobenthos")
}


if (plottype == "index") {

if (report == "MidAtlantic") {
filterEPUs <- c("MAB")
} else {
filterEPUs <- c("GB", "GOM")
}

fix<- ecodata::benthos_index |>
dplyr::filter(Var %in% c(paste("Fall",varName,"Biomass Index Estimate"),
paste("Spring",varName,"Megabenthos Biomass Index Estimate")),
EPU %in% filterEPUs) |>
dplyr::group_by(EPU) |>
dplyr::summarise(max = max(Value))

p <- ecodata::benthos_index |>
dplyr::filter(Var %in% c(paste("Fall",varName,"Biomass Index Estimate"),
paste("Fall",varName,"Biomass Index Estimate SE"),
paste("Spring",varName,"Biomass Index Estimate"),
paste("Spring",varName,"Biomass Index 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(ggplot2::aes(x = Time, y = Mean, group = Season))+
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_ribbon(ggplot2::aes(ymin = Lower, ymax = Upper, fill = Season), alpha = 0.5)+
ggplot2::geom_point()+
ggplot2::geom_line()+
ggplot2::ggtitle("")+
ggplot2::ylab(paste("Relative",varName,"Biomass"))+
ggplot2::xlab(ggplot2::element_blank())+
ggplot2::facet_wrap(.~EPU)+
ecodata::geom_gls()+
ecodata::geom_lm(n=n)+
ecodata::theme_ts()+
ecodata::theme_facet()+
ecodata::theme_title()

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

}
}

if (plottype == "cog"){

p <- ecodata::benthos_index |>
dplyr::filter(Var %in% c(paste("Fall",varName,"Eastward Center of Gravity"),
paste("Fall",varName,"Eastward Center of Gravity SE"),
paste("Fall",varName,"Northward Center of Gravity"),
paste("Fall",varName,"Northward Center of Gravity SE"),
paste("Spring",varName,"Eastward Center of Gravity"),
paste("Spring",varName,"Eastward Center of Gravity SE"),
paste("Spring",varName,"Northward Center of Gravity"),
paste("Spring",varName,"Northward Center of Gravity SE"))) |>
tidyr::separate(Var, into = c("Season", "A", "Direction", "B", "C", "D", "Var")) |>
dplyr::mutate(Var = tidyr::replace_na(Var, "Mean")) |>
tidyr::pivot_wider(names_from = Var, values_from = Value) |>
dplyr::mutate(Mean = as.numeric(Mean),
Upper = Mean + SE,
Lower = Mean - SE) |>
ggplot2::ggplot(ggplot2::aes(x = Time, y = Mean, group = Season))+
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_ribbon(ggplot2::aes(ymin = Lower, ymax = Upper, fill = Season), alpha = 0.3)+ #
ggplot2::geom_point()+
ggplot2::geom_line()+
ggplot2::ggtitle("")+
ggplot2::ylab(paste(varName," Center of Gravity, km"))+
ggplot2::xlab(ggplot2::element_blank())+
ggplot2::facet_wrap(~Direction, scales = "free_y")+ #Season
ecodata::geom_gls()+
ecodata::geom_lm(n=n)+
ecodata::theme_ts()+
ecodata::theme_facet()+
ecodata::theme_title()

}

return(p)

}

attr(plot_benthos_index,"report") <- c("MidAtlantic","NewEngland")
attr(plot_benthos_index, "varName") <- c("Microbenthos", "Macrobenthos")
attr(plot_benthos_index, "plottype") <- c("index", "cog")
Loading

0 comments on commit aaaae6a

Please sign in to comment.