plot_abundance()
View source ↗On this page
Plot total abundance, abundance at age or abundance at length over time, with optional 95% intervals from the standard errors.
Usage
plot_abundance(
model_result,
line_size = NULL,
line_color = NULL,
line_type = "solid",
se = FALSE,
se_color = NULL,
se_alpha = NULL,
type = c("N", "NA", "NL"),
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
)
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("N", "NA", "NL") | Character. "N" (total), "NA" (at age) or "NL" (at length). Default "N". Letter case does not matter, so "na" gives the same as "NA". |
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 |
Value
A ggplot object, or with return_data = TRUE a list with plot and the plotted values data.
Details
The abundance estimates depend on the fixed survey catchability and the other model assumptions.
Titles, axis labels, time-axis breaks (x_breaks) and expansion (x_expand) inherit the global theme settings. The title keys are N, NA_ and NL, with _se appended for interval plots (NA_se for abundance at age), and the axis labels are xlab$year and ylab$abundance. A title, xlab, ylab, typography or line argument given in the call takes priority.
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().
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 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
Matrices by group and time step are read by position. Their row and column names are not used; model_result$year and model_result$len_label supply the plotted coordinates. With se = TRUE, the standard-error table must have one finite estimate and finite nonnegative standard error per plotted value. Missing or invalid uncertainty is an error; use se = FALSE to plot the estimates alone.
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), where the estimate and its standard error (SE) are those
stored in model_result$est_std. The bounds are
exp(log(estimate) +/- 1.96 * SE / estimate), so they 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 keeps the Wald upper bound,
and its lower bound is set to zero.
Neither interval makes up for a poorly determined fit, so check the
numerical checks of the fit 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+". 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 N, NA_ and NL;
append _se for interval plots (use NA_se for NA).
Axis labels use xlab$year and ylab$abundance.
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_abundance(b, type = "N", se = TRUE, line_size = 0.6)

plot_abundance(b, type = "N", se = TRUE, line_size = 0.6)