plot_SSB()
View source ↗On this page
Plot total spawning stock biomass, spawning stock biomass at length or at age over time, with optional 95% intervals and an optional series from maturity at age.
Usage
plot_SSB(
model_result,
line_size = NULL,
line_color = NULL,
line_type = "solid",
se = FALSE,
se_color = NULL,
se_alpha = NULL,
type = c("SSB", "SBL", "SBA"),
facet_ncol = NULL,
facet_scales = "free",
return_data = FALSE,
title = NULL,
xlab = NULL,
ylab = NULL,
font_family = NULL,
title_size = NULL,
axis_title_size = NULL,
axis_text_size = NULL,
strip_text_size = NULL,
legend_text_size = NULL,
x_breaks = NULL,
base_theme = NULL,
title_hjust = NULL,
interval = NULL,
maturity_at_age = NULL,
weight_at_age = NULL
)
Arguments
| Argument | Default | Description |
|---|---|---|
model_result | required | A fit from |
line_size | NULL | Numeric or NULL. Line width. NULL inherits the global line_size setting (1 under the default style, 1.5 under "classic"). While that setting keeps the value of the style, facets of more than four panels draw thinner lines. |
line_color | NULL | Character or NULL. NULL inherits the global stock_color setting, or line_color when that is NULL. |
line_type | "solid" | Character. Line type, such as "solid" or "dashed". Default "solid". |
se | FALSE | Logical. Draw approximate 95% intervals from the standard errors. Default FALSE. |
se_color | NULL | Character or NULL. NULL takes the color of the line, or the global se_color when it was set to a color other than the band color of the palette. |
se_alpha | NULL | Numeric or NULL. Transparency of the interval band. NULL inherits the global se_alpha setting (0.3 under the default style, 0.2 under "classic"). |
type | c("SSB", "SBL", "SBA") | Character. "SSB" (total), "SBL" (at length) or "SBA" (at age). Default "SSB". Letter case does not matter, so "sbl" gives the same as "SBL". |
facet_ncol | NULL | Integer or NULL. Number of columns of panels. NULL chooses it from the number of panels, for example 5 × 3 for 15 panels and 6 × 4 for 23. |
facet_scales | "free" | Character. Axis scales of the panels, "fixed", "free", "free_x" or "free_y". Letter case does not matter. |
return_data | FALSE | Logical. TRUE returns a list with the plot and the plotted data (see Value). Default FALSE. |
title | NULL | NULL (default) draws the default title, FALSE, NA or "" draws no title, and a character string draws that string; see |
xlab | NULL | Character or NULL. Label of the x axis. NULL uses the global theme setting. |
ylab | NULL | Character or NULL. Label of the y axis. NULL uses the global theme setting. |
font_family | NULL | Character or NULL. Font family of the text, which must be installed on the computer. NULL uses the global theme setting (default "sans"). |
title_size | NULL | Numeric or NULL. Size of the plot title in pt. NULL uses the global theme setting (default 14). |
axis_title_size | NULL | Numeric or NULL. Size of the axis titles in pt. NULL uses the global theme setting (default 12). |
axis_text_size | NULL | Numeric or NULL. Size of the axis tick labels in pt. NULL uses the global theme setting (default 10). |
strip_text_size | NULL | Numeric or NULL. Size of the panel labels in pt. NULL uses the global theme setting (default 10). |
legend_text_size | NULL | Numeric or NULL. Size of the legend text in pt. NULL uses the global theme setting (default 10). |
x_breaks | NULL | Numeric vector or NULL. Positions of the x-axis breaks. NULL inherits the global x_breaks setting when at least one of its values lies on this axis; otherwise the breaks are chosen automatically. |
base_theme | NULL | Character or NULL. Name of the base ggplot2 theme, such as "bw", "minimal" or "theme_bw". NULL uses the global theme setting. Letter case does not matter. |
title_hjust | NULL | Numeric or NULL. Horizontal position of the title, 0 for left, 0.5 for centered and 1 for right. NULL uses the global theme setting. |
interval | NULL | Character or NULL. The 95% interval drawn when |
maturity_at_age | NULL | NULL (default) or the proportion mature at age, given as |
weight_at_age | NULL | NULL or mean weight at age, as |
Value
A ggplot object, or with return_data = TRUE a list with plot and the plotted values data.
Details
The maturity and weight tables convert numbers to spawning stock biomass.
Titles, axis labels, time-axis breaks (x_breaks) and expansion (x_expand) inherit the global theme settings. The title keys are SSB, SBL and SBA, with _se appended for interval plots, and the axis labels are xlab$year and ylab$ssb. A title, xlab, ylab, typography or line argument given in the call takes priority.
ALSCL reports SSB, SBL and SBA with standard errors. ACL reports SSB with standard errors and SBL estimates only; SBA is unavailable. A missing quantity or a missing standard error stops the function with an error. Group-by-time matrices are read by position. Their row and column names are only for display; the plotted coordinates come from model_result$year and model_result$len_label. With se = TRUE, every plotted value needs a finite estimate and a finite, nonnegative standard error, otherwise the function stops; use se = FALSE to plot the estimates alone.
A panel with only one estimate is drawn as a point. With se = TRUE an error bar shows its 95% interval (lognormal by default; see interval), because a band through one point has no width. The point size follows the global point_size setting; the point takes the color of the line and the error bar the color of the interval. Grid lines follow the grid setting of acl_theme_set().
The models calculate SSB from the proportion mature at length. With maturity_at_age, the figure adds the SSB that ssb_at_age() calculates from maturity at age (the sum over age classes of biomass at age multiplied by the proportion mature at age), for a comparison with an age-based assessment that uses a maturity ogive by age. The interval of se = TRUE belongs to the SSB of the model; the added series has no standard error. Both series are in the unit of model biomass, whose level depends on the assumed survey catchability. Without maturity_at_age only the SSB of the model is drawn.
With se = TRUE the default interval is lognormal. The log of a positive estimate is treated as normal with standard error SE / estimate (delta method), so the bounds are exp(log(estimate) +/- 1.96 * SE / estimate) and cannot fall below zero. The estimate and its standard error (SE) are those stored in model_result$est_std. interval = "wald", or acl_theme_set(interval = "wald"), gives the symmetric interval estimate +/- 1.96 * SE. With the lognormal interval, an estimate of exactly zero, such as spawning stock biomass in a length bin with no mature fish, gets the Wald upper bound and a lower bound of zero. Neither interval corrects for a poorly determined fit; inspect the fit diagnostics before using the intervals.
Age panels are labelled with the fitted ages in model_result$age. The oldest age class is a plus group and is marked with a plus sign, for example "Age 15+". A fit without age metadata gets the position labels "Age bin 1", "Age bin 2" and so on.
Additional details from R help
ALSCL reports SSB, SBL and SBA with standard errors. ACL reports SSB
with standard errors and SBL estimates only; SBA is unavailable. A quantity
or standard error that the fit does not report is an error. With se = TRUE
the default interval is lognormal:
exp(log(estimate) +/- 1.96 * SE / estimate), where the estimate and
its standard error (SE) are those stored in model_result$est_std.
It cannot fall below zero. interval = "wald", or
acl_theme_set(interval = "wald"), gives the symmetric interval
estimate +/- 1.96 * SE. An estimate that is
exactly zero, such as spawning stock biomass in a length bin with no
mature fish, keeps the Wald upper bound, and its lower bound is set to
zero. Check the numerical checks of the fit before
using the intervals.
The models calculate SSB from the proportion mature at length.
With maturity_at_age, the figure adds the SSB calculated by
ssb_at_age() as the sum over age classes of biomass at age multiplied
by the proportion mature at age, for comparison with an age-based
assessment that uses a maturity ogive by age. The confidence interval of
se = TRUE belongs to the SSB of the model; the added series has no
standard error. Both series are in the unit of model biomass, whose
level depends on the assumed survey catchability.
Age panels are labelled with the fitted ages in model_result$age.
The oldest age class is a plus group and is marked with a plus sign, for
example "Age 15+". Results saved without age metadata keep the position
labels "Age bin 1", "Age bin 2" and so on.
Titles, axis labels, time-axis breaks and expansion inherit
acl_theme_set(). Title keys are SSB, SBL and SBA;
append _se for interval plots.
Axis labels use xlab$year and ylab$ssb.
A title, xlab or ylab given in the call replaces the
theme label, and the typography arguments replace the corresponding theme settings.
A group or panel with only one estimate is drawn as a point. When intervals are requested, its ribbon is replaced by an error bar. The point uses the global point_size setting and the estimate's line color.
With the global y_zero setting (TRUE under the default style) the y axis of every panel starts at zero.
Examples
Run the setup before the example. Fitting examples require an R-compatible C++ toolchain; simulation and export examples may write files.
Example setup
library(ALSCL)
library(ggplot2)
library(patchwork)
data("YTF_example")
x <- YTF_example
inputs <- x[c("data.CatL", "data.wgt", "data.mat")]
dat <- x$data.CatL
a <- run_acl(x, silent = TRUE)
b <- run_alscl(x, silent = TRUE)
# Use objects defined above
plot_SSB(b, type = "SSB", se = TRUE, line_size = 0.6)

plot_SSB(b, se = TRUE, line_size = 0.6)