From a2e714ce24defcd9327f792b7ab6920a04cbec43 Mon Sep 17 00:00:00 2001 From: Sam Schiano <125507018+Schiano-NOAA@users.noreply.github.com> Date: Wed, 7 Oct 2026 15:08:02 -0400 Subject: [PATCH 1/8] make adjustments so unit_label is extracted from dat and remove lbs as argument; adjust yaxis label to fix logic --- R/plot_spawning_biomass.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/plot_spawning_biomass.R b/R/plot_spawning_biomass.R index f5c21dfc..91b3cb80 100644 --- a/R/plot_spawning_biomass.R +++ b/R/plot_spawning_biomass.R @@ -141,7 +141,6 @@ plot_spawning_biomass <- function( ) { check_data(dat) - # TODO: start deprecation procedure for argument lbs if (relative & scale_amount > 1) { cli::cli_alert_warning("Scale amount is not applicable when relative = TRUE. Resetting scale_amount to 1.") scale_amount <- 1 From c4ef6e6d834f9648a203f2002cdb746b3281be18 Mon Sep 17 00:00:00 2001 From: Sam Schiano <125507018+Schiano-NOAA@users.noreply.github.com> Date: Wed, 7 Oct 2026 15:10:35 -0400 Subject: [PATCH 2/8] update documentation --- man/plot_spawning_biomass.Rd | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/man/plot_spawning_biomass.Rd b/man/plot_spawning_biomass.Rd index ab616183..d5665ffc 100644 --- a/man/plot_spawning_biomass.Rd +++ b/man/plot_spawning_biomass.Rd @@ -61,11 +61,19 @@ Default: "msy" Options: (including, but not limited to) "target", "msy", and "unfished" If the reference point is not found in the data, set ref_line = c("name" = value).} +<<<<<<< HEAD \item{unit_label}{String. Spawning biomass unit as indicated from the data. When setting a unit of pounds please use one of the following keywords: "lbs", "pounds", "lb". For example "1000s of lbs" would still be recognized as pounds. Do not set unit_label to the desired order of magnitude, rather the unit label reflected in the data. Please refer to the argument \code{scale_amount}. +======= +\item{unit_label}{String. Spawning biomass unit as indicated from the data. +When setting a unit of pounds please use one of the following keywords: +"lbs", "pounds", "lb". For example "1000s of lbs" would still be recognized +as pounds. Do not set unit label to the desired order of magnitude rather the +unit label reflected in the data. Please refer to the argument `scale_amount`. +>>>>>>> ccdf8a1 (update documentation) Default: NULL} @@ -75,7 +83,11 @@ Default: "time" Options: "early", "time", "fore" (forecast), or NULL (all data)} +<<<<<<< HEAD \item{lbs}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Logical. TRUE/FALSE; indicate whether to convert the y-axis values from +======= +\item{lbs}{`r lifecycle::badge('deprecated')` Logical. TRUE/FALSE; indicate whether to convert the y-axis values from +>>>>>>> ccdf8a1 (update documentation) kilograms to pounds. The default units match the default in the unit_label argument - 'mt'. -- Deprecate From 2d690cf0a95904cd54db6d25c10ce65dff0f60e6 Mon Sep 17 00:00:00 2001 From: Sam Schiano <125507018+Schiano-NOAA@users.noreply.github.com> Date: Thu, 22 Oct 2026 11:02:41 -0400 Subject: [PATCH 3/8] update man impacted by plot_sb change --- man/plot_spawning_biomass.Rd | 12 --- man/plot_spawning_potential_ratio.Rd | 128 +++++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 12 deletions(-) create mode 100644 man/plot_spawning_potential_ratio.Rd diff --git a/man/plot_spawning_biomass.Rd b/man/plot_spawning_biomass.Rd index d5665ffc..ab616183 100644 --- a/man/plot_spawning_biomass.Rd +++ b/man/plot_spawning_biomass.Rd @@ -61,19 +61,11 @@ Default: "msy" Options: (including, but not limited to) "target", "msy", and "unfished" If the reference point is not found in the data, set ref_line = c("name" = value).} -<<<<<<< HEAD \item{unit_label}{String. Spawning biomass unit as indicated from the data. When setting a unit of pounds please use one of the following keywords: "lbs", "pounds", "lb". For example "1000s of lbs" would still be recognized as pounds. Do not set unit_label to the desired order of magnitude, rather the unit label reflected in the data. Please refer to the argument \code{scale_amount}. -======= -\item{unit_label}{String. Spawning biomass unit as indicated from the data. -When setting a unit of pounds please use one of the following keywords: -"lbs", "pounds", "lb". For example "1000s of lbs" would still be recognized -as pounds. Do not set unit label to the desired order of magnitude rather the -unit label reflected in the data. Please refer to the argument `scale_amount`. ->>>>>>> ccdf8a1 (update documentation) Default: NULL} @@ -83,11 +75,7 @@ Default: "time" Options: "early", "time", "fore" (forecast), or NULL (all data)} -<<<<<<< HEAD \item{lbs}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Logical. TRUE/FALSE; indicate whether to convert the y-axis values from -======= -\item{lbs}{`r lifecycle::badge('deprecated')` Logical. TRUE/FALSE; indicate whether to convert the y-axis values from ->>>>>>> ccdf8a1 (update documentation) kilograms to pounds. The default units match the default in the unit_label argument - 'mt'. -- Deprecate diff --git a/man/plot_spawning_potential_ratio.Rd b/man/plot_spawning_potential_ratio.Rd new file mode 100644 index 00000000..a424822d --- /dev/null +++ b/man/plot_spawning_potential_ratio.Rd @@ -0,0 +1,128 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plot_spr.R +\name{plot_spawning_potential_ratio} +\alias{plot_spawning_potential_ratio} +\title{Plot spawning potential ratio (SPR)} +\usage{ +plot_spawning_potential_ratio( + dat, + geom = "line", + group = NULL, + facet = NULL, + ref_line = "target", + era = "time", + module = NULL, + interactive = TRUE, + make_rda = FALSE, + figures_dir = getwd(), + ylab = NULL, + ... +) +} +\arguments{ +\item{dat}{Data frame or list. A tibble or named list of tibbles (input as \code{list()}) +returned from \link[stockplotr]{convert_output}. + +If inputting a list of tibbles, the first tibble's reference point defined +in \code{ref_line} is used to plot a reference line or calculate relative spawning biomass.} + +\item{geom}{String. Geom used for the plot. + +Default: "line". + +Options: "line", "point", or "area"} + +\item{group}{String. Single column that groups the data. + +Set group = "none" to summarize data over all indexing values. + +Default: NULL +Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", NULL} + +\item{facet}{Character vector. Column name or names used for faceting. + +Default: NULL} + +\item{ref_line}{String or named vector. Reference point name (and value if +custom). When multiple models are being compared, a reference line for each +model will appear, if desired. The following options can be used to customize +the reference line: +\enumerate{ +\item all lines are comparing same ref_line = "msy", ref_line = "target", ref_line = "unfished", etc +\item custom input vector - ref_line = c("sable23_msy"=30, "sable25_msy"=40) -- user must indicate which model in label otherwise it will assign in order of dat +\item input vector of labels - ref_line = c("msy", "target") +} + +Default: "msy" + +Options: (including, but not limited to) "target", "msy", and "unfished" +If the reference point is not found in the data, set ref_line = c("name" = value).} + +\item{era}{String. Era of data. + +Default: "time" + +Options: "early", "time", "fore" (forecast), or NULL (all data)} + +\item{module}{Character vector. (Optional) Module name found in \code{dat$module_name}. +If selecting >1 module, place them in a vector like c("module1", "module2"). + +Default: NULL + +If the interactive and >1 module_name is found, user will select the +module_name in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + +\item{interactive}{Logical. TRUE/FALSE; indicate whether the environment is interactive. + +Default: \code{FALSE}} + +\item{make_rda}{Logical. TRUE/FALSE; indicate whether to save the object and +make an automated caption and alternative text in the form of an \code{rda} object. If TRUE, +the rda will be exported to the folder indicated in the argument "figures_dir". + +Default: \code{FALSE}.} + +\item{figures_dir}{Path. Path to the "figures" folder. + +Default: \code{getwd()} + +The folder is created within the path if it does not exist.} + +\item{ylab}{String. Y-axis label to show.} + +\item{...}{Arguments called from \link[ggplot2]{geom_line} or \link[ggplot2]{geom_point}} +} +\value{ +A plot showing spawning potential ratio (SPR). +} +\description{ +Plot spawning potential ratio (SPR) +} +\details{ +The input is from an assessment model output file +translated to a standardized output (\link[stockplotr]{convert_output}). +There are options to return a \code{ggplot2} object or export an .rda object +containing associated caption and alternative text for the figure. +} +\examples{ +plot_spawning_potential_ratio( + dat = stockplotr:::example_data, + unit_label = "metric tons", + group = "fleet", + interactive = FALSE, + make_rda = FALSE, + ylab = "SPR" +) +plot_spawning_potential_ratio( + dat = stockplotr:::example_data, + unit_label = "metric tons", + facet = "fleet", + module = "DERIVED_QUANTITIES", + interactive = FALSE, + make_rda = FALSE, + ylab = "(1-SPR)/(1-SPR_ref)" +) +} +\seealso{ +\code{\link[=convert_output]{convert_output()}}, \code{\link[=filter_data]{filter_data()}}, \code{\link[=process_data]{process_data()}}, \code{\link[=plot_timeseries]{plot_timeseries()}}, \code{\link[=export_kqs]{export_kqs()}}, \code{\link[=insert_kqs]{insert_kqs()}}, \code{\link[=create_rda]{create_rda()}} +} From 23ad410a3a219aedd5d08a18d97ab3eec8586539 Mon Sep 17 00:00:00 2001 From: "Sam (Schiano) Bredeck" <125507018+Schiano-NOAA@users.noreply.github.com> Date: Wed, 28 Oct 2026 14:55:30 -0400 Subject: [PATCH 4/8] [refactor]: add units into "at-age" plots (#434) * add change to units for aa plots to extract unit from std output * update man * add warning message if unit label not found --- R/plot_catch_at_age.R | 1 + man/plot_catch_at_age.Rd | 1 + 2 files changed, 2 insertions(+) diff --git a/R/plot_catch_at_age.R b/R/plot_catch_at_age.R index 11374f6e..49e311b4 100644 --- a/R/plot_catch_at_age.R +++ b/R/plot_catch_at_age.R @@ -50,6 +50,7 @@ #' dat = stockplotr::example_data, #' facet = "fleet", #' unit_label = "fish", +#' facet = "fleet", #' scale_amount = 100, #' interactive = FALSE, #' make_rda = FALSE, diff --git a/man/plot_catch_at_age.Rd b/man/plot_catch_at_age.Rd index 296e36aa..2dd93fff 100644 --- a/man/plot_catch_at_age.Rd +++ b/man/plot_catch_at_age.Rd @@ -96,6 +96,7 @@ plot_catch_at_age( dat = stockplotr::example_data, facet = "fleet", unit_label = "fish", + facet = "fleet", scale_amount = 100, interactive = FALSE, make_rda = FALSE, From 836684a7208049f3a0df4416d479de5b84ecf67e Mon Sep 17 00:00:00 2001 From: Sam Schiano <125507018+Schiano-NOAA@users.noreply.github.com> Date: Fri, 6 Nov 2026 17:41:20 -0500 Subject: [PATCH 5/8] fix documentaiton --- man/plot_spawning_potential_ratio.Rd | 128 --------------------------- 1 file changed, 128 deletions(-) delete mode 100644 man/plot_spawning_potential_ratio.Rd diff --git a/man/plot_spawning_potential_ratio.Rd b/man/plot_spawning_potential_ratio.Rd deleted file mode 100644 index a424822d..00000000 --- a/man/plot_spawning_potential_ratio.Rd +++ /dev/null @@ -1,128 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/plot_spr.R -\name{plot_spawning_potential_ratio} -\alias{plot_spawning_potential_ratio} -\title{Plot spawning potential ratio (SPR)} -\usage{ -plot_spawning_potential_ratio( - dat, - geom = "line", - group = NULL, - facet = NULL, - ref_line = "target", - era = "time", - module = NULL, - interactive = TRUE, - make_rda = FALSE, - figures_dir = getwd(), - ylab = NULL, - ... -) -} -\arguments{ -\item{dat}{Data frame or list. A tibble or named list of tibbles (input as \code{list()}) -returned from \link[stockplotr]{convert_output}. - -If inputting a list of tibbles, the first tibble's reference point defined -in \code{ref_line} is used to plot a reference line or calculate relative spawning biomass.} - -\item{geom}{String. Geom used for the plot. - -Default: "line". - -Options: "line", "point", or "area"} - -\item{group}{String. Single column that groups the data. - -Set group = "none" to summarize data over all indexing values. - -Default: NULL -Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", NULL} - -\item{facet}{Character vector. Column name or names used for faceting. - -Default: NULL} - -\item{ref_line}{String or named vector. Reference point name (and value if -custom). When multiple models are being compared, a reference line for each -model will appear, if desired. The following options can be used to customize -the reference line: -\enumerate{ -\item all lines are comparing same ref_line = "msy", ref_line = "target", ref_line = "unfished", etc -\item custom input vector - ref_line = c("sable23_msy"=30, "sable25_msy"=40) -- user must indicate which model in label otherwise it will assign in order of dat -\item input vector of labels - ref_line = c("msy", "target") -} - -Default: "msy" - -Options: (including, but not limited to) "target", "msy", and "unfished" -If the reference point is not found in the data, set ref_line = c("name" = value).} - -\item{era}{String. Era of data. - -Default: "time" - -Options: "early", "time", "fore" (forecast), or NULL (all data)} - -\item{module}{Character vector. (Optional) Module name found in \code{dat$module_name}. -If selecting >1 module, place them in a vector like c("module1", "module2"). - -Default: NULL - -If the interactive and >1 module_name is found, user will select the -module_name in the console. @seealso \code{\link[=filter_data]{filter_data()}}} - -\item{interactive}{Logical. TRUE/FALSE; indicate whether the environment is interactive. - -Default: \code{FALSE}} - -\item{make_rda}{Logical. TRUE/FALSE; indicate whether to save the object and -make an automated caption and alternative text in the form of an \code{rda} object. If TRUE, -the rda will be exported to the folder indicated in the argument "figures_dir". - -Default: \code{FALSE}.} - -\item{figures_dir}{Path. Path to the "figures" folder. - -Default: \code{getwd()} - -The folder is created within the path if it does not exist.} - -\item{ylab}{String. Y-axis label to show.} - -\item{...}{Arguments called from \link[ggplot2]{geom_line} or \link[ggplot2]{geom_point}} -} -\value{ -A plot showing spawning potential ratio (SPR). -} -\description{ -Plot spawning potential ratio (SPR) -} -\details{ -The input is from an assessment model output file -translated to a standardized output (\link[stockplotr]{convert_output}). -There are options to return a \code{ggplot2} object or export an .rda object -containing associated caption and alternative text for the figure. -} -\examples{ -plot_spawning_potential_ratio( - dat = stockplotr:::example_data, - unit_label = "metric tons", - group = "fleet", - interactive = FALSE, - make_rda = FALSE, - ylab = "SPR" -) -plot_spawning_potential_ratio( - dat = stockplotr:::example_data, - unit_label = "metric tons", - facet = "fleet", - module = "DERIVED_QUANTITIES", - interactive = FALSE, - make_rda = FALSE, - ylab = "(1-SPR)/(1-SPR_ref)" -) -} -\seealso{ -\code{\link[=convert_output]{convert_output()}}, \code{\link[=filter_data]{filter_data()}}, \code{\link[=process_data]{process_data()}}, \code{\link[=plot_timeseries]{plot_timeseries()}}, \code{\link[=export_kqs]{export_kqs()}}, \code{\link[=insert_kqs]{insert_kqs()}}, \code{\link[=create_rda]{create_rda()}} -} From 021156f38ab56c0e24b07036e12c4bb60ee7370f Mon Sep 17 00:00:00 2001 From: sbreitbart-NOAA Date: Wed, 11 Nov 2026 11:33:58 -0500 Subject: [PATCH 6/8] update total catch doc --- man/table_total_catch.Rd | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/man/table_total_catch.Rd b/man/table_total_catch.Rd index 25f6c5ce..5026642f 100644 --- a/man/table_total_catch.Rd +++ b/man/table_total_catch.Rd @@ -6,7 +6,7 @@ \usage{ table_total_catch( dat, - unit_label = "mt", + unit_label = NULL, era = NULL, interactive = TRUE, module = NULL, @@ -25,7 +25,7 @@ in \code{ref_line} is used to plot a reference line or calculate relative spawni \item{unit_label}{String. Abbreviated catch units -Default: "mt"} +Default: NULL} \item{era}{String. Era of data. @@ -81,7 +81,8 @@ There are options to return a \code{\link[gt:gt]{gt::gt()}} object or export an containing a gt-based table, caption, and LaTeX-based table. } \examples{ -table_total_catch(stockplotr::example_data, +table_total_catch( + stockplotr::example_data, module = "TIME_SERIES" ) From 234079017f63ca8a60413021551243b2484adaa0 Mon Sep 17 00:00:00 2001 From: sbreitbart-NOAA Date: Wed, 11 Nov 2026 11:50:30 -0500 Subject: [PATCH 7/8] Update documentation for AAA, BAA, CAA plots --- R/plot_abundance_at_age.R | 2 +- R/plot_catch_at_age.R | 3 +-- man/plot_abundance_at_age.Rd | 2 +- man/plot_biomass_at_age.Rd | 2 +- man/plot_catch_at_age.Rd | 3 +-- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/R/plot_abundance_at_age.R b/R/plot_abundance_at_age.R index 8c8d0e9f..485eac8e 100644 --- a/R/plot_abundance_at_age.R +++ b/R/plot_abundance_at_age.R @@ -11,7 +11,7 @@ #' #' @param unit_label String. Abundance units #' -#' Default: "fish" +#' Default: NULL #' #' @param scale_amount Number. A number describing how much to scale down the abundance at #' age. Please choose a value ranging from 1-1,000,000,000 (one billion) in orders diff --git a/R/plot_catch_at_age.R b/R/plot_catch_at_age.R index 49e311b4..574bdf46 100644 --- a/R/plot_catch_at_age.R +++ b/R/plot_catch_at_age.R @@ -3,7 +3,7 @@ #' @inheritParams plot_abundance_at_age #' @param unit_label String. Units of catch used to label the axis #' -#' Default: "mt" +#' Default: NULL #' #' @param scale_amount Number. A number describing how much to scale down the catch at #' age. Please choose a value ranging from 1-1,000,000,000 (one billion) in orders @@ -50,7 +50,6 @@ #' dat = stockplotr::example_data, #' facet = "fleet", #' unit_label = "fish", -#' facet = "fleet", #' scale_amount = 100, #' interactive = FALSE, #' make_rda = FALSE, diff --git a/man/plot_abundance_at_age.Rd b/man/plot_abundance_at_age.Rd index 62bef3a3..3dd4ff31 100644 --- a/man/plot_abundance_at_age.Rd +++ b/man/plot_abundance_at_age.Rd @@ -29,7 +29,7 @@ NULL} \item{unit_label}{String. Abundance units -Default: "fish"} +Default: NULL} \item{scale_amount}{Number. A number describing how much to scale down the abundance at age. Please choose a value ranging from 1-1,000,000,000 (one billion) in orders diff --git a/man/plot_biomass_at_age.Rd b/man/plot_biomass_at_age.Rd index 54fce339..66e19b6d 100644 --- a/man/plot_biomass_at_age.Rd +++ b/man/plot_biomass_at_age.Rd @@ -29,7 +29,7 @@ NULL} \item{unit_label}{String. Abundance units -Default: "fish"} +Default: NULL} \item{scale_amount}{Number. A number describing how much to scale down the biomass at age. For example, scale_amount = 100 would scale down a value diff --git a/man/plot_catch_at_age.Rd b/man/plot_catch_at_age.Rd index 2dd93fff..8044bc76 100644 --- a/man/plot_catch_at_age.Rd +++ b/man/plot_catch_at_age.Rd @@ -36,7 +36,7 @@ Options: "early", "time", "fore" (forecast), or NULL (all data)} \item{unit_label}{String. Units of catch used to label the axis -Default: "mt"} +Default: NULL} \item{scale_amount}{Number. A number describing how much to scale down the catch at age. Please choose a value ranging from 1-1,000,000,000 (one billion) in orders @@ -96,7 +96,6 @@ plot_catch_at_age( dat = stockplotr::example_data, facet = "fleet", unit_label = "fish", - facet = "fleet", scale_amount = 100, interactive = FALSE, make_rda = FALSE, From b58503f5ca3c8fca8aad84a8e9dea2ee05e80735 Mon Sep 17 00:00:00 2001 From: sbreitbart-NOAA Date: Wed, 11 Nov 2026 12:12:18 -0500 Subject: [PATCH 8/8] Update documentation; ensure selected_module removed from R env after plot finishes; update plot_landings()' unit_label to filter when multiple options present --- R/plot_abundance_at_age.R | 5 +++ R/plot_biomass.R | 8 ++--- R/plot_biomass_at_age.R | 5 +++ R/plot_catch_at_age.R | 7 ++++- R/plot_discard.R | 6 +++- R/plot_fishing_mortality.R | 9 +++--- R/plot_index.R | 8 +++-- R/plot_landings.R | 62 +++++++++++++++++++++----------------- R/plot_natural_mortality.R | 6 +++- man/plot_biomass.Rd | 2 +- man/plot_index.Rd | 2 +- 11 files changed, 77 insertions(+), 43 deletions(-) diff --git a/R/plot_abundance_at_age.R b/R/plot_abundance_at_age.R index 485eac8e..22f7e7b7 100644 --- a/R/plot_abundance_at_age.R +++ b/R/plot_abundance_at_age.R @@ -199,5 +199,10 @@ plot_abundance_at_age <- function( dat ) } + + if (exists("selected_module")) { + rm(selected_module, envir = .GlobalEnv) + } + plot } diff --git a/R/plot_biomass.R b/R/plot_biomass.R index 6595b8a4..ac8570bc 100644 --- a/R/plot_biomass.R +++ b/R/plot_biomass.R @@ -3,7 +3,7 @@ #' @inheritParams plot_spawning_biomass #' @param unit_label String. Biomass units #' -#' Default: "mt" +#' Default: NULL #' @param ref_line String. Type of reference point to #' compare biomass to. The default `"msy"` looks for #' `"biomass_msy"` in the `"label"` column of `dat`. The actual @@ -337,10 +337,10 @@ plot_biomass <- function( ) } - # remove global variable "selected_module" - if (exists("selected_module", envir = .GlobalEnv)) rm("selected_module", envir = .GlobalEnv) + if (exists("selected_module")) { + rm(selected_module, envir = .GlobalEnv) + } - # Output final plot final } diff --git a/R/plot_biomass_at_age.R b/R/plot_biomass_at_age.R index 58e3dbd6..1b9cd130 100644 --- a/R/plot_biomass_at_age.R +++ b/R/plot_biomass_at_age.R @@ -165,5 +165,10 @@ plot_biomass_at_age <- function( dat ) } + + if (exists("selected_module")) { + rm(selected_module, envir = .GlobalEnv) + } + plot } diff --git a/R/plot_catch_at_age.R b/R/plot_catch_at_age.R index 574bdf46..4917c45d 100644 --- a/R/plot_catch_at_age.R +++ b/R/plot_catch_at_age.R @@ -183,9 +183,14 @@ plot_catch_at_age <- function( # get name of function and remove "plot_" from it topic_label = gsub("plot_", "", utils::tail(as.character(sys.call()[[1]]), n = 1)), fig_or_table = "figure", - dir=figures_dir, + dir = figures_dir, dat ) } + + if (exists("selected_module")) { + rm(selected_module, envir = .GlobalEnv) + } + plot } diff --git a/R/plot_discard.R b/R/plot_discard.R index 796cbe6c..689bd45b 100644 --- a/R/plot_discard.R +++ b/R/plot_discard.R @@ -162,6 +162,10 @@ plot_discard <- function( scale_amount = scale_amount ) } - # Output final plot + + if (exists("selected_module")) { + rm(selected_module, envir = .GlobalEnv) + } + final } diff --git a/R/plot_fishing_mortality.R b/R/plot_fishing_mortality.R index dbe6fd7b..dfd5b141 100644 --- a/R/plot_fishing_mortality.R +++ b/R/plot_fishing_mortality.R @@ -203,10 +203,9 @@ plot_fishing_mortality <- function( ) } - # remove global variable "selected_module" - if (exists("selected_module", envir = .GlobalEnv)) rm("selected_module", envir = .GlobalEnv) + if (exists("selected_module")) { + rm(selected_module, envir = .GlobalEnv) + } - # Output final plot - final - + final } diff --git a/R/plot_index.R b/R/plot_index.R index a9c7c81a..2c3ad84a 100644 --- a/R/plot_index.R +++ b/R/plot_index.R @@ -8,7 +8,7 @@ #' Options: May include, but is not limited to: "fleet", "year", "area", NULL #' @param unit_label String. Index of abundance/CPUE units #' -#' Default: "" +#' Default: NULL #' @param focus Character vector. Column name or names used to filter data. #' (i.e. select names of fleets to zoom into the plot) #' @@ -173,6 +173,10 @@ plot_index <- function( dir = figures_dir ) } - # Output final plot + + if (exists("selected_module")) { + rm(selected_module, envir = .GlobalEnv) + } + plt } diff --git a/R/plot_landings.R b/R/plot_landings.R index 0ab3a74c..efd1b7bf 100644 --- a/R/plot_landings.R +++ b/R/plot_landings.R @@ -60,10 +60,32 @@ plot_landings <- function( # filter NA from year # dplyr::filter(!is.na(year)) + # Process data + processed_data <- process_data( + dat = prepared_data, + group = group, + facet = facet, + lbs = lbs + ) + landings_data <- processed_data[[1]] + group <- processed_data[[2]] + facet <- processed_data[[3]] + + # Check if there is >1 label + if (length(landings_data$label) > 1) { + landings_data <- landings_data |> + # always select the first label if TRUE + dplyr::filter(label == unique(label)[1]) + } + # extract unit if unit_label is null and set lbs to F by default lbs <- FALSE if (is.null(unit_label)) { - unit_label <- unique(prepared_data$unit) + labels <- unique(landings_data$label) + unit_label <- prepared_data |> + dplyr::filter(label %in% labels) |> + dplyr::pull(unit) |> + unique() if (is.na(unit_label)) { cli::cli_alert_warning("No unit label found in the data. Please provide a unit label using the 'unit_label' argument.") unit_label <- "" @@ -79,33 +101,15 @@ plot_landings <- function( scale_amount = dplyr::if_else(lbs, 1000 * scale_amount, scale_amount), legend = FALSE ) - - # Process data - processed_data <- process_data( - dat = prepared_data, - group = group, - facet = facet, - lbs = lbs - ) - prepared_data <- processed_data[[1]] - group <- processed_data[[2]] - facet <- processed_data[[3]] - - # Check if there is >1 label - if (length(prepared_data$label) > 1) { - prepared_data <- prepared_data |> - # always select the first label if TRUE - dplyr::filter(label == unique(label)[1]) - } # Override grouping variable when there is only NA's if (!is.null(group)) { - if (group %notin% colnames(prepared_data)) group <- NULL + if (group %notin% colnames(landings_data)) group <- NULL } # inital base plot plt <- plot_timeseries( - dat = prepared_data, + dat = landings_data, y = "estimate", geom = geom, ylab = landings_label, @@ -114,17 +118,17 @@ plot_landings <- function( ... ) + theme_noaa() - if (length(unique(prepared_data$group_var)) == 1) { + if (length(unique(landings_data$group_var)) == 1) { plt <- plt + ggplot2::theme(legend.position = "none") } ### Make RDA ---- if (make_rda) { # Obtain relevant key quantities for captions/alt text - landings.start.year <- min(prepared_data$year) - landings.end.year <- max(prepared_data$year) - landings.min <- min(prepared_data$estimate) |> round(digits = 3) - landings.max <- max(prepared_data$estimate) |> round(digits = 3) + landings.start.year <- min(landings_data$year) + landings.end.year <- max(landings_data$year) + landings.min <- min(landings_data$estimate) |> round(digits = 3) + landings.max <- max(landings_data$estimate) |> round(digits = 3) landings.units <- unit_label # calculate & export key quantities @@ -157,6 +161,10 @@ plot_landings <- function( scale_amount = scale_amount ) } - # Output final plot + + if (exists("selected_module")) { + rm(selected_module, envir = .GlobalEnv) + } + plt } diff --git a/R/plot_natural_mortality.R b/R/plot_natural_mortality.R index 5fb1af55..e3c70b03 100644 --- a/R/plot_natural_mortality.R +++ b/R/plot_natural_mortality.R @@ -142,6 +142,10 @@ plot_natural_mortality <- function( dir = figures_dir ) } - # Output final plot + + if (exists("selected_module")) { + rm(selected_module, envir = .GlobalEnv) + } + final } diff --git a/man/plot_biomass.Rd b/man/plot_biomass.Rd index c358192b..e0881fa3 100644 --- a/man/plot_biomass.Rd +++ b/man/plot_biomass.Rd @@ -65,7 +65,7 @@ Options: "early", "time", "fore" (forecast), or NULL (all data)} \item{unit_label}{String. Biomass units -Default: "mt"} +Default: NULL} \item{module}{Character vector. (Optional) Module name found in \code{dat$module_name}. If selecting >1 module, place them in a vector like c("module1", "module2"). diff --git a/man/plot_index.Rd b/man/plot_index.Rd index 12a0666c..0eb9591c 100644 --- a/man/plot_index.Rd +++ b/man/plot_index.Rd @@ -26,7 +26,7 @@ in \code{ref_line} is used to plot a reference line or calculate relative spawni \item{unit_label}{String. Index of abundance/CPUE units -Default: ""} +Default: NULL} \item{group}{String. Single column that groups the data.