diff --git a/R/plot_abundance_at_age.R b/R/plot_abundance_at_age.R index 480da3a1..753f9718 100644 --- a/R/plot_abundance_at_age.R +++ b/R/plot_abundance_at_age.R @@ -35,6 +35,13 @@ #' #' If the interactive and >1 module_name is found, user will select the #' module_name in the console. @seealso [filter_data()] +#' @param model Character vector. (Optional) Model name found in `dat$model`. +#' If selecting >1 model, place them in a vector like c("model1", "model2"). +#' +#' Default: NULL +#' +#' If the interactive and >1 model is found, user will select the +#' model in the console. @seealso [filter_data()] #' @param interactive A logical value indicating if the environment is interactive. #' #' Default: `FALSE` @@ -81,6 +88,7 @@ plot_abundance_at_age <- function( scale_amount = 1, proportional = TRUE, module = NULL, + model = NULL, interactive = TRUE, make_rda = FALSE, figures_dir = getwd() @@ -94,8 +102,10 @@ plot_abundance_at_age <- function( geom = "point", group = "age", module = module, + model = model, scale_amount = scale_amount, - interactive = interactive + interactive = interactive, + allow_multiple_models = TRUE ) # Create label for abundance units in legend diff --git a/R/plot_biomass.R b/R/plot_biomass.R index 211056d0..15e2c7e5 100644 --- a/R/plot_biomass.R +++ b/R/plot_biomass.R @@ -50,6 +50,7 @@ plot_biomass <- function( era = NULL, unit_label = NULL, module = NULL, + model = NULL, scale_amount = 1, relative = FALSE, make_rda = FALSE, @@ -84,8 +85,10 @@ plot_biomass <- function( facet = facet, era = era, module = module, + model = model, scale_amount = scale_amount, - interactive = interactive + interactive = interactive, + allow_multiple_models = TRUE ) if (is.null(unit_label)) { @@ -155,7 +158,7 @@ plot_biomass <- function( } else { final <- plt + add_reference_line( - dat = dat, + dat = dat |> dplyr::filter(model %in% selected_model), ref_line = ref_line, label = "biomass", scale_amount = scale_amount diff --git a/R/plot_biomass_at_age.R b/R/plot_biomass_at_age.R index f335ed19..362db96c 100644 --- a/R/plot_biomass_at_age.R +++ b/R/plot_biomass_at_age.R @@ -46,6 +46,7 @@ plot_biomass_at_age <- function( scale_amount = 1, proportional = TRUE, module = NULL, + model = NULL, interactive = TRUE, make_rda = FALSE, figures_dir = getwd() @@ -61,8 +62,10 @@ plot_biomass_at_age <- function( group = "age", era = "time", module = module, + model = model, scale_amount = scale_amount, - interactive = interactive + interactive = interactive, + allow_multiple_models = TRUE ) if (is.null(unit_label)) { diff --git a/R/plot_catch_at_age.R b/R/plot_catch_at_age.R index 78308e52..c3922351 100644 --- a/R/plot_catch_at_age.R +++ b/R/plot_catch_at_age.R @@ -74,6 +74,7 @@ plot_catch_at_age <- function( proportional = TRUE, interactive = TRUE, module = NULL, + model = NULL, make_rda = FALSE, figures_dir = getwd() ) { @@ -89,7 +90,9 @@ plot_catch_at_age <- function( group = "age", scale_amount = scale_amount, interactive = interactive, - module = module + module = module, + model = model, + allow_multiple_models = TRUE ) if (is.null(unit_label)) { unit_label <- unique(catch$unit) diff --git a/R/plot_discard.R b/R/plot_discard.R index e3aab52b..212ac774 100644 --- a/R/plot_discard.R +++ b/R/plot_discard.R @@ -87,6 +87,7 @@ plot_discard <- function( scale_amount = 1, interactive = TRUE, module = NULL, + model = NULL, predicted = TRUE, interval = 0.95, tolerance = 0.001, @@ -115,8 +116,10 @@ plot_discard <- function( group = group, facet = facet, module = module, + model = model, scale_amount = scale_amount, - interactive = interactive + interactive = interactive, + allow_multiple_models = TRUE ) # extract unit if unit_label is null and set lbs to F by default diff --git a/R/plot_fishing_mortality.R b/R/plot_fishing_mortality.R index ccbb73d7..0bfcb9dc 100644 --- a/R/plot_fishing_mortality.R +++ b/R/plot_fishing_mortality.R @@ -36,6 +36,7 @@ plot_fishing_mortality <- function( ref_line = "msy", era = NULL, module = NULL, + model = NULL, make_rda = FALSE, figures_dir = getwd(), interactive = TRUE, @@ -54,8 +55,10 @@ plot_fishing_mortality <- function( group = group, facet = facet, module = module, + model = model, scale_amount = 1, - interactive = interactive + interactive = interactive, + allow_multiple_models = TRUE ) # Process data processed_data <- process_data( diff --git a/R/plot_index.R b/R/plot_index.R index 227db90e..56c555a9 100644 --- a/R/plot_index.R +++ b/R/plot_index.R @@ -75,6 +75,7 @@ plot_index <- function( facet = NULL, interactive = TRUE, module = NULL, + model = NULL, focus = NULL, interval = 0.95, log = FALSE, @@ -110,7 +111,9 @@ plot_index <- function( group = group, facet = facet, interactive = interactive, - module = module + module = module, + model = model, + allow_multiple_models = TRUE ) # There's 3 cases handled here diff --git a/R/plot_landings.R b/R/plot_landings.R index 798b52f3..1a581bec 100644 --- a/R/plot_landings.R +++ b/R/plot_landings.R @@ -97,6 +97,7 @@ plot_landings <- function( era = NULL, scale_amount = 1, module = NULL, + model = NULL, interactive = TRUE, predicted = TRUE, interval = 0.95, @@ -136,8 +137,10 @@ plot_landings <- function( group = group, facet = facet, module = module, + model = model, scale_amount = scale_amount, - interactive = interactive + interactive = interactive, + allow_multiple_models = TRUE ) # Intervals from the observation error of the observed and predicted diff --git a/R/plot_natural_mortality.R b/R/plot_natural_mortality.R index 09d1c1e9..e53c3882 100644 --- a/R/plot_natural_mortality.R +++ b/R/plot_natural_mortality.R @@ -26,6 +26,7 @@ plot_natural_mortality <- function( era = NULL, interactive = TRUE, module = NULL, + model = NULL, make_rda = FALSE, figures_dir = getwd(), ... @@ -43,7 +44,9 @@ plot_natural_mortality <- function( facet = facet, geom = "line", interactive = interactive, - module = module + module = module, + model = model, + allow_multiple_models = TRUE ) # Set group back to NULL if it is age since this is an at age plot diff --git a/R/plot_recruitment.R b/R/plot_recruitment.R index 5dbf3c9a..d6190d2a 100644 --- a/R/plot_recruitment.R +++ b/R/plot_recruitment.R @@ -42,6 +42,7 @@ plot_recruitment <- function( # relative = FALSE, interactive = TRUE, module = NULL, + model = NULL, make_rda = FALSE, figures_dir = getwd() ) { @@ -57,7 +58,9 @@ plot_recruitment <- function( facet = facet, interactive = interactive, module = module, - scale_amount = scale_amount + model = model, + scale_amount = scale_amount, + allow_multiple_models = TRUE ) # process data processed_data <- process_data( diff --git a/R/plot_recruitment_deviations.R b/R/plot_recruitment_deviations.R index f2ad753d..638cc5c9 100644 --- a/R/plot_recruitment_deviations.R +++ b/R/plot_recruitment_deviations.R @@ -33,6 +33,7 @@ plot_recruitment_deviations <- function( dat, module = NULL, + model = NULL, era = NULL, interactive = TRUE, make_rda = FALSE, @@ -46,10 +47,12 @@ plot_recruitment_deviations <- function( dat = dat, label_name = "recruitment_deviations", module = module, + model = model, era = era, interactive = interactive, geom = "point", - group = NULL + group = NULL, + allow_multiple_models = TRUE ) # Process data processed_data <- process_data( diff --git a/R/plot_retrospective.R b/R/plot_retrospective.R index fea5df17..86fdada0 100644 --- a/R/plot_retrospective.R +++ b/R/plot_retrospective.R @@ -141,9 +141,9 @@ plot_retrospective <- function( func_pars <- list( dat = retro_dat, group="peel", - model = "All", # turn this on to bypass interactive model selection and plot all available models - make_rda=FALSE, # don't want to overwrite files from non-retro plots - ... + model = names(end_years), # turn this on to bypass interactive model selection and plot all available models + make_rda=FALSE # don't want to overwrite files from non-retro plots + # ... ) plt <- do.call(func_name, func_pars) @@ -226,5 +226,3 @@ plot_retrospective <- function( plt } - -# plot_retrospective(dat) diff --git a/R/plot_selectivity.R b/R/plot_selectivity.R index d4781ad4..4d34336c 100644 --- a/R/plot_selectivity.R +++ b/R/plot_selectivity.R @@ -37,6 +37,7 @@ plot_selectivity <- function( facet = NULL, interactive = TRUE, module = NULL, + model = NULL, make_rda = FALSE, figures_dir = getwd(), ... @@ -52,7 +53,9 @@ plot_selectivity <- function( group = group, facet = facet, interactive = interactive, - module = module + module = module, + model = model, + allow_multiple_models = TRUE ) if (is.null(unit_label)) { diff --git a/R/plot_spawning_biomass.R b/R/plot_spawning_biomass.R index 1047b598..e4f954f5 100644 --- a/R/plot_spawning_biomass.R +++ b/R/plot_spawning_biomass.R @@ -59,6 +59,13 @@ #' #' If the interactive and >1 module_name is found, user will select the #' module_name in the console. @seealso [filter_data()] +#' @param model Character vector. (Optional) Model name found in `dat$model`. +#' If selecting >1 model, place them in a vector like c("model1", "model2"). +#' +#' Default: NULL +#' +#' If the interactive and >1 model is found, user will select the +#' model in the console. @seealso [filter_data()] #' @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 @@ -132,6 +139,7 @@ plot_spawning_biomass <- function( era = NULL, lbs = lifecycle::deprecated(), module = NULL, + model = NULL, scale_amount = 1, relative = FALSE, make_rda = FALSE, @@ -155,8 +163,10 @@ plot_spawning_biomass <- function( group = group, facet = facet, module = module, + model = model, scale_amount = scale_amount, - interactive = interactive + interactive = interactive, + allow_multiple_models = TRUE ) # extract unit if unit_label is null and set lbs to F by default lbs <- FALSE @@ -221,7 +231,7 @@ plot_spawning_biomass <- function( } else { final <- plt + add_reference_line( - dat = dat, + dat = dat |> dplyr::filter(model %in% selected_model), ref_line = ref_line, label = "spawning_biomass", lbs = lbs, @@ -308,6 +318,7 @@ plot_spawning_biomass <- function( if (exists("selected_module")) { rm(selected_module, envir = .GlobalEnv) + rm(selected_model, envir = .GlobalEnv) } # Output final plot diff --git a/R/plot_spr.R b/R/plot_spr.R index dc000ab2..b1d91a83 100644 --- a/R/plot_spr.R +++ b/R/plot_spr.R @@ -41,6 +41,7 @@ plot_spr <- function( ref_line = "target", era = "time", module = NULL, + model = NULL, interactive = TRUE, make_rda = FALSE, figures_dir = getwd(), @@ -59,8 +60,10 @@ plot_spr <- function( group = group, facet = facet, module = module, + model = model, scale_amount = 1, - interactive = interactive + interactive = interactive, + allow_multiple_models = TRUE ) |> # filter NA from year dplyr::filter(!is.na(year)) diff --git a/R/plot_stock_recruitment.R b/R/plot_stock_recruitment.R index e0debed2..dbdf270f 100644 --- a/R/plot_stock_recruitment.R +++ b/R/plot_stock_recruitment.R @@ -43,6 +43,7 @@ plot_stock_recruitment <- function( interactive = TRUE, era = NULL, module = NULL, + model = NULL, scale_amount = 1, make_rda = FALSE, figures_dir = getwd() @@ -58,7 +59,9 @@ plot_stock_recruitment <- function( geom = "point", scale_amount = scale_amount, interactive = interactive, - module = module + module = module, + model = model, + allow_multiple_models = TRUE ) |> # filter for year !na dplyr::filter( diff --git a/R/table_biomass_abundance_catch.R b/R/table_biomass_abundance_catch.R index a29ddfa3..417ff754 100644 --- a/R/table_biomass_abundance_catch.R +++ b/R/table_biomass_abundance_catch.R @@ -67,6 +67,7 @@ table_biomass_abundance_catch <- function( method = "sum", module = NULL, label = NULL, + model = NULL, make_rda = FALSE, tables_dir = getwd() ) { @@ -82,6 +83,9 @@ table_biomass_abundance_catch <- function( biomass_abundance_catch.abundance.units <- NA biomass_abundance_catch.catch.units <- NA + # Do this so that we don't have to repeatedly choose the same model + selected_model <- model + # Aiming for totals # iterate through label_names lab_list <- purrr::map( @@ -95,9 +99,12 @@ table_biomass_abundance_catch <- function( geom = "line", era = "time", module = module, + model = selected_model[1], scale_amount = 1, - interactive = interactive + interactive = interactive, + allow_multiple_models = FALSE ) + selected_model <<- unique(filtered_data$model) uncertainty_label <- ifelse( is.na(unique(filtered_data$uncertainty_label)), @@ -235,7 +242,10 @@ table_biomass_abundance_catch <- function( if (exists("selected_module")) { rm(selected_module, envir = .GlobalEnv) + rm(selected_model, envir = .GlobalEnv) } final } + +# table_biomass_abundance_catch(result) diff --git a/R/table_index.R b/R/table_index.R index 9e41058c..1f4129f7 100644 --- a/R/table_index.R +++ b/R/table_index.R @@ -54,6 +54,7 @@ table_index <- function( group = NULL, method = "sum", module = NULL, + model = NULL, label = NULL, digits = 2, make_rda = FALSE, @@ -69,8 +70,10 @@ table_index <- function( geom = "line", era = era, module = module, + model = model, scale_amount = 1, - interactive = interactive + interactive = interactive, + allow_multiple_models = FALSE ) |> dplyr::mutate( estimate = round(as.numeric(estimate), digits = digits), @@ -162,5 +165,10 @@ table_index <- function( ) } + if (exists("selected_module")) { + rm(selected_module, envir = .GlobalEnv) + rm(selected_model, envir = .GlobalEnv) + } + final -} +} \ No newline at end of file diff --git a/R/table_landings.R b/R/table_landings.R index 98ecf2fc..24ee9ae4 100644 --- a/R/table_landings.R +++ b/R/table_landings.R @@ -62,6 +62,7 @@ table_landings <- function( group = NULL, method = "sum", module = NULL, + model = NULL, label = NULL, digits = 2, scale_amount = 1, @@ -81,8 +82,10 @@ table_landings <- function( geom = "line", era = era, module = module, + model = NULL, scale_amount = scale_amount, - interactive = interactive + interactive = interactive, + allow_multiple_models = FALSE ) |> dplyr::mutate(estimate = round(as.numeric(estimate), digits = digits)) |> dplyr::mutate(uncertainty = round(as.numeric(uncertainty), digits = digits)) @@ -192,3 +195,4 @@ table_landings <- function( final } + diff --git a/R/table_projections.R b/R/table_projections.R index b18c429a..b9b45284 100644 --- a/R/table_projections.R +++ b/R/table_projections.R @@ -37,6 +37,7 @@ table_projections <- function( spawning_biomass_label = NULL, interactive = TRUE, module = NULL, + model = NULL, make_rda = FALSE, tables_dir = getwd() ) { @@ -59,6 +60,8 @@ table_projections <- function( "fishing_mortality" = "fishing_mortality" ) + selected_model <- model + # iterate through 3 label names lab_list <- purrr::map( names(named_vec), @@ -70,11 +73,24 @@ table_projections <- function( geom = "line", era = "fore", module = module, + model = selected_model, scale_amount = 1, - interactive = interactive + interactive = interactive, + allow_multiple_models = FALSE ) |> - dplyr::mutate(estimate = ifelse(x != "fishing_mortality", round(as.numeric(estimate), digits = 0), round(as.numeric(estimate), digits = 4))) |> - dplyr::mutate(uncertainty = round(as.numeric(uncertainty), digits = 2)) + dplyr::mutate( + estimate = if(x != "fishing_mortality"){ + round(as.numeric(estimate), digits=0) + }else{ + round(as.numeric(estimate), digits = 4) + } + ) |> + # estimate = ifelse(x != "fishing_mortality", round(as.numeric(estimate), digits = 0), round(as.numeric(estimate), digits = 4))) |> + dplyr::mutate(uncertainty = round(as.numeric(uncertainty), digits = 2)) |> + dplyr::distinct() # only preserve unique rows + + selected_model <<- unique(filtered_data$model) + uncertainty_label <- ifelse( is.na(unique(filtered_data$uncertainty_label)), "Uncertainty", @@ -170,6 +186,7 @@ table_projections <- function( if (exists("selected_module")) { rm(selected_module, envir = .GlobalEnv) + rm(selected_model, envir = .GlobalEnv) } final diff --git a/R/table_total_catch.R b/R/table_total_catch.R index 7965aa7a..c5283f89 100644 --- a/R/table_total_catch.R +++ b/R/table_total_catch.R @@ -44,6 +44,7 @@ table_total_catch <- function( era = NULL, interactive = TRUE, module = NULL, + model = NULL, scale_amount = 1, digits = 2, make_rda = FALSE, @@ -63,8 +64,10 @@ table_total_catch <- function( geom = "line", era = era, module = module, + model = model, scale_amount = scale_amount, - interactive = interactive + interactive = interactive, + allow_multiple_models = FALSE ) # Check if there is any data and if all labels contain "catchability", not "catch" @@ -201,6 +204,7 @@ table_total_catch <- function( if (exists("selected_module")) { rm(selected_module, envir = .GlobalEnv) + rm(selected_model, envir = .GlobalEnv) } final diff --git a/R/utils_plot.R b/R/utils_plot.R index cfb47702..7f2e00b1 100644 --- a/R/utils_plot.R +++ b/R/utils_plot.R @@ -675,6 +675,9 @@ cap_first_letter <- function(s) { #' @inheritParams plot_spawning_biomass #' @param label_name String. Name of the label used to filter #' the data. +#' @param allow_multiple_models Logical. Whether to allow multiple models. +#' +#' Default: TRUE #' #' @returns a data frame that is preformatted for plotting with ggplot2. #' @export @@ -682,18 +685,40 @@ cap_first_letter <- function(s) { #' @examples #' \dontrun{ #' filter_data(dat, "biomass", "line", group = "fleet") +#' filter_data( +#' dat, +#' label = "biomass", +#' geom = "line", +#' module="derived_quants", +#' model=NULL, +#' allow_multiple_models=FALSE # can only select one model to filter by +#' ) #' } filter_data <- function( dat, label_name, module = NULL, + model = NULL, era = NULL, geom, group = NULL, facet = NULL, scale_amount = 1, - interactive = TRUE + interactive = TRUE, + allow_multiple_models = TRUE ) { + + # Check if there are multiple module_names present + model_select <- filter_interactive( + dat, + column_name="model", + column_value=model, + interactive=interactive, + allow_multiple_selection = allow_multiple_models + ) + dat <- model_select$plot_data + selected_model <<- model_select$selected + # TODO: add method to filter by units once added into the converter # TODO: add option to scale data # Replace all spaces with underscore if not in proper format @@ -775,57 +800,16 @@ filter_data <- function( } # Check if there are multiple module_names present - if (length(unique(plot_data$module_name)) > 1) { - module_names <- unique(plot_data$module_name) - if (!is.null(module)) { - plot_data <- plot_data |> - dplyr::filter( - module_name %in% module - ) - # export module to environment for use with key quantity calc - selected_module <<- module - } else { - cli::cli_alert_warning("Multiple module names found in data. \n") - options <- c() - for (i in seq_along(module_names)) { - # options <- paste0(options, " ", i, ") ", unique(plot_data$module_name)[i], "\n") - options[i] <- paste0(module_names[i]) - } - if (interactive()) { - if (interactive) { - selected <- utils::select.list( - options, - multiple = TRUE, - title = "Select one or more of the following module names" - ) - question1 <- if (length(selected) == 0 || identical(selected, "")) { - options[1] - } else { - selected - } - # use <<- to export module to environment for use with key quantity calc - selected_module <<- intersect(module_names, question1) - if (length(selected_module) < 1) { - selected_module <<- module_names[1] - } - } else { - # use <<- to export module to environment for use with key quantity calc - selected_module <<- module_names[1] - cli::cli_alert_info("Selection bypassed. Filtering by {selected_module}.") - } - } else { - # use <<- to export module to environment for use with key quantity calc - selected_module <<- module_names[1] - cli::cli_alert_info(glue::glue("Environment not interactive. Selecting {selected_module}.")) - } - if (length(selected_module) > 0) { - plot_data <- plot_data |> - dplyr::filter( - module_name %in% selected_module - ) - } - } - } + module_select <- filter_interactive( + plot_data, + column_name="module_name", + column_value=module, + interactive=interactive, + allow_multiple_selection = TRUE + ) + plot_data <- module_select$plot_data + selected_module <<- module_select$selected + # TODO: add lines to summarize final data for selected grouping and or facet if (geom == "area") { plot_data <- dplyr::mutate( @@ -1231,3 +1215,111 @@ add_reference_line <- function( } # close if ref_line NULL ref_lines_list } + + +#' Filter plot data interactively +#' +#' Allows user to interactively select values from those available +#' to filter their data by. +#' +#' @param dat data.frame. A tibble or named list of tibbles (input as `list()`) +#' returned from \link[stockplotr]{convert_output}. +#' +#' @param column_name String. Name of the column to allow interactive filtering for. +#' +#' @param column_value String. Value of the column to filter by. If NULL, interactive +#' selection will be enabled. +#' +#' Default: NULL +#' +#' @param interactive Logical. indicate whether the environment is interactive. +#' +#' Default: TRUE +#' +#' @param allow_multiple_selection Logical. Whether to allow the selection of multiple inputs. +#' +#' Default: FALSE +#' +#' @return List. filtered data.frame (`plot_data`) and selected option(`selected`). +#' +#' @examples +#' \dontrun{ +#' filter_interactive( +#' dat = example_dat, +#' column_name = "model", +#' column_value = NULL, +#' allow_multiple_selection = TRUE # allow selecting multiple models +#' ) +#' } +filter_interactive <- function( + dat, + column_name, + column_value = NULL, + interactive = TRUE, + allow_multiple_selection = TRUE +){ + + pretty_columns <- c("module_name"="module", "model"="model") + + plot_dat <- dat + selected <- unique(dat[[column_name]]) + if(length(unique(dat[[column_name]])) > 1){ + available_names <- unique(dat[[column_name]]) + if(!is.null(column_value)){ + if(length(column_value) > 1 && !allow_multiple_selection){ + cli::cli_alert_danger("Multiple {pretty_columns[column_name]}s provided, but only 1 allowed. Defaulting to first available {pretty_columns[column_name]} name: {available_names[1]}.") + column_value <- available_names[1] + } + plot_dat <- dat |> dplyr::filter(.data[[column_name]] %in% column_value) + selected <- column_value + }else{ + cli::cli_alert_warning("Multiple {pretty_columns[column_name]}s found in data. \n") + options <- c() + for (i in seq_along(available_names)) { + # options <- paste0(options, " ", i, ") ", unique(plot_data$module_name)[i], "\n") + options[i] <- paste0(available_names[i]) + } + + if(column_name == "model"){ + options <- c(options, "All") + } + + if(interactive()){ + if(interactive){ + selection <- utils::select.list( + options, + multiple=allow_multiple_selection, + title = glue::glue("Select one of the following {pretty_columns[column_name]} names") + ) + question1 <- if(length(selection)==0 || identical(selection, "")){ + options[1] + }else if("All" %in% selection){ + options[-length(options)] + }else{ + selection + } + + selected <- intersect(available_names, question1) + if (length(selected) < 1 || (length(selected) > 1 && !allow_multiple_selection)) { + selected <- available_names[1] + } + }else{ + selected <- available_names[1] + cli::cli_alert_info("Selection bypassed. Filtering by {selected}.") + } + }else{ + selected <- available_names[1] + cli::cli_alert_info(glue::glue("Environment not interactive. Selecting {selected}.")) + } + if (length(selected) > 0) { + plot_dat <- dat |> + dplyr::filter( + .data[[column_name]] %in% selected + ) + } + } + } + out <- list("plot_data"=plot_dat, "selected"=selected) + + return(out) +} diff --git a/man/filter_data.Rd b/man/filter_data.Rd index 4884d58e..68e661da 100644 --- a/man/filter_data.Rd +++ b/man/filter_data.Rd @@ -8,12 +8,14 @@ filter_data( dat, label_name, module = NULL, + model = NULL, era = NULL, geom, group = NULL, facet = NULL, scale_amount = 1, - interactive = TRUE + interactive = TRUE, + allow_multiple_models = TRUE ) } \arguments{ @@ -34,6 +36,14 @@ 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{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{era}{String. Era of data. Default: "time" @@ -67,6 +77,10 @@ Default: 1} \item{interactive}{Logical. TRUE/FALSE; indicate whether the environment is interactive. Default: \code{FALSE}} + +\item{allow_multiple_models}{Logical. Whether to allow multiple models. + +Default: TRUE} } \value{ a data frame that is preformatted for plotting with ggplot2. @@ -77,5 +91,13 @@ Filter data for input into aesthetics for ggplot2 \examples{ \dontrun{ filter_data(dat, "biomass", "line", group = "fleet") +filter_data( + dat, + label = "biomass", + geom = "line", + module="derived_quants", + model=NULL, + allow_multiple_models=FALSE # can only select one model to filter by +) } } diff --git a/man/filter_interactive.Rd b/man/filter_interactive.Rd new file mode 100644 index 00000000..cc6944ff --- /dev/null +++ b/man/filter_interactive.Rd @@ -0,0 +1,50 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils_plot.R +\name{filter_interactive} +\alias{filter_interactive} +\title{Filter plot data interactively} +\usage{ +filter_interactive( + dat, + column_name, + column_value = NULL, + interactive = TRUE, + allow_multiple_selection = TRUE +) +} +\arguments{ +\item{dat}{data.frame. A tibble or named list of tibbles (input as \code{list()}) +returned from \link[stockplotr]{convert_output}.} + +\item{column_name}{String. Name of the column to allow interactive filtering for.} + +\item{column_value}{String. Value of the column to filter by. If NULL, interactive +selection will be enabled. + +Default: NULL} + +\item{interactive}{Logical. indicate whether the environment is interactive. + +Default: TRUE} + +\item{allow_multiple_selection}{Logical. Whether to allow the selection of multiple inputs. + +Default: FALSE} +} +\value{ +List. filtered data.frame (\code{plot_data}) and selected option(\code{selected}). +} +\description{ +Allows user to interactively select values from those available +to filter their data by. +} +\examples{ +\dontrun{ + filter_interactive( + dat = example_dat, + column_name = "model", + column_value = NULL, + allow_multiple_selection = TRUE # allow selecting multiple models + ) +} +} diff --git a/man/plot_abundance_at_age.Rd b/man/plot_abundance_at_age.Rd index 3dd4ff31..bf6188e2 100644 --- a/man/plot_abundance_at_age.Rd +++ b/man/plot_abundance_at_age.Rd @@ -11,6 +11,7 @@ plot_abundance_at_age( scale_amount = 1, proportional = TRUE, module = NULL, + model = NULL, interactive = TRUE, make_rda = FALSE, figures_dir = getwd() @@ -54,6 +55,14 @@ 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{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{interactive}{A logical value indicating if the environment is interactive. Default: \code{FALSE}} diff --git a/man/plot_biomass.Rd b/man/plot_biomass.Rd index e0881fa3..416079d8 100644 --- a/man/plot_biomass.Rd +++ b/man/plot_biomass.Rd @@ -13,6 +13,7 @@ plot_biomass( era = NULL, unit_label = NULL, module = NULL, + model = NULL, scale_amount = 1, relative = FALSE, make_rda = FALSE, @@ -75,6 +76,14 @@ 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{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \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 diff --git a/man/plot_biomass_at_age.Rd b/man/plot_biomass_at_age.Rd index 66e19b6d..99e15c73 100644 --- a/man/plot_biomass_at_age.Rd +++ b/man/plot_biomass_at_age.Rd @@ -11,6 +11,7 @@ plot_biomass_at_age( scale_amount = 1, proportional = TRUE, module = NULL, + model = NULL, interactive = TRUE, make_rda = FALSE, figures_dir = getwd() @@ -52,6 +53,14 @@ 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{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{interactive}{Logical. TRUE/FALSE; indicate whether the environment in which the function is operating is interactive. This bypasses some options for filtering when preparing data for the plot. diff --git a/man/plot_catch_at_age.Rd b/man/plot_catch_at_age.Rd index 8044bc76..87a0202b 100644 --- a/man/plot_catch_at_age.Rd +++ b/man/plot_catch_at_age.Rd @@ -13,6 +13,7 @@ plot_catch_at_age( proportional = TRUE, interactive = TRUE, module = NULL, + model = NULL, make_rda = FALSE, figures_dir = getwd() ) @@ -65,6 +66,14 @@ 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{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{make_rda}{Logical. TRUE/FALSE; indicate whether to produce an .rda file containing a list with the figure/table, caption, and alternative text (if figure). If TRUE, the .rda will be exported to the folder indicated in the argument "rda_dir". diff --git a/man/plot_discard.Rd b/man/plot_discard.Rd index 7160d03f..bbf9b76b 100644 --- a/man/plot_discard.Rd +++ b/man/plot_discard.Rd @@ -15,6 +15,7 @@ plot_discard( scale_amount = 1, interactive = TRUE, module = NULL, + model = NULL, predicted = TRUE, interval = 0.95, tolerance = 0.001, @@ -88,6 +89,13 @@ 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{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} \item{predicted}{Logical. TRUE (Default) or FALSE; show the discards predicted by the model as lines, with the observed discards as points, to show the fit to the observed discards. The predicted discards are shown diff --git a/man/plot_fishing_mortality.Rd b/man/plot_fishing_mortality.Rd index c0c449b1..ecc4d0a4 100644 --- a/man/plot_fishing_mortality.Rd +++ b/man/plot_fishing_mortality.Rd @@ -12,6 +12,7 @@ plot_fishing_mortality( ref_line = "msy", era = NULL, module = NULL, + model = NULL, make_rda = FALSE, figures_dir = getwd(), interactive = TRUE, @@ -71,6 +72,14 @@ 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{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \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". diff --git a/man/plot_index.Rd b/man/plot_index.Rd index d7a28a1f..a21c24cb 100644 --- a/man/plot_index.Rd +++ b/man/plot_index.Rd @@ -11,6 +11,7 @@ plot_index( facet = NULL, interactive = TRUE, module = NULL, + model = NULL, focus = NULL, interval = 0.95, log = FALSE, @@ -52,6 +53,14 @@ 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{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{focus}{Character vector. Column name or names used to filter data. (i.e. select names of fleets to zoom into the plot). Default = NULL} diff --git a/man/plot_landings.Rd b/man/plot_landings.Rd index 2a444005..2134758b 100644 --- a/man/plot_landings.Rd +++ b/man/plot_landings.Rd @@ -14,6 +14,7 @@ plot_landings( era = NULL, scale_amount = 1, module = NULL, + model = NULL, interactive = TRUE, predicted = TRUE, interval = 0.95, @@ -84,6 +85,14 @@ 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{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{interactive}{Logical. TRUE/FALSE; indicate whether the environment is interactive. Default: \code{FALSE}} diff --git a/man/plot_natural_mortality.Rd b/man/plot_natural_mortality.Rd index 0e6bddf5..dd719185 100644 --- a/man/plot_natural_mortality.Rd +++ b/man/plot_natural_mortality.Rd @@ -11,6 +11,7 @@ plot_natural_mortality( era = NULL, interactive = TRUE, module = NULL, + model = NULL, make_rda = FALSE, figures_dir = getwd(), ... @@ -52,6 +53,14 @@ 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{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \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". diff --git a/man/plot_recruitment.Rd b/man/plot_recruitment.Rd index b7b5b170..f4bb2355 100644 --- a/man/plot_recruitment.Rd +++ b/man/plot_recruitment.Rd @@ -13,6 +13,7 @@ plot_recruitment( facet = NULL, interactive = TRUE, module = NULL, + model = NULL, make_rda = FALSE, figures_dir = getwd() ) @@ -64,6 +65,14 @@ 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{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \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". diff --git a/man/plot_recruitment_deviations.Rd b/man/plot_recruitment_deviations.Rd index 80369856..10011862 100644 --- a/man/plot_recruitment_deviations.Rd +++ b/man/plot_recruitment_deviations.Rd @@ -7,6 +7,7 @@ plot_recruitment_deviations( dat, module = NULL, + model = NULL, era = NULL, interactive = TRUE, make_rda = FALSE, @@ -29,6 +30,14 @@ 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{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{era}{String. Era of data. Default: "time" diff --git a/man/plot_selectivity.Rd b/man/plot_selectivity.Rd index 4a70ccba..4b800bdd 100644 --- a/man/plot_selectivity.Rd +++ b/man/plot_selectivity.Rd @@ -11,6 +11,7 @@ plot_selectivity( facet = NULL, interactive = TRUE, module = NULL, + model = NULL, make_rda = FALSE, figures_dir = getwd(), ... @@ -50,6 +51,14 @@ 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{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \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". diff --git a/man/plot_spawning_biomass.Rd b/man/plot_spawning_biomass.Rd index ab616183..933c4b6e 100644 --- a/man/plot_spawning_biomass.Rd +++ b/man/plot_spawning_biomass.Rd @@ -14,6 +14,7 @@ plot_spawning_biomass( era = NULL, lbs = lifecycle::deprecated(), module = NULL, + model = NULL, scale_amount = 1, relative = FALSE, make_rda = FALSE, @@ -89,6 +90,14 @@ 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{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \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 diff --git a/man/plot_spr.Rd b/man/plot_spr.Rd index a329fdfd..fb577c25 100644 --- a/man/plot_spr.Rd +++ b/man/plot_spr.Rd @@ -12,6 +12,7 @@ plot_spr( ref_line = "target", era = "time", module = NULL, + model = NULL, interactive = TRUE, make_rda = FALSE, figures_dir = getwd(), @@ -72,6 +73,14 @@ 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{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{interactive}{Logical. TRUE/FALSE; indicate whether the environment is interactive. Default: \code{FALSE}} diff --git a/man/plot_stock_recruitment.Rd b/man/plot_stock_recruitment.Rd index c9d11886..16a52b5c 100644 --- a/man/plot_stock_recruitment.Rd +++ b/man/plot_stock_recruitment.Rd @@ -11,6 +11,7 @@ plot_stock_recruitment( interactive = TRUE, era = NULL, module = NULL, + model = NULL, scale_amount = 1, make_rda = FALSE, figures_dir = getwd() @@ -52,6 +53,14 @@ 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{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \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 diff --git a/man/table_biomass_abundance_catch.Rd b/man/table_biomass_abundance_catch.Rd index e289ff3f..e0f8df67 100644 --- a/man/table_biomass_abundance_catch.Rd +++ b/man/table_biomass_abundance_catch.Rd @@ -15,6 +15,7 @@ table_biomass_abundance_catch( method = "sum", module = NULL, label = NULL, + model = NULL, make_rda = FALSE, tables_dir = getwd() ) @@ -77,6 +78,14 @@ in this ordered list: "landings_weight", "landings_numbers", "landings_expected Default: NULL} +\item{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \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". diff --git a/man/table_index.Rd b/man/table_index.Rd index 96a8327a..f986ba31 100644 --- a/man/table_index.Rd +++ b/man/table_index.Rd @@ -11,6 +11,7 @@ table_index( group = NULL, method = "sum", module = NULL, + model = NULL, label = NULL, digits = 2, make_rda = FALSE, @@ -56,6 +57,14 @@ 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{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{label}{String. The label that will be chosen from the input file. If unspecified, the function will search the "label" column and use the first matching label in this ordered list: "index_weight", "index_numbers", "index_expected", diff --git a/man/table_landings.Rd b/man/table_landings.Rd index d0f1989a..509a16f4 100644 --- a/man/table_landings.Rd +++ b/man/table_landings.Rd @@ -12,6 +12,7 @@ table_landings( group = NULL, method = "sum", module = NULL, + model = NULL, label = NULL, digits = 2, scale_amount = 1, @@ -62,6 +63,14 @@ 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{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \item{label}{String or vector of strings. The labels in the "label" column of \code{dat} to tabulate (e.g., "landings_predicted_weight"). If unspecified, the observed landings are used: the first of "landings_observed", diff --git a/man/table_projections.Rd b/man/table_projections.Rd index b3e3e049..b122c685 100644 --- a/man/table_projections.Rd +++ b/man/table_projections.Rd @@ -10,6 +10,7 @@ table_projections( spawning_biomass_label = NULL, interactive = TRUE, module = NULL, + model = NULL, make_rda = FALSE, tables_dir = getwd() ) @@ -41,6 +42,14 @@ 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{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \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". diff --git a/man/table_total_catch.Rd b/man/table_total_catch.Rd index 5026642f..ea656a1b 100644 --- a/man/table_total_catch.Rd +++ b/man/table_total_catch.Rd @@ -10,6 +10,7 @@ table_total_catch( era = NULL, interactive = TRUE, module = NULL, + model = NULL, scale_amount = 1, digits = 2, make_rda = FALSE, @@ -45,6 +46,14 @@ 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{model}{Character vector. (Optional) Model name found in \code{dat$model}. +If selecting >1 model, place them in a vector like c("model1", "model2"). + +Default: NULL + +If the interactive and >1 model is found, user will select the +model in the console. @seealso \code{\link[=filter_data]{filter_data()}}} + \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 diff --git a/tests/testthat/test-plot_abundance_at_age.R b/tests/testthat/test-plot_abundance_at_age.R index 853f6563..140e23ae 100644 --- a/tests/testthat/test-plot_abundance_at_age.R +++ b/tests/testthat/test-plot_abundance_at_age.R @@ -171,7 +171,7 @@ test_that("plot_abundace_at_age generates plots for multiple models", { "model2" = r4ss::SS_output(test_path("fixtures", "ss3_models", "models", "Hake_2019_semi-parametric_selex")) )) - expect_no_error(plt <- plot_abundance_at_age(dat, module="natage")) + expect_no_error(plt <- plot_abundance_at_age(dat, module="natage", model=c("model1", "model2"))) expect_s3_class(plt, "gg") p <- ggplot2::ggplot_build(plt) diff --git a/tests/testthat/test-plot_spawning_biomass.R b/tests/testthat/test-plot_spawning_biomass.R index f12c97c6..8f26e1c5 100644 --- a/tests/testthat/test-plot_spawning_biomass.R +++ b/tests/testthat/test-plot_spawning_biomass.R @@ -63,7 +63,7 @@ test_that("plot_spawning_biomass generates plots for multiple models", { "model2" = r4ss::SS_output(test_path("fixtures", "ss3_models", "models", "Empirical_Wtatage_Age_Selex")) )) - expect_no_error(plt <- plot_spawning_biomass(dat, module="derived_quants")) + expect_no_error(plt <- plot_spawning_biomass(dat, module="derived_quants", model=c("model1", "model2"))) expect_s3_class(plt, "gg") p <- ggplot2::ggplot_build(plt) diff --git a/tests/testthat/test-utils_plot.R b/tests/testthat/test-utils_plot.R index 5e633c51..6457ba2d 100644 --- a/tests/testthat/test-utils_plot.R +++ b/tests/testthat/test-utils_plot.R @@ -62,7 +62,8 @@ test_that("filter_data handles data frames", { dat = mm_dat, label_name = "biomass", geom = "point", - interactive = FALSE + interactive = FALSE, + model = c("model_one", "model_two") ) expect_setequal(unique(filtered_list$model), c("model_one", "model_two")) expect_setequal(unique(filtered_list$group_var), c("model_one", "model_two"))