plot_length_at_age()
View source ↗On this page
Plot the mean length of each age class of a fitted model by time step, with optional observed means from age readings.
Usage
plot_length_at_age(
fit,
observed = NULL,
basis = c("population", "survey"),
years = NULL,
ages = NULL,
facet_by = c("age", "none"),
line_size = NULL,
line_color = NULL,
line_type = "solid",
point_size = NULL,
observed_color = NULL,
observed_name = "Age readings",
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
)
Arguments
| Argument | Default | Description |
|---|---|---|
fit | required | An ACL or ALSCL fit, or a saved fit read with |
observed | NULL | NULL or a data frame of observed mean length at age from age readings, drawn as points. It needs the columns |
basis | c("population", "survey") | Character. |
years | NULL | NULL (all time steps) or the time steps to draw, as values of |
ages | NULL | NULL (all age classes) or the age classes to draw, as values of |
facet_by | c("age", "none") | Character. |
line_size | NULL | Numeric or NULL. Line width. NULL inherits the global line_size setting. |
line_color | NULL | Character or NULL. Line color with |
line_type | "solid" | Character. Line type, such as "solid" or "dashed". Default "solid". |
point_size | NULL | Numeric or NULL. Size of the observed points; NULL inherits the global point_size setting (default 2.5). |
observed_color | NULL | Character or NULL. Color of the observed points with |
observed_name | "Age readings" | Character. Name of the observed points in the legend and the caption. Default is "Age readings". |
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, described under the return 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. |
Value
A ggplot object, or a list with plot and data when return_data = TRUE. data has one row per age class and time step, with the columns Year, Age, AgeClass (the panel label), mean_length and sd_length.
Details
The figure shows the mean length of each age class of a fitted model against the time step, from length_at_age(), and optionally the observed mean length at age by time step from age readings. Use it to see how the lengths at age of the model change over time and to compare them with age readings. plot_VB() shows the mean of the same values over the time steps against age.
For an ALSCL fit the values come from the estimated numbers by length bin, age class and time step, so they change over time with growth, recruitment and mortality at length. For an ACL fit they come from the age-length key, which is the same in every time step. The lines are then horizontal on the population basis, and on the survey basis they change only when the supplied survey catchability changes over time. Each length bin is represented by its midpoint, so the mean of an age class with a large share of its fish in the first or the last length bin is drawn toward the midpoint of that bin; for a comparison with age readings, first assign the lengths of the aged fish to the length bins of the model. The oldest age class is a plus group and is marked with a plus sign. The title uses the theme key length_at_age_time, and the axis labels use xlab$year and ylab$growth; the package holds no unit for length, so give it in ylab.
Additional details from R help
The values are those of length_at_age(). For an ALSCL fit they
come from the estimated numbers by length bin, age class and time step,
so they change over time with growth, recruitment and mortality at
length. For an ACL fit they come from the age-length key, which is the
same in every time step, so the lines are horizontal on the population
basis, and on the survey basis they change only when the supplied survey
catchability changes over time. Each length bin is represented by its
midpoint, so the mean of an age class with a large share of its fish in
the first or the last length bin is drawn toward the midpoint of that bin.
The oldest age class is a plus group and is marked with a plus sign.
The title uses the theme key length_at_age_time, and the axis labels
use xlab$year and ylab$growth. The package holds no unit for length;
give it in ylab, for example ylab = "Length (cm)".
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_length_at_age(b, ages = c(2, 5, 8, 11))
# Survey basis, with mean length at age from age readings by time step (made up here)
readings <- subset(length_at_age(b, basis = "survey"), age %in% c(2, 5) & year %% 2 == 0)
readings$mean_length <- readings$mean_length + rep(c(-1, 1), length.out = nrow(readings))
plot_length_at_age(b, observed = readings, basis = "survey", ages = c(2, 5))

plot_length_at_age(b, ages = c(2, 5, 8, 11), line_size = 0.6)