Plot observed and predicted discards

plot_discard(
  dat,
  geom = "line",
  group = NULL,
  facet = NULL,
  unit_label = NULL,
  era = NULL,
  lbs = FALSE,
  scale_amount = 1,
  interactive = TRUE,
  module = NULL,
  model = NULL,
  predicted = TRUE,
  interval = 0.95,
  tolerance = 0.001,
  make_rda = FALSE,
  figures_dir = getwd(),
  ...
)

Arguments

dat

Data frame or list. A tibble or named list of tibbles (input as list()) returned from convert_output.

If inputting a list of tibbles, the first tibble's reference point defined in ref_line is used to plot a reference line or calculate relative spawning biomass.

geom

String. How the discards are drawn. Default: "line". Options: "line" draws the predicted discards as lines (with intervals as ribbons) and the observed discards as points, or the observed discards as lines when there are no predicted discards to show; "bar" draws the observed discards of each fleet as side-by-side bars for each year (pass position = "stack" to stack them); "point" draws the observed discards as points.

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

facet

Character vector. Column name or names used for faceting.

Default: NULL

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: NULL

era

String. Era of data.

Default: "time"

Options: "early", "time", "fore" (forecast), or NULL (all data)

lbs

[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'. – Deprecate

Default: FALSE

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

interactive

Logical. TRUE/FALSE; indicate whether the environment is interactive.

Default: FALSE

module

Character vector. (Optional) Module name found in 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 filter_data()

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()

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 only when they differ from the observed discards by more than tolerance.

interval

Number. Coverage of the intervals drawn as ribbons around the lines (e.g., 0.95), based on the observation error of the discards. NULL draws no intervals. Default: 0.95

tolerance

Number. The predicted discards are shown only when the range of their differences from the observed discards is more than this proportion of the largest observed discards, as in plot_landings(). Models that fit the discards almost exactly otherwise show two identical series. Use 0 to always show the predicted discards. Default: 0.001 (0.1%)

make_rda

Logical. TRUE/FALSE; indicate whether to save the object and make an automated caption and alternative text in the form of an rda object. If TRUE, the rda will be exported to the folder indicated in the argument "figures_dir".

Default: FALSE.

figures_dir

Path. Path to the "figures" folder.

Default: getwd()

The folder is created within the path if it does not exist.

...

Arguments passed to the geom that draws the main series (ggplot2::geom_line() for the predicted discards, ggplot2::geom_col() for bars, e.g., position = "stack").

Value

A ggplot showing discards over time, usually by fleet.

Details

The input is from an assessment model output file translated to a standardized output (convert_output). There are options to return a ggplot2 object or export an .rda object containing associated caption and alternative text for the figure.

When dat has observed and predicted discards ("discard_observed" and "discard_predicted") and predicted = TRUE, the predicted discards are drawn as lines in the color of each fleet, with the observed discards as points, for the fleets and years with observed discards, as in plot_landings(). Use facet = "fleet" to plot each fleet in its own panel. When the observed and predicted discards are the same (within tolerance), only the observed discards are drawn, as lines, with a message. Otherwise, the observed discards (or the first label starting with "discard") are drawn as lines.

The intervals are lognormal, from the log-scale standard error or the coefficient of variation of the discards, as in plot_index(). Around the predicted discards, they show the range in which observations are expected given the fit and the observation error; observed discards outside the ribbon are poorly fit. Discards with another type of uncertainty are drawn without intervals.

Note

All plotting functions automatically recognize indexing variables and will use them in groupings and/or facetting. @seealso process_data().

Examples

plot_discard(
  dat = stockplotr::example_data,
  unit_label = "fish",
  module = "DISCARD_OUTPUT"
)

# Fit to the discards: observed (points) and predicted (lines, with 95%
# intervals), one panel per fleet
plot_discard(
  dat = stockplotr::vermilion_snapper,
  facet = "fleet",
  interactive = FALSE
)
#> ! Multiple modules found in data. 
#> ℹ Environment not interactive. Selecting t.series.

# Observed discards of each fleet as stacked bars
plot_discard(
  dat = stockplotr::vermilion_snapper,
  geom = "bar",
  position = "stack",
  interactive = FALSE
)
#> ! Multiple modules found in data. 
#> ℹ Environment not interactive. Selecting t.series.