plot_fishing_mortality()
View source ↗On this page
Plot the fishing mortality rate of a fit over time, by age or by length, with optional 95% intervals.
Usage
plot_fishing_mortality(
model_result,
line_size = NULL,
line_color = NULL,
line_type = "solid",
facet_ncol = NULL,
facet_scales = "free",
se = FALSE,
se_color = NULL,
se_alpha = NULL,
se_type = "ribbon",
type = c("year", "age", "length"),
return_data = FALSE,
x_breaks = NULL,
title = NULL,
xlab = NULL,
ylab = NULL,
font_family = NULL,
title_size = NULL,
base_theme = NULL,
axis_title_size = NULL,
axis_text_size = NULL,
strip_text_size = NULL,
legend_text_size = 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 F_color setting, or line_color when that is NULL. |
line_type | "solid" | Character. Line type, such as "solid" or "dashed". Default "solid". |
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. |
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 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 | "ribbon" | Character. Style of the interval, "ribbon" or "errorbar". Default "ribbon". Letter case does not matter. |
type | c("year", "age", "length") | Character. The dimension on the x axis. "year" (default) draws time, with one panel per age class (ACL) or length bin (ALSCL); "age" draws age, with one panel per time step; "length" (ALSCL only) draws the length-bin midpoints in |
return_data | FALSE | Logical. TRUE returns a list with the plot and the plotted data, described under the return value. Default FALSE. |
x_breaks | NULL | Numeric vector or NULL. Custom 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. Expansion follows global x_expand. |
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. Custom x-axis label. |
ylab | NULL | Character or NULL. Custom y-axis label; NULL inherits global ylab$F. The default label gains the time basis of the fit, for example "Fishing mortality rate (per year)". |
font_family | NULL | Character. Font family for text elements. |
title_size | NULL | Numeric. Title text size. |
base_theme | NULL | Theme name or ggplot2 theme object; NULL inherits the global base theme. Grid lines follow the |
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). |
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; with return_data = TRUE, a list with the plot plot and the plotted data data.
Details
type = "year" draws F over time with one panel per age class (ACL) or length bin (ALSCL); type = "age" draws F at age with one panel per time step; type = "length" (ALSCL) draws F against the length-bin midpoints len_mid with one panel per time step. ACL estimates F by age and has no F at length, so for ACL type = "length" draws F at age with a warning. ALSCL calculates F at age as the negative log of the proportion of an age class that survives the time step, minus natural mortality. When F is shared across groups (F_structure = "year"), every group has the same series, and type = "year" draws one panel, labelled "All age classes" for ACL and "All length bins" for ALSCL; the returned data still hold every group.
F is an instantaneous rate per model time step, per year for annual fits and per quarter for quarterly fits; the default y-axis label states this, for example "Fishing mortality rate (per year)". Age axes and age panels use the fitted ages in model_result$age and keep age order with or without intervals. The oldest age class of an ACL fit is the plus group, marked with a plus sign, for example the panel title "Age 15+" or the tick label "15+". Results saved without age metadata are plotted against group positions, and their age axis is labelled "Age bin" unless a label is given. With return_data = TRUE and type = "age", the data keep the group position in AgeGroup and add the fitted age in Age.
For ALSCL, type = "age" without intervals shows F at every age, including the plus group, and every time step. The fitted report (report$FA) holds the ages before the plus group and the time steps before the last, with standard errors. The other cells are calculated with the same formula from the reported numbers at length and age (report$NLA) and the total mortality at length (report$ZL), and they have no standard errors. With se = TRUE this plot therefore shows only the ages before the plus group and the time steps before the last. A result without numbers at length and age, for example a hand-made list, is drawn with the reported cells only. F in the last time step is predicted by the F process and is not informed by observations.
With se = TRUE, every plotted cell needs a finite estimate and a finite nonnegative standard error, and an incomplete table stops with an error; use se = FALSE for estimates only. The default interval is lognormal (see interval). A panel with a single estimate is drawn as a point. With se = TRUE its interval is an error bar, because a one-point ribbon has no visible width; the point takes the color of the line and the error bar the color of the interval.
Coordinates come from the matrix positions and the fitted time and group metadata, so matrix dimnames do not change them. Titles come from the global keys F_year, F_age or F_length (with _se added when intervals are drawn), and axis labels, x_breaks and x_expand from the theme; arguments given in the call take priority. base_theme accepts a theme name such as "theme_bw" or a ggplot2 theme object such as ggplot2::theme_bw(); grid lines follow the grid setting of acl_theme_set() in both cases.
Additional details from R help
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.
Age axes and age panels use the fitted ages in model_result$age.
The oldest age class of an ACL fit is a plus group and is marked with a
plus sign, for example "Age 15+" or the tick label "15+". ALSCL F at age
includes the plus group when it is drawn without intervals. With return_data = TRUE and type = "age", the
data keep the group position in AgeGroup and add the fitted age in
Age.
When F is shared across groups (F_structure = "year"), every
group has the same series. type = "year" then draws one panel
labelled "All age classes" (ACL) or "All length bins" (ALSCL) instead of
one identical panel per group. The returned
data still hold every group.
With the global y_zero setting (TRUE under the default style) the y axis of every panel starts at zero.
Matrix positions are matched to the time steps and groups of the fit; row and column names of the matrices do not replace these coordinates. Intervals need one finite estimate and one finite nonnegative standard error per plotted cell, so use se = FALSE for a saved fit without a complete table of standard errors.
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_fishing_mortality(b, type = "year",
se = TRUE, line_size = 0.6)

plot_fishing_mortality(b, type = "year", se = TRUE, line_size = 0.6)