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

ArgumentDefaultDescription
model_resultrequired

A fit from run_acl() or run_alscl().

line_sizeNULL

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_colorNULL

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".

seFALSE

Logical. Draw approximate 95% intervals from the standard errors. Default FALSE.

se_colorNULL

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_alphaNULL

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_typeNULL

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_dataFALSE

Logical. TRUE returns a list with the plot and the plotted data (see Value). Default FALSE.

titleNULL

NULL (default) draws the default title, FALSE, NA or "" draws no title, and a character string draws that string; see acl_theme_set() for the default titles and the show_title setting.

xlabNULL

Character or NULL. Label of the x axis. NULL uses the global theme setting.

ylabNULL

Character or NULL. Label of the y axis. NULL uses the global theme setting.

font_familyNULL

Character or NULL. Font family of the text, which must be installed on the computer. NULL uses the global theme setting (default "sans").

title_sizeNULL

Numeric or NULL. Size of the plot title in pt. NULL uses the global theme setting (default 14).

axis_title_sizeNULL

Numeric or NULL. Size of the axis titles in pt. NULL uses the global theme setting (default 12).

axis_text_sizeNULL

Numeric or NULL. Size of the axis tick labels in pt. NULL uses the global theme setting (default 10).

strip_text_sizeNULL

Numeric or NULL. Size of the panel labels in pt. NULL uses the global theme setting (default 10).

legend_text_sizeNULL

Numeric or NULL. Size of the legend text in pt. NULL uses the global theme setting (default 10).

x_breaksNULL

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_themeNULL

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_hjustNULL

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.

intervalNULL

Character or NULL. The 95% interval drawn when se = TRUE. "lognormal" is exp(log(estimate) +/- 1.96 * SE / estimate) and stays above zero. "wald" is estimate +/- 1.96 * SE and can fall below zero. NULL inherits the global interval setting (default "lognormal"). Point estimates are the same for both. Letter case does not matter.

geomNULL

Character or NULL. "bar" draws the series as bars 0.8 of a time step wide, with error bars when se = TRUE; "line" draws a line, with a band when se = TRUE. NULL (default) follows the global bars setting, which gives bars under the default style and a line under "classic". se_type changes the form of the interval. Letter case does not matter.

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)
Example figure
Example figure: plot_recruitment(b, se = TRUE)

See also

Search documentation