diff --git a/NAMESPACE b/NAMESPACE index e8cc6bbc..c08fb1d6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -38,6 +38,7 @@ export(plot_heatwave) export(plot_heatwave_peak_date) export(plot_heatwave_year) export(plot_hms_cpue) +export(plot_hms_landings) export(plot_ichthyo_diversity) export(plot_long_term_sst) export(plot_mab_inshore_survey) diff --git a/R/plot_hms_landings.R b/R/plot_hms_landings.R new file mode 100644 index 00000000..e09500c7 --- /dev/null +++ b/R/plot_hms_landings.R @@ -0,0 +1,114 @@ +#' plot hms_landings +#' +#' Plot time series of Highly Migratory Species (HMS) commercial landings. +#' +#' @param shadedRegion Numeric vector. Years denoting the shaded region of the plot (most recent 10) +#' @param report Character string. Which SOE report ("MidAtlantic", "NewEngland"). +#' HMS landings are by Mid Atlantic or New England, not EPU +#' +#' @return ggplot object +#' +#' +#' @export +#' + +plot_hms_landings <- function(shadedRegion = shadedRegion, + report="MidAtlantic") { + + # 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("NE") + } + + # optional code to wrangle ecodata object prior to plotting + # e.g., calculate mean, max or other needed values to join below + apex<-ecodata::hms_landings |> + dplyr::filter(stringr::str_detect(Var, "Landings")) |> + tidyr::separate(Var, c("Var", "trash"), sep = "_") |> + dplyr::filter(EPU %in% filterEPUs) |> + dplyr::group_by(Var) |> + dplyr::mutate(hline = mean(Value)) + + + # 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 + # + p <- apex |> + ggplot2::ggplot(ggplot2::aes(x = Time, y = Value, color = Var)) + + ggplot2::geom_line(size = setup$lwd) + + ggplot2::geom_point(size = setup$pcex) + + ggplot2::geom_hline(ggplot2::aes(yintercept = hline, + color = Var, + size = Var), + size = setup$hline.size, + alpha = setup$hline.alpha, + linetype = setup$hline.lty)+ + ecodata::theme_facet() + + ggplot2::theme(strip.text=ggplot2::element_text(hjust=0), + legend.position = "bottom", + legend.direction = "horizontal", + legend.title = ggplot2::element_blank())+ + ggplot2::ylab(expression("Landings (metric tons)")) + + ggplot2::xlab("Time")+ + ggplot2::ggtitle(paste("HMS", setup$region, "Commercial Landings"))+ + ecodata::theme_title() + + # # optional code for New England specific (2 panel) formatting + # if (report == "NewEngland") { + # p <- p + + # ggplot2::theme(legend.position = "bottom", + # legend.title = ggplot2::element_blank()) + # + # } + + return(p) + + # Paste commented original plot code chunk for reference + #Get data for plotting + # ## Apex pred + # apex<-ecodata::hms_landings %>% + # dplyr::filter(stringr::str_detect(Var, "Landings")) %>% + # #dplyr::mutate(Value = as.numeric(Value)) %>% + # separate(Var, c("Var", "trash"), sep = "_") #%>% + # #dplyr::filter(!Var == "Smoothhound Sharks") + # + # ##Plot + # p1<-apex %>% + # dplyr::filter(EPU == "NE") %>% + # dplyr::group_by(Var) %>% + # dplyr::mutate(hline = mean(Value)) %>% + # + # ggplot2::ggplot(aes(x = Time, y = Value, color = Var)) + + # ggplot2::annotate("rect", fill = shade.fill, alpha = shade.alpha, + # xmin = x.shade.min , xmax = x.shade.max, + # ymin = -Inf, ymax = Inf) + + # ggplot2::geom_line(size = lwd) + + # ggplot2::geom_point(size = pcex) + + # # ggplot2::geom_hline(aes(yintercept = hline, + # # color = Var, + # # size = Var), + # # size = hline.size, + # # alpha = hline.alpha, + # # linetype = hline.lty)+ + # ecodata::theme_facet() + + # ggplot2::theme(strip.text=element_text(hjust=0), + # legend.position = "bottom", + # legend.direction = "horizontal", + # legend.title = element_blank())+ + # ggplot2::ylab("Landings (metric tons)")+ + # ggplot2::ggtitle("HMS Commercial Landings") + # ggplot2::xlab(element_blank())+ + # ecodata::theme_title() + # + # p1 + # + +} diff --git a/man/plot_hms_landings.Rd b/man/plot_hms_landings.Rd new file mode 100644 index 00000000..a77dd975 --- /dev/null +++ b/man/plot_hms_landings.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plot_hms_landings.R +\name{plot_hms_landings} +\alias{plot_hms_landings} +\title{plot hms_landings} +\usage{ +plot_hms_landings(shadedRegion = shadedRegion, report = "MidAtlantic") +} +\arguments{ +\item{shadedRegion}{Numeric vector. Years denoting the shaded region of the plot (most recent 10)} + +\item{report}{Character string. Which SOE report ("MidAtlantic", "NewEngland"). +HMS landings are by Mid Atlantic or New England, not EPU} +} +\value{ +ggplot object +} +\description{ +Plot time series of Highly Migratory Species (HMS) commercial landings. +}