Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion R/plot_abundance_at_age.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -199,5 +199,10 @@ plot_abundance_at_age <- function(
dat
)
}

if (exists("selected_module")) {
rm(selected_module, envir = .GlobalEnv)
}

plot
}
8 changes: 4 additions & 4 deletions R/plot_biomass.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

}
5 changes: 5 additions & 0 deletions R/plot_biomass_at_age.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,10 @@ plot_biomass_at_age <- function(
dat
)
}

if (exists("selected_module")) {
rm(selected_module, envir = .GlobalEnv)
}

plot
}
9 changes: 7 additions & 2 deletions R/plot_catch_at_age.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
6 changes: 5 additions & 1 deletion R/plot_discard.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ plot_discard <- function(
scale_amount = scale_amount
)
}
# Output final plot

if (exists("selected_module")) {
rm(selected_module, envir = .GlobalEnv)
}

final
}
9 changes: 4 additions & 5 deletions R/plot_fishing_mortality.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 6 additions & 2 deletions R/plot_index.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#'
Expand Down Expand Up @@ -173,6 +173,10 @@ plot_index <- function(
dir = figures_dir
)
}
# Output final plot

if (exists("selected_module")) {
rm(selected_module, envir = .GlobalEnv)
}

plt
}
62 changes: 35 additions & 27 deletions R/plot_landings.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 <- ""
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -157,6 +161,10 @@ plot_landings <- function(
scale_amount = scale_amount
)
}
# Output final plot

if (exists("selected_module")) {
rm(selected_module, envir = .GlobalEnv)
}

plt
}
6 changes: 5 additions & 1 deletion R/plot_natural_mortality.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ plot_natural_mortality <- function(
dir = figures_dir
)
}
# Output final plot

if (exists("selected_module")) {
rm(selected_module, envir = .GlobalEnv)
}

final
}
1 change: 0 additions & 1 deletion R/plot_spawning_biomass.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion man/plot_abundance_at_age.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/plot_biomass.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/plot_biomass_at_age.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/plot_catch_at_age.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/plot_index.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions man/table_total_catch.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading