On this page

Plot mean length at age, as the von Bertalanffy curve of an ACL fit or as mean length at age from the fitted numbers of an ALSCL fit, with optional observed means from age readings.

Usage

plot_VB(
  model_result,
  age_range = NULL,
  line_size = NULL,
  line_color = NULL,
  line_type = "solid",
  se = FALSE,
  se_color = NULL,
  se_alpha = NULL,
  se_type = c("ribbon", "errorbar"),
  text_color = "black",
  text_size = 3.5,
  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,
  observed = NULL,
  basis = c("population", "survey"),
  years = NULL,
  parameter_curve = FALSE,
  point_size = NULL,
  observed_color = NULL,
  observed_name = "Age readings"
)

Arguments

ArgumentDefaultDescription
model_resultrequired

A fitted ACL or ALSCL result. The von Bertalanffy curve needs a "report" component with "Linf", "vbk" and "t0"; mean length at age from the fitted numbers needs a result of run_alscl() or run_acl(), or a saved fit.

age_rangeNULL

For the von Bertalanffy curve of an ACL fit, NULL uses the fitted ages, or ages 1-25 for results without age metadata, with an automatic start no earlier than t0; explicit ranges must be finite increasing pairs starting at or after t0. For mean length at age from the fitted numbers, NULL uses all age classes and an explicit range selects the age classes within it.

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. Color of the curve. NULL inherits the global line_color setting.

line_type"solid"

Character. Line type, such as "solid" or "dashed". Default "solid".

seFALSE

Logical. Whether to draw the 95% confidence interval of the curve computed from Linf, k and t0 (delta method). Default FALSE. For an ACL fit it is the interval of the figure; for an ALSCL fit it is drawn around the reference line when parameter_curve = TRUE.

se_colorNULL

Character or NULL. Color of the interval ribbon or error bars. NULL inherits the global se_color setting.

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_typec("ribbon", "errorbar")

Character. Style of the interval, "ribbon" (shaded area) or "errorbar" (error bars). Error bars are drawn at the fitted ages in model_result$age that lie within age_range. Results saved without age metadata, and ranges that contain no fitted age, use every plotted age. Default is "ribbon". Letter case does not matter.

text_color"black"

Character. Color of the growth-parameter annotation. Default "black".

text_size3.5

Numeric. Size of the growth-parameter annotation in all display modes. Default 3.5.

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.

observedNULL

NULL or a data frame of observed mean length at age from age readings, drawn as points. It needs the columns age (years) and mean_length, and may have sd_length (or sd), drawn as bars of one standard deviation on each side of the mean, or lower and upper, drawn as the bars of an interval, and year (the time step). Every row is drawn as one point. With years, only the rows of those time steps are drawn; rows without a time step are always drawn.

basisc("population", "survey")

Character. "population" (default) gives mean length at age in the population, and "survey" mean length at age in the survey catch, with numbers at length multiplied by the survey catchability at length used in the fit. Use "survey" to compare with age readings of fish caught in the survey. For an ACL fit, "survey" draws mean length at age from the age-length key in place of the von Bertalanffy curve, which describes the population. Letter case does not matter.

yearsNULL

NULL (all time steps) or the time steps over which mean length at age from the fitted numbers is averaged, as values of model_result$year. It does not change the von Bertalanffy curve of an ACL fit.

parameter_curveFALSE

Logical. For an ALSCL fit, and for an ACL fit with basis = "survey", whether to add the curve computed from Linf, k and t0 as a dashed reference line, named in the legend and explained in the caption. It has no effect on the von Bertalanffy curve of an ACL fit.

point_sizeNULL

Numeric or NULL. Size of the observed points; NULL inherits the global point_size setting (default 2.5).

observed_colorNULL

Character or NULL. Color of the observed points; NULL inherits the global observed_color setting.

observed_name"Age readings"

Character. Name of the observed points in the legend. Default is "Age readings".

Value

A ggplot object, which can be styled further or saved with acl_save_plot().

Details

The figure shows mean length at age of a fitted model. What is drawn depends on the model, because the growth parameters have different meanings in ACL and ALSCL. For an ACL fit, Linf, vbk and t0 are the parameters of a von Bertalanffy (VB) curve of mean length at age in the population; the figure shows this curve with an annotation of Linf and k, and t0 is the theoretical age at zero length. For an ALSCL fit, Linf and k set the mean growth increment at length, and Linf, k and t0 set the mean length of recruits; they are not the parameters of a curve of mean length at age. The figure then shows mean length at age calculated from the fitted numbers by length bin and age class (length_at_age()), averaged over the time steps, without an annotation of Linf and k.

