diff --git a/NAMESPACE b/NAMESPACE index 0de5d9df..ab256ecd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -23,6 +23,7 @@ export(plot_recruitment) export(plot_recruitment_deviations) export(plot_selectivity) export(plot_spawning_biomass) +export(plot_spawning_potential_ratio) export(plot_stock_recruitment) export(plot_timeseries) export(process_data) diff --git a/R/plot_abundance_at_age.R b/R/plot_abundance_at_age.R index ce389084..62b156cd 100644 --- a/R/plot_abundance_at_age.R +++ b/R/plot_abundance_at_age.R @@ -63,34 +63,28 @@ #' #' @examples #' plot_abundance_at_age( -#' dat = stockplotr:::example_data, +#' dat = stockplotr::example_data, #' facet = "growth_pattern", #' unit_label = "fish", #' scale_amount = 1000, #' proportional = TRUE #' ) #' plot_abundance_at_age( -#' dat = stockplotr:::example_data, +#' dat = stockplotr::example_data, #' facet = "none", #' proportional = FALSE #' ) plot_abundance_at_age <- function( dat, facet = NULL, - unit_label = "fish", - scale_amount = 1000, + unit_label = NULL, + scale_amount = 1, proportional = TRUE, module = NULL, interactive = TRUE, make_rda = FALSE, figures_dir = getwd() ) { - # Create label for abundance units in legend - abundance_label <- label_magnitude( - label = "Abundance", - unit_label = unit_label, - scale_amount = scale_amount - ) # Filter data b <- filter_data( dat = dat, @@ -102,6 +96,21 @@ plot_abundance_at_age <- function( interactive = interactive ) + # Create label for abundance units in legend + if (is.null(unit_label)) { + unit_label <- unique(b$unit) + if (grepl("number", unit_label)) unit_label <- "fish" + 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 <- "" + } + } + abundance_label <- label_magnitude( + label = "Abundance", + unit_label = unit_label, + scale_amount = scale_amount + ) + if (!is.null(facet) && facet == "none") { data <- b |> dplyr::group_by(year, age) |> diff --git a/R/plot_biomass.R b/R/plot_biomass.R index 724649ed..eba136a6 100644 --- a/R/plot_biomass.R +++ b/R/plot_biomass.R @@ -28,7 +28,7 @@ #' #' @examples #' plot_biomass( -#' dat = stockplotr:::example_data, +#' dat = stockplotr::example_data, #' unit_label = "mt", #' ref_line = c("target" = 20000), #' scale_amount = 100, @@ -36,7 +36,7 @@ #' figures_dir = getwd() #' ) #' plot_biomass( -#' dat = stockplotr:::example_data, +#' dat = stockplotr::example_data, #' ref_line = NULL, #' module = "TIME_SERIES", #' figures_dir = getwd() @@ -48,7 +48,7 @@ plot_biomass <- function( facet = NULL, ref_line = "msy", era = NULL, - unit_label = "mt", + unit_label = NULL, module = NULL, scale_amount = 1, relative = FALSE, @@ -57,22 +57,6 @@ plot_biomass <- function( interactive = TRUE, ... ) { - # TODO: Fix the unit label if scaling. Maybe this is up to the user to do if - # they want something scaled then they have to supply a better unit name - # or we create a helper function to do this. - biomass_label <- ifelse( - relative, - yes = "Relative biomass", - no = { - label_magnitude( - label = "Biomass", - unit_label = unit_label, - scale_amount = scale_amount, - legend = FALSE - ) - } - ) - # Pull first df if in a list to find reference point if (!is.data.frame(dat)) { rp_dat <- dat[[1]] @@ -101,6 +85,28 @@ plot_biomass <- function( scale_amount = scale_amount, interactive = interactive ) + + if (is.null(unit_label)) { + unit_label <- unique(prepared_data$unit) + 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 <- "" + } + } + + biomass_label <- ifelse( + relative, + yes = "Relative biomass", + no = { + label_magnitude( + label = "Biomass", + unit_label = unit_label, + scale_amount = scale_amount, + legend = FALSE + ) + } + ) + if (relative) { if (nrow(prepared_data) == 0) { cli::cli_abort("No data found for relative biomass. Please check that your data contains a label for 'biomass_biomass_unfished'.") diff --git a/R/plot_biomass_at_age.R b/R/plot_biomass_at_age.R index f2485a9f..64e5f3c4 100644 --- a/R/plot_biomass_at_age.R +++ b/R/plot_biomass_at_age.R @@ -27,14 +27,14 @@ #' #' @examples #' plot_biomass_at_age( -#' dat = stockplotr:::example_data, +#' dat = stockplotr::example_data, #' unit_label = "mt", #' scale_amount = 100, #' proportional = FALSE, # displays legend #' make_rda = FALSE #' ) #' plot_biomass_at_age( -#' dat = stockplotr:::example_data, +#' dat = stockplotr::example_data, #' unit_label = "mt", #' facet = "none", #' proportional = FALSE @@ -42,20 +42,14 @@ plot_biomass_at_age <- function( dat, facet = NULL, - unit_label = "mt", - scale_amount = 1000, + unit_label = NULL, + scale_amount = 1, proportional = TRUE, module = NULL, interactive = TRUE, make_rda = FALSE, figures_dir = getwd() ) { - # Create label for abundance units in legend - biomass_label <- label_magnitude( - label = "Biomass", - unit_label = unit_label, - scale_amount = scale_amount - ) # Filter data b <- filter_data( dat = dat |> @@ -68,6 +62,22 @@ plot_biomass_at_age <- function( scale_amount = scale_amount, interactive = interactive ) + + if (is.null(unit_label)) { + unit_label <- unique(b$unit) + 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 <- "" + } + } + + # Create label for abundance units in legend + biomass_label <- label_magnitude( + label = "Biomass", + unit_label = unit_label, + scale_amount = scale_amount + ) + if (!is.null(facet) && facet == "none") { data <- b |> dplyr::group_by(year, age) |> diff --git a/R/plot_catch_comp.R b/R/plot_catch_comp.R index e49882cc..97a9cb1d 100644 --- a/R/plot_catch_comp.R +++ b/R/plot_catch_comp.R @@ -47,9 +47,8 @@ #' @export #' @examples #' plot_catch_comp( -#' dat = stockplotr:::example_data, +#' dat = stockplotr::example_data, #' facet = "fleet", -#' unit_label = "mt", #' scale_amount = 100, #' interactive = FALSE, #' make_rda = FALSE, @@ -57,7 +56,7 @@ #' ) #' #' plot_catch_comp( -#' dat = stockplotr:::example_data, +#' dat = stockplotr::example_data, #' facet = "none", #' unit_label = "mt", #' scale_amount = 100, @@ -69,7 +68,7 @@ plot_catch_comp <- function( dat, facet = NULL, era = "time", - unit_label = "mt", + unit_label = NULL, scale_amount = 1, proportional = TRUE, interactive = TRUE, @@ -77,13 +76,6 @@ plot_catch_comp <- function( make_rda = FALSE, figures_dir = getwd() ) { - # Create label for abundance units in legend - catch_label <- label_magnitude( - label = "catch", - unit_label = unit_label, - scale_amount = scale_amount, - legend = TRUE - ) # Filter data catch <- filter_data( dat = dat |> @@ -96,6 +88,21 @@ plot_catch_comp <- function( interactive = interactive, module = module ) + if (is.null(unit_label)) { + unit_label <- unique(catch$unit) + 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 <- "" + } + } + # Create label for abundance units in legend + catch_label <- label_magnitude( + label = "catch", + unit_label = unit_label, + scale_amount = scale_amount, + legend = TRUE + ) + # Check for extracted data, if not return warning and empty plot if (nrow(catch) == 0) { cli::cli_alert_warning("No data found for catch at age. Please check the input data.") diff --git a/R/plot_discard.R b/R/plot_discard.R index efde6518..36d9ef04 100644 --- a/R/plot_discard.R +++ b/R/plot_discard.R @@ -21,14 +21,15 @@ #' #' @examples #' plot_discard( -#' dat = stockplotr:::example_data, +#' dat = stockplotr::example_data, +#' unit_label = "fish", #' module = "DISCARD_OUTPUT" #' ) plot_discard <- function( dat, group = NULL, facet = NULL, - unit_label = "mt", + unit_label = NULL, era = NULL, lbs = FALSE, scale_amount = 1, @@ -43,17 +44,6 @@ plot_discard <- function( unit_label <- "lbs" } - discard_label <- label_magnitude( - label = "Discard", - unit_label = unit_label, - scale_amount = dplyr::if_else( - lbs, - ifelse(unit_label %in% c("mt", "mts", "metric tons", "metric ton"), 1000, 1) * scale_amount, - scale_amount - ), - legend = TRUE - ) - # Filter data for discards prepared_data <- filter_data( dat = dat, @@ -66,6 +56,24 @@ plot_discard <- function( scale_amount = scale_amount, interactive = interactive ) + + # 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) + 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 <- "" + } + } else { + if (grepl("lbs|pounds|lb", unit_label, ignore.case = TRUE)) lbs <- TRUE + } + discard_label <- label_magnitude( + label = "Discard", + unit_label = unit_label, + scale_amount = scale_amount, + legend = TRUE + ) if (any(grepl("observed|predicted", unique(prepared_data$label)))) { # select only the observed and predicted discards for plotting diff --git a/R/plot_index.R b/R/plot_index.R index 99fd2624..971172c7 100644 --- a/R/plot_index.R +++ b/R/plot_index.R @@ -33,7 +33,7 @@ #' plot_index <- function( dat, - unit_label = "", + unit_label = NULL, group = NULL, # facet always assigned to fleet since that is how indices are calc'd -- unless replaced with NULL facet = NULL, @@ -44,13 +44,6 @@ plot_index <- function( figures_dir = getwd(), ... ) { - # Set cpue unit label for plot - u_units <- ifelse( - is.null(unit_label) | unit_label == "", - glue::glue("Estimated Index"), - glue::glue("Estimated Index ({unit_label})") - ) - if (is.null(facet) || "fleet" %notin% facet) { facet <- c(facet, "fleet") } @@ -68,6 +61,17 @@ plot_index <- function( interactive = interactive, module = module ) + if (unit_label != "" && !is.na(unique(prepared_data$unit))) unit_label <- unique(prepared_data$unit) + 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 <- "" + } + # Set cpue unit label for plot + u_units <- ifelse( + is.null(unit_label) | unit_label == "", + glue::glue("Estimated Index"), + glue::glue("Estimated Index ({unit_label})") + ) # Subset data if focus if (!is.null(focus)) { @@ -102,7 +106,7 @@ plot_index <- function( predicted_label = "index_predicted", geom = "line", xlab = "Year", - ylab = "Estimated Index", + ylab = u_units, group = group, facet = facet ) + diff --git a/R/plot_landings.R b/R/plot_landings.R index 6c50cbac..cf9cb087 100644 --- a/R/plot_landings.R +++ b/R/plot_landings.R @@ -15,14 +15,14 @@ #' #' @examples #' plot_landings( -#' dat = stockplotr:::example_data, +#' dat = stockplotr::example_data, #' unit_label = "metric tons", #' group = "fleet", #' interactive = FALSE, #' make_rda = FALSE #' ) #' plot_landings( -#' dat = stockplotr:::example_data, +#' dat = stockplotr::example_data, #' unit_label = "metric tons", #' facet = "fleet", #' interactive = FALSE, @@ -30,7 +30,7 @@ #' ) plot_landings <- function( dat, - unit_label = "mt", + unit_label = NULL, geom = "line", group = NULL, facet = NULL, @@ -43,20 +43,6 @@ plot_landings <- function( figures_dir = getwd(), ... ) { - # this assumes that the previous units were metric tons - if (lbs && unit_label %notin% c("lbs", "pounds", "lb")) { - cli::cli_alert_info("Unit label was not changed. Setting unit_label to 'lbs'.") - unit_label <- "lbs" - } - - # Units - landings_label <- label_magnitude( - label = "Landings", - unit_label = unit_label, - scale_amount = dplyr::if_else(lbs, 1000 * scale_amount, scale_amount), - legend = FALSE - ) - # Filter data for landings prepared_data <- filter_data( dat = dat, @@ -71,6 +57,27 @@ plot_landings <- function( ) # |> # filter NA from year # dplyr::filter(!is.na(year)) + + # 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) + 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 <- "" + } + } else { + if (grepl("lbs|pounds|lb", unit_label, ignore.case = TRUE)) lbs <- TRUE + } + + # Units + landings_label <- label_magnitude( + label = "Landings", + unit_label = unit_label, + scale_amount = dplyr::if_else(lbs, 1000 * scale_amount, scale_amount), + legend = FALSE + ) + # Process data processed_data <- process_data( dat = prepared_data, diff --git a/R/plot_spawning_biomass.R b/R/plot_spawning_biomass.R index e079ca74..3e92b2c4 100644 --- a/R/plot_spawning_biomass.R +++ b/R/plot_spawning_biomass.R @@ -40,12 +40,16 @@ #' #' 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). -#' @param unit_label String. Spawning biomass unit. +#' @param 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`. #' -#' Default: "mt" -#' @param lbs Logical. TRUE/FALSE; indicate whether to convert the y-axis values from +#' Default: NULL +#' @param lbs `r lifecycle::badge('deprecated')` Logical. TRUE/FALSE; indicate whether to convert the y-axis values from #' kilograms to pounds. The default units match the default in the -#' unit_label argument - 'mt'. +#' unit_label argument - 'mt'. -- Deprecate #' #' Default: `FALSE` #' @param module Character vector. (Optional) Module name found in `dat$module_name`. @@ -55,7 +59,10 @@ #' #' If the interactive and >1 module_name is found, user will select the #' module_name in the console. @seealso [filter_data()] -#' @param scale_amount Number. A number to scale the y-axis values. +#' @param scale_amount Number. A number to scale the y-axis values. If > 1, the +#' magnitude of the scale amount will be added to the unit label +#' (e.g. scale_amount = 1000 with a unit label of "1000s of lbs" will result +#' in "thousands of 1000s of lbs") #' #' Default: 1 #' @param relative Logical. TRUE/FALSE; specify whether to set y-axis values relative to @@ -121,9 +128,9 @@ plot_spawning_biomass <- function( group = NULL, facet = NULL, ref_line = "msy", - unit_label = "mt", + unit_label = NULL, era = NULL, - lbs = FALSE, + lbs = lifecycle::deprecate(), module = NULL, scale_amount = 1, relative = FALSE, @@ -132,32 +139,7 @@ plot_spawning_biomass <- function( interactive = TRUE, ... ) { - # this assumes that the previous units were metric tons - if (lbs && unit_label %notin% c("lbs", "pounds", "lb")) { - cli::cli_alert_info("Unit label was not changed. Setting unit_label to 'lbs'.") - unit_label <- "lbs" - } - - # TODO: Fix the unit label if scaling. Maybe this is up to the user to do if - # they want something scaled then they have to supply a better unit name - # or we create a helper function to do this. - spawning_biomass_label <- ifelse( - relative, - yes = "Relative spawning biomass", - no = { - label_magnitude( - label = "Spawning Biomass", - unit_label = unit_label, - scale_amount = dplyr::if_else( - lbs, - ifelse(unit_label %in% c("mt", "mts", "metric tons", "metric ton"), 1000, 1) * scale_amount, - scale_amount - ), - legend = TRUE - ) - } - ) - + # 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 @@ -175,7 +157,31 @@ plot_spawning_biomass <- function( scale_amount = scale_amount, interactive = interactive ) - + # 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) + if (is.na(unit_label)) cli::cli_abort("No unit label found in the data. Please provide a unit label using the 'unit_label' argument.") + } else { + if (grepl("lbs|pounds|lb", unit_label, ignore.case = TRUE)) lbs <- TRUE + } + + # TODO: Fix the unit label if scaling. Maybe this is up to the user to do if + # they want something scaled then they have to supply a better unit name + # or we create a helper function to do this. + spawning_biomass_label <- ifelse( + relative, + yes = "Relative spawning biomass", + no = { + label_magnitude( + label = "Spawning Biomass", + unit_label = unit_label, + scale_amount = scale_amount, + legend = TRUE + ) + } + ) + if (relative) { if (nrow(prepared_data) == 0) { cli::cli_abort("No data found for relative biomass. Please check that your data contains a label for 'biomass_biomass_unfished'.") diff --git a/man/calculate_reference_point.Rd b/man/calculate_reference_point.Rd index 86e38307..6f1736e2 100644 --- a/man/calculate_reference_point.Rd +++ b/man/calculate_reference_point.Rd @@ -13,11 +13,11 @@ 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{reference_name}{a string of the name of the reference point (e.g. "spawning biomass msy")} +\item{reference_name}{String. Name of the reference point (e.g. "spawning biomass msy")} -\item{lbs}{Logical. TRUE/FALSE; indicate whether to convert the y-axis values from +\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 kilograms to pounds. The default units match the default in the -unit_label argument - 'mt'. +unit_label argument - 'mt'. -- Deprecate Default: \code{FALSE}} } diff --git a/man/filter_data.Rd b/man/filter_data.Rd index 129fea0d..4884d58e 100644 --- a/man/filter_data.Rd +++ b/man/filter_data.Rd @@ -57,7 +57,10 @@ Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", Default: NULL} -\item{scale_amount}{Number. A number to scale the y-axis values. +\item{scale_amount}{Number. A number to scale the y-axis values. If > 1, the +magnitude of the scale amount will be added to the unit label +(e.g. scale_amount = 1000 with a unit label of "1000s of lbs" will result +in "thousands of 1000s of lbs") Default: 1} diff --git a/man/plot_abundance_at_age.Rd b/man/plot_abundance_at_age.Rd index 2c87df83..62bef3a3 100644 --- a/man/plot_abundance_at_age.Rd +++ b/man/plot_abundance_at_age.Rd @@ -7,8 +7,8 @@ plot_abundance_at_age( dat, facet = NULL, - unit_label = "fish", - scale_amount = 1000, + unit_label = NULL, + scale_amount = 1, proportional = TRUE, module = NULL, interactive = TRUE, @@ -83,14 +83,14 @@ containing associated caption and alternative text for the figure. } \examples{ plot_abundance_at_age( - dat = stockplotr:::example_data, + dat = stockplotr::example_data, facet = "growth_pattern", unit_label = "fish", scale_amount = 1000, proportional = TRUE ) plot_abundance_at_age( - dat = stockplotr:::example_data, + dat = stockplotr::example_data, facet = "none", proportional = FALSE ) diff --git a/man/plot_biomass.Rd b/man/plot_biomass.Rd index 33bc9913..c358192b 100644 --- a/man/plot_biomass.Rd +++ b/man/plot_biomass.Rd @@ -11,7 +11,7 @@ plot_biomass( facet = NULL, ref_line = "msy", era = NULL, - unit_label = "mt", + unit_label = NULL, module = NULL, scale_amount = 1, relative = FALSE, @@ -75,7 +75,10 @@ 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{scale_amount}{Number. A number to scale the y-axis values. +\item{scale_amount}{Number. A number to scale the y-axis values. If > 1, the +magnitude of the scale amount will be added to the unit label +(e.g. scale_amount = 1000 with a unit label of "1000s of lbs" will result +in "thousands of 1000s of lbs") Default: 1} @@ -116,7 +119,7 @@ containing associated caption and alternative text for the figure. } \examples{ plot_biomass( - dat = stockplotr:::example_data, + dat = stockplotr::example_data, unit_label = "mt", ref_line = c("target" = 20000), scale_amount = 100, @@ -124,7 +127,7 @@ plot_biomass( figures_dir = getwd() ) plot_biomass( - dat = stockplotr:::example_data, + dat = stockplotr::example_data, ref_line = NULL, module = "TIME_SERIES", figures_dir = getwd() diff --git a/man/plot_biomass_at_age.Rd b/man/plot_biomass_at_age.Rd index e58c2227..13f2373b 100644 --- a/man/plot_biomass_at_age.Rd +++ b/man/plot_biomass_at_age.Rd @@ -8,7 +8,7 @@ plot_biomass_at_age( dat, facet = NULL, unit_label = "mt", - scale_amount = 1000, + scale_amount = 1, proportional = TRUE, module = NULL, interactive = TRUE, @@ -83,14 +83,14 @@ containing associated caption and alternative text for the figure. } \examples{ plot_biomass_at_age( - dat = stockplotr:::example_data, + dat = stockplotr::example_data, unit_label = "mt", scale_amount = 100, proportional = FALSE, # displays legend make_rda = FALSE ) plot_biomass_at_age( - dat = stockplotr:::example_data, + dat = stockplotr::example_data, unit_label = "mt", facet = "none", proportional = FALSE diff --git a/man/plot_catch_comp.Rd b/man/plot_catch_comp.Rd index 9bcfe44b..360aaff1 100644 --- a/man/plot_catch_comp.Rd +++ b/man/plot_catch_comp.Rd @@ -8,7 +8,7 @@ plot_catch_comp( dat, facet = NULL, era = "time", - unit_label = "mt", + unit_label = NULL, scale_amount = 1, proportional = TRUE, interactive = TRUE, @@ -93,9 +93,8 @@ containing associated caption and alternative text for the figure. } \examples{ plot_catch_comp( - dat = stockplotr:::example_data, + dat = stockplotr::example_data, facet = "fleet", - unit_label = "mt", scale_amount = 100, interactive = FALSE, make_rda = FALSE, @@ -103,7 +102,7 @@ plot_catch_comp( ) plot_catch_comp( - dat = stockplotr:::example_data, + dat = stockplotr::example_data, facet = "none", unit_label = "mt", scale_amount = 100, diff --git a/man/plot_discard.Rd b/man/plot_discard.Rd index 4add2f87..a58f65ad 100644 --- a/man/plot_discard.Rd +++ b/man/plot_discard.Rd @@ -8,7 +8,7 @@ plot_discard( dat, group = NULL, facet = NULL, - unit_label = "mt", + unit_label = NULL, era = NULL, lbs = FALSE, scale_amount = 1, @@ -36,9 +36,13 @@ Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", Default: NULL} -\item{unit_label}{String. Spawning biomass unit. +\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}. -Default: "mt"} +Default: NULL} \item{era}{String. Era of data. @@ -46,13 +50,16 @@ Default: "time" Options: "early", "time", "fore" (forecast), or NULL (all data)} -\item{lbs}{Logical. TRUE/FALSE; indicate whether to convert the y-axis values from +\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 kilograms to pounds. The default units match the default in the -unit_label argument - 'mt'. +unit_label argument - 'mt'. -- Deprecate Default: \code{FALSE}} -\item{scale_amount}{Number. A number to scale the y-axis values. +\item{scale_amount}{Number. A number to scale the y-axis values. If > 1, the +magnitude of the scale amount will be added to the unit label +(e.g. scale_amount = 1000 with a unit label of "1000s of lbs" will result +in "thousands of 1000s of lbs") Default: 1} @@ -98,7 +105,8 @@ use them in groupings and/or facetting. @seealso \code{\link[=process_data]{proc } \examples{ plot_discard( - dat = stockplotr:::example_data, + dat = stockplotr::example_data, + unit_label = "fish", module = "DISCARD_OUTPUT" ) } diff --git a/man/plot_landings.Rd b/man/plot_landings.Rd index b005bfa2..f6a80c21 100644 --- a/man/plot_landings.Rd +++ b/man/plot_landings.Rd @@ -6,7 +6,7 @@ \usage{ plot_landings( dat, - unit_label = "mt", + unit_label = NULL, geom = "line", group = NULL, facet = NULL, @@ -27,9 +27,13 @@ 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{unit_label}{String. Spawning biomass unit. +\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}. -Default: "mt"} +Default: NULL} \item{geom}{String. Geom used for the plot. @@ -48,9 +52,9 @@ Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", Default: NULL} -\item{lbs}{Logical. TRUE/FALSE; indicate whether to convert the y-axis values from +\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 kilograms to pounds. The default units match the default in the -unit_label argument - 'mt'. +unit_label argument - 'mt'. -- Deprecate Default: \code{FALSE}} @@ -60,7 +64,10 @@ Default: "time" Options: "early", "time", "fore" (forecast), or NULL (all data)} -\item{scale_amount}{Number. A number to scale the y-axis values. +\item{scale_amount}{Number. A number to scale the y-axis values. If > 1, the +magnitude of the scale amount will be added to the unit label +(e.g. scale_amount = 1000 with a unit label of "1000s of lbs" will result +in "thousands of 1000s of lbs") Default: 1} @@ -104,14 +111,14 @@ containing associated caption and alternative text for the figure. } \examples{ plot_landings( - dat = stockplotr:::example_data, + dat = stockplotr::example_data, unit_label = "metric tons", group = "fleet", interactive = FALSE, make_rda = FALSE ) plot_landings( - dat = stockplotr:::example_data, + dat = stockplotr::example_data, unit_label = "metric tons", facet = "fleet", interactive = FALSE, diff --git a/man/plot_recruitment.Rd b/man/plot_recruitment.Rd index 7c05f910..a1f9e177 100644 --- a/man/plot_recruitment.Rd +++ b/man/plot_recruitment.Rd @@ -28,7 +28,10 @@ in \code{ref_line} is used to plot a reference line or calculate relative spawni Default: "mt"} -\item{scale_amount}{Number. A number to scale the y-axis values. +\item{scale_amount}{Number. A number to scale the y-axis values. If > 1, the +magnitude of the scale amount will be added to the unit label +(e.g. scale_amount = 1000 with a unit label of "1000s of lbs" will result +in "thousands of 1000s of lbs") Default: 1} diff --git a/man/plot_spawning_biomass.Rd b/man/plot_spawning_biomass.Rd index 43e1e35f..458a9435 100644 --- a/man/plot_spawning_biomass.Rd +++ b/man/plot_spawning_biomass.Rd @@ -10,9 +10,9 @@ plot_spawning_biomass( group = NULL, facet = NULL, ref_line = "msy", - unit_label = "mt", + unit_label = NULL, era = NULL, - lbs = FALSE, + lbs = lifecycle::deprecate(), module = NULL, scale_amount = 1, relative = FALSE, @@ -61,9 +61,13 @@ 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{unit_label}{String. Spawning biomass unit. +\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}. -Default: "mt"} +Default: NULL} \item{era}{String. Era of data. @@ -71,9 +75,9 @@ Default: "time" Options: "early", "time", "fore" (forecast), or NULL (all data)} -\item{lbs}{Logical. TRUE/FALSE; indicate whether to convert the y-axis values from +\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 kilograms to pounds. The default units match the default in the -unit_label argument - 'mt'. +unit_label argument - 'mt'. -- Deprecate Default: \code{FALSE}} @@ -85,7 +89,10 @@ 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{scale_amount}{Number. A number to scale the y-axis values. +\item{scale_amount}{Number. A number to scale the y-axis values. If > 1, the +magnitude of the scale amount will be added to the unit label +(e.g. scale_amount = 1000 with a unit label of "1000s of lbs" will result +in "thousands of 1000s of lbs") Default: 1} 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()}} +} diff --git a/man/plot_stock_recruitment.Rd b/man/plot_stock_recruitment.Rd index ebd87c62..1099dd06 100644 --- a/man/plot_stock_recruitment.Rd +++ b/man/plot_stock_recruitment.Rd @@ -52,7 +52,10 @@ 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{scale_amount}{Number. A number to scale the y-axis values. +\item{scale_amount}{Number. A number to scale the y-axis values. If > 1, the +magnitude of the scale amount will be added to the unit label +(e.g. scale_amount = 1000 with a unit label of "1000s of lbs" will result +in "thousands of 1000s of lbs") Default: 1} diff --git a/man/reference_line.Rd b/man/reference_line.Rd index 76cf1025..120b0a91 100644 --- a/man/reference_line.Rd +++ b/man/reference_line.Rd @@ -18,7 +18,10 @@ extract the reference point from} \item{ref_line}{String. Reference point(s)} -\item{scale_amount}{Number. A number to scale the y-axis values. +\item{scale_amount}{Number. A number to scale the y-axis values. If > 1, the +magnitude of the scale amount will be added to the unit label +(e.g. scale_amount = 1000 with a unit label of "1000s of lbs" will result +in "thousands of 1000s of lbs") Default: 1} diff --git a/man/table_landings.Rd b/man/table_landings.Rd index ee28d9b0..69b3e42f 100644 --- a/man/table_landings.Rd +++ b/man/table_landings.Rd @@ -74,7 +74,10 @@ table will be rounded to. Default: 2} -\item{scale_amount}{Number. A number to scale the y-axis values. +\item{scale_amount}{Number. A number to scale the y-axis values. If > 1, the +magnitude of the scale amount will be added to the unit label +(e.g. scale_amount = 1000 with a unit label of "1000s of lbs" will result +in "thousands of 1000s of lbs") Default: 1} diff --git a/man/table_total_catch.Rd b/man/table_total_catch.Rd index 855b5835..25f6c5ce 100644 --- a/man/table_total_catch.Rd +++ b/man/table_total_catch.Rd @@ -45,7 +45,10 @@ 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{scale_amount}{Number. A number to scale the y-axis values. +\item{scale_amount}{Number. A number to scale the y-axis values. If > 1, the +magnitude of the scale amount will be added to the unit label +(e.g. scale_amount = 1000 with a unit label of "1000s of lbs" will result +in "thousands of 1000s of lbs") Default: 1}