On this page

Plot the natural mortality rate that a fit used, given as a single value, by age class and time step, or by length.

Usage

plot_natural_mortality(
  fit,
  line_size = NULL,
  line_color = NULL,
  line_type = "solid",
  point_size = NULL,
  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

ArgumentDefaultDescription
fitrequired

An ACL or ALSCL fit, or a saved fit read with read_assessment().

line_sizeNULL

Numeric or NULL. Line width. NULL inherits the global line_size setting.

line_colorNULL

Character or NULL. Color of the line and points. NULL inherits the global line_color setting.

line_type"solid"

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

point_sizeNULL

Numeric or NULL. Size of the points at the age classes or length bins; NULL inherits the global point_size setting (default 2.5).

facet_ncolNULL

Integer or NULL. Columns of panels, for M by age class and time step; NULL chooses them from the number of panels.

facet_scales"free"

Character. Axis scales of the panels, "fixed", "free", "free_x" or "free_y". Letter case does not matter.

return_dataFALSE

Logical. TRUE returns a list with the plot and the plotted data, described under the return 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.

Value

A ggplot object; with return_data = TRUE, a list with plot and the plotted data, which has a Year, Age or Length column that follows the form of the input.

Details

The figure shows the natural mortality rate (M) that a fitted ACL or ALSCL model used. M is an input supplied by the user and is not estimated. The figure follows the form of the input. A single value is drawn as a horizontal line against the time step, and a rate by age class that is the same in every time step against age, with a point at each age class. A rate by age class and time step is drawn against the time step with one panel per age class, and a rate by length (ALSCL only) against the length-bin midpoints, with a point at each length bin. The subtitle names the form.

M is an instantaneous rate per model time step, and the default y-axis label states this time basis, for example "Natural mortality rate (per year)". The rate is read from the inputs and settings stored in the fit (fit$recipe), or from the live TMB object of a fit without them. The survey index does not inform the split of total mortality into fishing and natural mortality, so the level of the estimated fishing mortality rate and of the model catch depends on this input. The title uses the theme key natural_mortality; the axis labels use xlab$year, xlab$age or xlab$length, and ylab$M.

Additional details from R help

The figure depends on the form of M (see M in run_alscl()):

A single value

A horizontal line against the time step.

By age class, the same in every time step

M against age, with a point at each age class.

By age class and time step

M against the time step, one panel per age class.

By length (ALSCL)

M against the midpoints of the length bins, with a point at each length bin.

The subtitle names the form. M is an instantaneous rate per model time step, and the default y-axis label states this time basis, for example "Natural mortality rate (per year)". The oldest age class is a plus group and is marked with a plus sign.

The rate is read from the recipe of the fit (the fitting inputs and settings stored with it), or from the live TMB object of a fit without a recipe. The survey index does not inform the split of total mortality into fishing and natural mortality, so the level of the estimated fishing mortality rate and of the model catch depends on this input.

The title uses the theme key natural_mortality; the axis labels use xlab$year, xlab$age or xlab$length, and ylab$M.

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_natural_mortality(b)
# The values, with a Year, Age or Length column that follows the form of the input
head(plot_natural_mortality(b, return_data = TRUE)$data)
Example figure
Example figure: plot_natural_mortality(b, title = "Natural mortality rate") | plot_survey_catchability(b, title = "Survey catchability at length")

See also

Search documentation