basis = "survey" uses the survey basis (numbers at length multiplied by the survey catchability at length used in the fit); use it to compare with age readings of fish caught in the survey. An ACL fit then also shows mean length at age from its age-length key. years selects the time steps of the mean. observed supplies mean length at age from age readings, drawn as points, with an optional standard deviation or interval. parameter_curve = TRUE adds the curve computed from Linf, k and t0 as a dashed reference line; the legend and the caption name it. With the original structure, it is the mean length at age in the first time step and the mean length of recruits in every time step. The interval of se = TRUE belongs to this curve. The model reports no standard error for mean length at age from the fitted numbers, so a request for an interval without the curve gives a warning and the estimate only. For an ALSCL fit, add parameter_curve = TRUE to draw this curve with its interval.

Each length bin is represented by its midpoint, including the two open-ended outer bins. Where a large share of an age class lies in the first or the last length bin, its mean length is drawn toward the midpoint of that bin. For a comparison with age readings, assign the lengths of the aged fish to the length bins of the model and average the bin midpoints, so that both means are calculated in the same way.

For the VB curve of an ACL fit, age_range = NULL uses the fitted age range, or ages 1-25 for results without age metadata, and the automatic lower endpoint is at least t0. An explicit range must be a finite increasing pair starting at or after t0. For mean length at age from the numbers, age_range = NULL draws all age classes and an explicit range selects the age classes within it; it may start before t0. The parameter annotation honors text_size, text_color and font_family. The y-axis label inherits ylab$growth; the package holds no unit for length, so give it in ylab, for example ylab = "Length (cm)". An ALSCL result without ages, time steps, length-bin midpoints or numbers by length and age is an error.

ylab is honored in every mode; when the covariance is unavailable, or Linf, k and t0 are all fixed, se = TRUE gives a warning and draws the estimate only, with all custom styling.

Additional details from R help

For an ACL fit, the asymptotic length (Linf), the growth rate (vbk, per year) and t0 (the theoretical age at zero length, in years) are the parameters of a von Bertalanffy curve of mean length at age in the population. The figure shows this curve, and the annotation gives Linf in the length unit of the data and k per year.

For an ALSCL fit, Linf and k set the mean growth increment at length, and Linf, k and t0 set the mean length of recruits (see length_at_age()). They are not the parameters of a von Bertalanffy curve of mean length at age. The figure therefore shows mean length at age calculated from the fitted numbers by length bin and age class (length_at_age()), averaged over the time steps, and has no annotation of Linf and k. The curve computed from Linf, k and t0 can be added as a reference line with parameter_curve = TRUE.

For an ALSCL fit, and for any fit with basis = "survey", mean length at age is that of length_at_age(): for ALSCL from the estimated numbers by length bin, age class and time step, and for ACL from the age-length key. Each length bin is represented by its midpoint. The line connects the values of the age classes, and the oldest age class is a plus group, marked with a plus sign on the age axis. The subtitle states the basis and the time steps of the mean. plot_length_at_age() shows the values of each time step.

In an ALSCL fit with the original structure, the curve computed from Linf, k and t0 is the mean length at age in the first time step and the mean length of recruits in every time step. With structure = list(initial_length = "growth") (part of structure = "von_bertalanffy"), its value at the first age class is the mean length of recruits. In later time steps the lengths of a cohort follow from the growth increments and from mortality at length, so the curve is not the mean length at age of the fitted population. The caption of the figure states which of the two cases applies.

For an ALSCL fit, the annotation of Linf and k is drawn only with the curve from the growth parameters (parameter_curve = TRUE), under the heading "Curve from the growth parameters". se = TRUE without parameter_curve = TRUE gives a warning and draws the estimate only, because the model reports no standard error for mean length at age from the fitted numbers; add parameter_curve = TRUE to draw that curve with its interval. An explicit age_range that starts before t0 is accepted for these fits, because the fitted numbers are not extrapolated.

If the growth covariance is unavailable or unusable, or Linf, k and t0 are all fixed, a request for confidence intervals warns and draws the estimate only, preserving all supplied labels, axis settings, text styles and theme options. The parameter annotation is retained with and without intervals and inherits font_family. The y-axis inherits the global growth label unless ylab is supplied. The package holds no unit for length; give it in ylab, for example ylab = "Length (cm)". The title uses the theme key VB for the von Bertalanffy curve of an ACL fit and length_at_age otherwise. An automatic age range with no positive span at or above t0 is rejected; supply an explicit biologically meaningful age_range in that case.

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_VB(b)
# Simulated age readings; each length is assigned to its model length bin
set.seed(42)
ref <- data.frame(Age = rep(1:15, each = 5))
ref$Length <- VB_func(60, 0.2, 1/60, ref$Age) + stats::rnorm(nrow(ref), sd = 2)
ref$Mid <- b$len_mid[findInterval(ref$Length, b$len_border) + 1]
readings <- data.frame(age = 1:15, mean_length = as.numeric(tapply(ref$Mid, ref$Age, mean)),
    sd_length = as.numeric(tapply(ref$Mid, ref$Age, sd)))
plot_VB(b, observed = readings, parameter_curve = TRUE)
Example figure
Example figure: plot_VB(b, observed = readings, parameter_curve = TRUE)

See also

Search documentation