On this page

Compare the observed survey indices at length with the predictions of two fits, one panel per time step.

Usage

plot_compare_CatL(
  model1,
  model2,
  data.CatL,
  years = NULL,
  model1_name = NULL,
  model2_name = NULL,
  colors = NULL,
  linetypes = NULL,
  line_size = NULL,
  facet_ncol = NULL,
  facet_scales = NULL,
  obs_color = "grey40",
  obs_size = NULL,
  obs_alpha = 0.6,
  obs_shape = 16,
  legend_pos = NULL,
  ...,
  point_size = NULL,
  title = NULL
)

Arguments

ArgumentDefaultDescription
model1required

The first fit.

model2required

The second fit.

data.CatLrequired

The survey index table used for both fits, with a length-bin column followed by one column of survey indices per time step.

yearsNULL

Numeric vector or NULL. Time steps to show, as years of data.CatL, for example years = c(2000, 2005, 2010, 2015). NULL (default) shows every time step. Years that do not occur in the data are left out with a warning, and none occurring is an error.

model1_nameNULL

Character or NULL. Name of the first fit in the plot and in the default title. NULL takes the model type ("ACL" or "ALSCL"); when both fits have the same type, the F structure, or 1 and 2, is added in parentheses.

model2_nameNULL

Character or NULL. Name of the second fit in the plot and in the default title. NULL takes the model type ("ACL" or "ALSCL"); when both fits have the same type, the F structure, or 1 and 2, is added in parentheses.

colorsNULL

Character vector of two colors, named by model or in model order. NULL uses the global compare_colors setting; fewer than two colors give a warning, and the global setting is used.

linetypesNULL

Character vector of two line types, with the same rules as colors. NULL uses the global compare_linetypes setting.

line_sizeNULL

Numeric or NULL. Line width. NULL uses the global compare_line_size setting.

facet_ncolNULL

Integer or NULL. Number of columns of panels. NULL (default) uses the global compare_facet_ncol setting, which by default chooses it from the number of panels.

facet_scalesNULL

Character or NULL. Axis scales of the panels, "fixed", "free", "free_x" or "free_y". NULL (default) uses the global compare_facet_scales setting ("free_y" unless changed). Letter case does not matter.

obs_color"grey40"

Character. Color of the observed points. Default "grey40".

obs_sizeNULL

Numeric or NULL. Another name for the size of the observed points; point_size takes priority when both are given.

obs_alpha0.6

Numeric. Transparency of the observed points. Default 0.6.

obs_shape16

Integer. Shape of the observed points. Default 16.

legend_posNULL

Character or NULL. Legend position, such as "bottom", "right" or "none". NULL uses the global compare_legend_pos setting. Letter case does not matter.

...…

The former argument names linewidth (for line_size), ncol (for facet_ncol) and scales (for facet_scales), accepted with a warning.

point_sizeNULL

Numeric or NULL. Size of the observed points. NULL uses obs_size when it is given, then the global compare_point_size setting, then the global point_size setting (default 2.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.

Value

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

Details

The plot compares the survey observations with the predictions exp(Elog_index) of both fits on the original scale of the index, where Elog_index is the fitted natural-log survey index. The predictions are medians, without a lognormal correction to the mean.

Zero and missing observations are left out of the observed points, as in fitting; the prediction curves keep every length bin of each selected time step and must be finite. When the fits store their observations, their positive observations and their pattern of missing data must match data.CatL. A saved fit without stored observations can be plotted, but its alignment with the data cannot be checked in full. The y axis uses the global survey label, as in plot_CatL().

Two fits of the same model get distinct default names, such as ACL (group_year) and ACL (year); model1_name and model2_name set other names, which must differ. Before matching observations to predictions, the function checks the time and length metadata of both fits against data.CatL and stops when they differ. A visual comparison does not show that the likelihoods or the biological assumptions of the two fits are comparable.

The observed points take the global point_size setting (default 2.5) unless the global compare_point_size setting is given. A point_size in the call takes priority, then obs_size, then the theme; acl_theme_set(compare_point_size = NULL) returns to the global point_size.

Additional details from R help

The positive observations and missing values must match both fitted results when the fits store their observations, and the length bins and time steps that the fits record must match too. Zeros and NA are left out of the observed points as in fitting; the predicted curves keep every length of each selected time step and must be finite at every plotted cell. For a saved fit that does not store its observations, the alignment with the data cannot be fully checked. Data frames, matrices and tibbles are converted to numbers as in fitting. The y-axis uses the global survey label, independently of the catch label. When the survey label is unset, a customized abundance label is used; otherwise the default is "Survey index". The plotted predictions are exp(Elog_index), the exponential of the predicted log survey index.

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_compare_CatL(a, b, dat, years = c(2000, 2005, 2010, 2015))
Example figure
Example figure: plot_compare_CatL(a, b, dat, years = c(2000, 2005, 2010, 2015))

See also

Search documentation