plot_recruitment()
View source ↗On this page
Plot the estimated recruitment over time, as bars or a line, with optional 95% intervals from the standard errors.
Usage
plot_recruitment(
model_result,
line_size = NULL,
line_color = NULL,
line_type = "solid",
se = FALSE,
se_color = NULL,
se_alpha = NULL,
se_type = NULL,
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,
geom = 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. Line or bar color. NULL inherits the global recruitment_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. Color of the ribbon or of error bars around a line. 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. Error bars on bars are dark grey with a light outline unless se_color is given. |
se_alpha | NULL | Numeric or NULL. Transparency of the interval ribbon; NULL inherits the global se_alpha setting (0.3 under the default style, 0.2 under "classic"). Error bars are opaque unless se_alpha is given. |
se_type | NULL | Character or NULL. Form of the interval, "ribbon" for a shaded band or "errorbar" for error bars. NULL (default) draws error bars on bars and a band around a line. 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 |
geom | NULL | Character or NULL. "bar" draws the series as bars 0.8 of a time step wide, with error bars when |
Value
A ggplot object, or with return_data = TRUE a list with plot and the plotted values data.
Details
Recruitment is drawn as bars under the default style, with dark grey error bars that have a light outline when se = TRUE, and as a line with a band under acl_theme_set(style = "classic"). geom = "bar" or geom = "line" chooses the form for one call, and se_type chooses error bars or a band.
Recruitment is the number of fish entering the youngest modelled age class. Its scale depends on the assumed survey catchability.
With se = TRUE, every time step 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.
Additional details from R help
With se = TRUE, the standard-error table must have one finite estimate and finite nonnegative standard error per model time step. Missing or invalid uncertainty is an error; use se = FALSE to plot the estimates alone.
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 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_recruitment(b, se = TRUE)

plot_recruitment(b, se = TRUE)