Package 'gadgetplots'

Title: Plot gadget3 models
Description: Creates plots of gadget.fit objects for gadget3 (Globally applicable Area Disaggregated General Ecosystem Toolbox) stock assessment model framework.
Authors: Mikko Vihtakari [aut, cre] (affiliation: Institute of Marine Research, ORCID: <https://orcid.org/0000-0003-0371-4319>), Bjarki Thor Elvarsson [aut], Will Butler [aut], Jamie Lentin [aut], Marine and Freshwater Research Institute (Iceland) [cph], Institute of Marine Research (Norway) [cph]
Maintainer: Mikko Vihtakari <[email protected]>
License: GPL-3
Version: 0.3.11
Built: 2026-12-02 09:24:44 UTC
Source: https://github.com/gadget-framework/gadgetplots

Help Index


Age-length input data to gadget

Description

Age-length input data to gadget

Usage

aldist_example

Format

Data frame with gadget attributes containing Greenland halibut age-length distributions from the Institute of Marine Research EggaNord survey.

Source

Joint Russian-Norwegian Arctic Fisheries Working Group

See Also

Other datasets: example_catches, fit, ldist_example, sexratio_example, stockdist_example


Plot age distribution data for a gadget3 model

Description

The dplot functions plot data passed to a gadget3 model instead of data from the model or fit objects.

Usage

dplot_adist(
  x,
  type = "bar",
  color_palette = scales::brewer_pal(palette = "Set1"),
  dir = "v",
  base_size = 8,
  ...
)

Arguments

x

A gadget3 ready data frame created using mfdb, g3_data or add_g3_attributes.

type

Character specifying the plot type: "bar" or "ggridges".

color_palette

A function defining the color palette to be used for fill of bars.

dir

Character specifying the direction of the facets ("h" for horizontal, "v" for vertical). See facet_wrap. Defaults to "v" unlike in facet_wrap to make it easier to follow length and age groups across years.

base_size

Base size parameter for ggplot. See ggtheme.

...

Additional arguments passed to facet_wrap.

Value

A ggplot object.

Examples

data(aldist_example)
dplot_adist(aldist_example)
dplot_adist(aldist_example, type = "ggridges")

Plot age-length distribution data for a gadget3 model

Description

The dplot functions plot data passed to a gadget3 model instead of data from the model or fit objects.

Usage

dplot_aldist(
  x,
  type = "bar",
  facet_age = FALSE,
  dir = "v",
  color_palette = scales::brewer_pal(palette = "Set1"),
  base_size = 8,
  ...
)

Arguments

x

A gadget3 ready data frame created using mfdb, g3_data or add_g3_attributes.

type

Character specifying the plot type: "bar", "step", or "area". "step" produces a similar plot where age and length distributions are plotted separately as in plot_catchdist. "area" produces an area plot instead of a bar plot, but works poorly when there are many age groups.

facet_age

Logical indicating whether ages should be plotted in separate facets. Does not apply for type = "step".

dir

Character specifying the direction of the facets ("h" for horizontal, "v" for vertical). See facet_wrap. Defaults to "v" unlike in facet_wrap to make it easier to follow length and age groups across years.

color_palette

A function defining the color palette to be used for fill of bars when facet_age = TRUE. See scale_color_manual. To adjust color when facet_age = FALSE, use the standard ggplot2::scale_fill_* functions.

base_size

Base size parameter for ggplot. See ggtheme.

...

Additional arguments passed to facet_wrap.

Value

A ggplot object.

Examples

data(aldist_example)
dplot_aldist(aldist_example)
dplot_aldist(aldist_example, type = "step") # as in plot_catchdist
dplot_aldist(aldist_example, facet_age = TRUE)
dplot_aldist(aldist_example, type = "area") # works poorly

Plot catch data for a gadget3 model

Description

The dplot functions plot data passed to a gadget3 model instead of data from the model or fit objects.

Usage

dplot_catch(x, base_size = 8)

Arguments

x

A gadget3 ready data frame created using mfdb, g3_data or add_g3_attributes. Can be a single data frame or a named list of data frames in which case multiple catches are plotted in the same figure.

base_size

Base size parameter for ggplot. See ggtheme.

Value

A ggplot object.

Examples

data(example_catches)
dplot_catch(TrawlNor_catches)
dplot_catch(
  list("TrawlNor" = TrawlNor_catches,
       "OtherNor" = OtherNor_catches,
       "TrawlRus" = TrawlRus_catches,
       "OtherRus" = OtherRus_catches,
       "Internat" = Internat_catches)
       )

Plot length distribution data for a gadget3 model

Description

The dplot functions plot data passed to a gadget3 model instead of data from the model or fit objects.

Usage

dplot_ldist(x, type = "bar", scales = "free_y", dir = "v", base_size = 8, ...)

Arguments

x

A gadget3 ready data frame created using mfdb, g3_data or add_g3_attributes.

type

Character specifying the plot type: "bar", "ggridges" or "line"

scales

Character specifying the scales argument passed to facet_wrap. Defaults to "free_y".

dir

Character specifying the direction of the facets ("h" for horizontal, "v" for vertical). See facet_wrap. Defaults to "v" unlike in facet_wrap to make it easier to follow length and age groups across years.

base_size

Base size parameter for ggplot. See ggtheme.

...

Additional arguments passed to facet_wrap.

Value

A ggplot object.

Examples

data(ldist_example)
dplot_ldist(ldist_example)
dplot_ldist(ldist_example, type = "ggridges")
dplot_ldist(ldist_example, type = "line")

Plot sex ratio data for a gadget3 model

Description

The dplot functions plot data passed to a gadget3 model instead of data from the model or fit objects.

Usage

dplot_sexr(x, dir = "v", base_size = 8, ...)

Arguments

x

A gadget3 ready data frame created using mfdb, g3_data or add_g3_attributes.

dir

Character specifying the direction of the facets ("h" for horizontal, "v" for vertical). See facet_wrap. Defaults to "v" unlike in facet_wrap to make it easier to follow length and age groups across years.

base_size

Base size parameter for ggplot. See ggtheme.

...

Additional arguments passed to facet_wrap.

Value

A ggplot object.

Examples

data(sexratio_example)
dplot_sexr(sexratio_example)

Plot stock distribution data for a gadget3 model

Description

The dplot functions plot data passed to a gadget3 model instead of data from the model or fit objects.

Usage

dplot_stockdist(
  x,
  stock_col = "maturity_stage",
  proportion = FALSE,
  group_by_sex = FALSE,
  sexes = c(female = "^female", male = "^male"),
  colors = NULL,
  scales = "free_y",
  dir = "v",
  base_size = 8,
  ...
)

Arguments

x

A gadget3 ready data frame created using mfdb, g3_data or add_g3_attributes.

stock_col

Character defining the name of the column separating stocks.

proportion

Logical indicating whether to plot proportion of stocks instead of absolute numbers.

group_by_sex

Logical indicating whether to take the proportions by sex (TRUE) or by all stocks (FALSE). Used only when proportion = TRUE

sexes

Named vector of length two containing regular expressions separating sexes in stock_col. See the default as an example.

colors

A vector of colors to be used for stocks. If NULL, scales::hue_pal() will be used

scales

Character specifying the scales argument passed to facet_wrap. Defaults to "free_y".

dir

Character specifying the direction of the facets ("h" for horizontal, "v" for vertical). See facet_wrap. Defaults to "v" unlike in facet_wrap to make it easier to follow length and age groups across years.

base_size

Base size parameter for ggplot. See ggtheme.

...

Additional arguments passed to facet_wrap.

Value

A ggplot object.

Examples

data(stockdist_example)
dplot_stockdist(stockdist_example)
dplot_stockdist(stockdist_example, proportion = TRUE)
dplot_stockdist(stockdist_example, proportion = TRUE, group_by_sex = TRUE)

Catch input data to gadget

Description

Catch input data to gadget

Usage

TrawlNor_catches

Internat_catches

OtherNor_catches

Internat_catches

OtherRus_catches

TrawlRus_catches

TrawlNor_catches

Format

Data frame with gadget attributes containing Greenland halibut catches for ICES areas 1 and 2 (Northeast Arctic)

An object of class data.frame with 43 rows and 4 columns.

An object of class data.frame with 43 rows and 4 columns.

An object of class data.frame with 43 rows and 4 columns.

An object of class data.frame with 43 rows and 4 columns.

An object of class data.frame with 43 rows and 4 columns.

An object of class data.frame with 43 rows and 4 columns.

Source

Joint Russian-Norwegian Arctic Fisheries Working Group

See Also

Other datasets: aldist_example, fit, ldist_example, sexratio_example, stockdist_example


An example gadget.fit object.

Description

An example gadget.fit object.

Usage

fit

Format

gadget.fit object containing an early draft of the gadget model for Northeast Arctic Greenland halibut stock assessment. This draft is used because the final model is too large as an example dataset.

Source

Joint Russian-Norwegian Arctic Fisheries Working Group

See Also

Other datasets: aldist_example, example_catches, ldist_example, sexratio_example, stockdist_example


Plot of data passed into a gadget model

Description

Plot all observational data from a gadget model

Usage

g3d_plot(model, regexp = NULL, scales = "fixed", ncol = NULL, base_size = 8)

Arguments

model

R or TMB model. A model object from g3_to_r or g3_to_tmb functions.

regexp

Either NULL (no filtering) or a character string giving a regular expression to filter model-data components. Useful alternatives: "adist" for abundance distribution data, "cdist" for catch distribution data, "surveyindices" for survey indices, and "catch" for catches.

scales

Character defining the facet_wrap scales argument to use.

ncol

Number of columns passed to facet_wrap

base_size

Base size parameter for ggplot. See ggtheme.

Details

Plots data as contained in a gadget model. Helpful in checking models for possible data issues and for documentation of models.

Value

A list of ggplot objects.


Plot Andersen suitability using model parameters

Description

Plot Andersen suitability using model parameters

Usage

g3plot_andersen(
  length,
  p0,
  p1,
  p2,
  p3,
  p4,
  p5,
  add = FALSE,
  base_size = 8,
  ...
)

Arguments

length

Numeric vector defining the lengths for which suitabilities should be plotted

p0, p1, p2, p3, p4, p5

(Named) numeric vectors defining the Andersen suitability function parameters. See suitability. If length > 1, multiple curves will be plotted using a different line type. All of these parameters must have the same length.

add

Logical indicating whether the function should produce a ggplot2 layer which can be added to an existing ggplot (TRUE) or whether to plot the results (FALSE)

base_size

Base size parameter for ggplot. See ggtheme.

...

Additional arguments passed to plot_* functions.

Examples

g3plot_andersen(length = 1:120, p0 = 0, p1 = 0.659, p2 = 1, p3 = 0.15, p4 = 1e4, p5 = 120)

Plot exponentiall50 suitability using model parameters

Description

Plot exponentiall50 suitability using model parameters

Usage

g3plot_exponentiall50(length, alpha, l50, add = FALSE, base_size = 8, ...)

Arguments

length

Numeric vector defining the lengths for which suitabilities should be plotted

alpha

(Named) numeric vector defining the exponentiall50 slopes. If length > 1, multiple curves will be plotted using a different line type. See suitability.

l50

Numeric vector defining the exponentiall50 l50 values. Must be same length than alpha

add

Logical indicating whether the function should produce a ggplot2 layer which can be added to an existing ggplot (TRUE) or whether to plot the results (FALSE)

base_size

Base size parameter for ggplot. See ggtheme.

...

Additional arguments passed to geom_line

Examples

data(fit)
suit <- fit$params[grepl("ghl_female.ecos.survey", fit$params$switch),]

g3plot_exponentiall50(
   length = 1:60,
   alpha = unlist(suit[grepl("alpha", suit$switch), "value"]),
   l50 = unlist(suit[grepl("l50", suit$switch), "value"])
   )

Wrapper for plot.gadget.fit that saves all diagnostic graphs to a directory

Description

Wrapper for plot.gadget.fit that saves all diagnostic graphs to a directory

Usage

gadget_plots(
  fit,
  path,
  file_type = "png",
  quiet = FALSE,
  width = NULL,
  height = NULL,
  units = "cm",
  res = 300,
  ...
)

Arguments

fit

A gadget fit object. See g3_fit.

path

Directory path for saving figures.

file_type

Character. Either one of the devices in ggsave, in which case files of the defined type are printed to path, or "html" which compiles all plots into one html file using knit and the make_html function.

quiet

Logical indicating whether to print messages about the plotting process. Set to FALSE to suppress the messages.

width, height

Plot size given in units. If NULL, reasonable standard values are used.

units

Units for plot size. See ggsave

res

Plot resolution. See the dpi argument in ggsave

...

Additional arguments to plotting functions (only used for plot_annual at the moment)

Value

Returns nothing, but makes the requested files.

See Also

make_html


Length input data to gadget

Description

Length input data to gadget

Usage

ldist_example

Format

Data frame with gadget attributes containing Greenland halibut length distributions from the Institute of Marine Research EggaNord survey.

Source

Joint Russian-Norwegian Arctic Fisheries Working Group

See Also

Other datasets: aldist_example, example_catches, fit, sexratio_example, stockdist_example


Save diagnostic graphs to a single html document

Description

Save diagnostic graphs to a single html document

Usage

make_html(
  fit,
  path = getwd(),
  harvest_rate = TRUE,
  file_name = "model_output_figures.html",
  template = "standard",
  model_name = "Gadget model output"
)

Arguments

fit

A gadget fit object. See g3_fit.

path

Directory path for saving the html output. Defaults to working directory.

harvest_rate

A Logical value, if TRUE the harvest rate will be plotted, if FALSE the fishing mortality will be plotted.

file_name

Character specifying the name of the html file without path. Must include the file extension.

template

Character specifying the html template to use. See details.

model_name

Character specifying the name of the model when "standard template is used.

Details

The package contains html templates tailored for different stocks needed by the authors. Specify the name in the template argument. Current alternatives are:

standard

Standard model output figures. Use the harvest_rate argument to switch between F and HR figures.

iceland

Output tailored for Icelandic stock assessment.

nea_ghl

Output tailored for Northeast Arctic Greenland halibut assessment.

Value

Returns nothing, but makes the requested file. See the webpage for example output.


Plot model age distributions for stocks by year

Description

Plot model age distributions for stocks by year

Usage

plot_adist(
  fit,
  type = "bar",
  scales = "fixed",
  ncol = NULL,
  years = NULL,
  base_size = 8
)

Arguments

fit

A gadget fit object. See g3_fit.

type

Character specifying the plot type. Options: "line", "bar" or "ggridges". See examples.

scales

Character defining the facet_wrap scales argument to use.

ncol

Number of columns passed to facet_wrap

years

Numeric vector defining which years to plot. If NULL (default), all years are plotted.

base_size

Base size parameter for ggplot. See ggtheme.

Value

A ggplot object or a list of such objects depending on the type argument.

Examples

data(fit)
plot_adist(fit)
plot_adist(fit, type = "line")
plot_adist(fit, type = "ggridges")

Plot an age class from the model

Description

Plot an age class from the model

Plots age class from the model at the beginning of the year

Usage

plot_ageclass(
  fit,
  age = 2,
  biomass = FALSE,
  base_size = 8,
  return_data = FALSE
)

Arguments

fit

A gadget fit object. See g3_fit.

age

Integer specifying the age class to plot.

biomass

Logical indicating whether biomass should be plotted instead of abundance.

base_size

Base size parameter for ggplot. See ggtheme.

return_data

Logical indicating whether to return data for the plot instead of the plot itself.

Value

A ggplot object.

Examples

data(fit)
plot_ageclass(fit)
plot_ageclass(fit, age = 5, biomass = TRUE)

Plot of age composition from the model

Description

Plot of age composition from the model

Usage

plot_agecomp(
  fit,
  type = "bubble",
  scales = "fixed",
  biomass = FALSE,
  base_size = 8,
  return_data = FALSE
)

Arguments

fit

A gadget fit object. See g3_fit.

type

Character specifying the plot type. Options: "bar", "line", "ggridges" or "bubble". See Details.

scales

Character defining the facet_wrap scales argument to use.

biomass

Logical indicating whether biomass should be plotted instead of abundance.

base_size

Base size parameter for ggplot. See ggtheme.

return_data

Logical indicating whether to return data for the plot instead of the plot itself.

Details

Possible plot types are:

bar

Facetted bar plot with year on x-axis, abundance on y-axis and ages along rows. Year classes are colored.

line

Facetted line plot with year on x-axis, abundance on y-axis and ages along rows. Stocks are colored.

ggridges

Same as above but the bars are overlapping.

bubble (or any other string)

Bubble plot with year on x-axis, age on y-axis and point size scaled to abundance. Year classes are colored.

Note that both "bar" and "bubble" contain extra information as text for plotly::ggplotly.

Value

A ggplot object.

Examples

data(fit)
plot_agecomp(fit)
plot_agecomp(fit, type = "line", biomass = TRUE)
plot_agecomp(fit, type = "bar")
plot_agecomp(fit, type = "ggridges")

Plot of fitted growth for each age-length component

Description

Plot of fitted growth for each age-length component

Usage

plot_agelength(fit, name = NULL, base_size = 8)

Arguments

fit

A gadget fit object. See g3_fit.

name

A character vector specifying the unique(fit$catchdist.fleets$name) to plot. If NULL, all names with relevant data are plotted.

base_size

Base size parameter for ggplot. See ggtheme.

Value

A ggplot object. A list of ggplot objects if there are multiple age-length (aldist) data sources (unique(fit$catchdist.fleets$name)).

Examples

data(fit)
plot_agelength(fit)

Plot annual ICES type of graphic returning central model data

Description

Plot annual ICES type of graphic returning central model data

Usage

plot_annual(
  fit,
  harvest_rate = TRUE,
  color_palette = scales::hue_pal(),
  base_size = 8,
  ...
)

Arguments

fit

A gadget fit object. See g3_fit.

harvest_rate

A Logical value, if TRUE the harvest rate will be plotted, if FALSE the fishing mortality will be plotted.

color_palette

A function defining the color palette to be used or a vector of colors which is 1 longer than the number of stocks in the model. The extra color will be used for total estimate. See scale_color_manual.

base_size

Base size parameter for ggplot. See ggtheme.

...

Additional arguments passed to plot_* functions.

Value

A ggplot object. If fleet = NULL, a list of ggplot objects.

Examples

data(fit)
# Annual plot with custom colors
plot_annual(fit, color_palette = scales::brewer_pal(palette = "Spectral"))

Plot stock biomasses

Description

Plot stock biomasses

Usage

plot_biomass(
  fit,
  type = "line",
  total = FALSE,
  biomass = TRUE,
  stocks = NULL,
  min_catch_length = NULL,
  return_data = FALSE,
  base_size = 8,
  scale = c("kt", "Mt", "t")
)

Arguments

fit

A gadget fit object. See g3_fit.

type

Character specifying the plot type. Options: "line" or "area". See examples.

total

Logical indicating whether total biomass should be plotted. Has no effect if type = "area".

biomass

Logical indicating whether biomass should be plotted instead of abundance.

stocks

Character specifying the substock to plot in fit. If NULL, all stocks are plotted. Not applicable if min_catch_length is defined.

min_catch_length

Numeric value defining the minimum catch length (size), which will be used to filter (>=) the model population before calculating biomass. Combines all stocks. Turn of by setting to NULL (default).

return_data

Logical indicating whether to return data for the plot instead of the plot itself.

base_size

Base size parameter for ggplot. See ggtheme.

scale

Character specifying the display unit of biomass: "kt" (default), "Mt" or "t". Applies to biomass only; abundance is always shown in millions.

Value

A ggplot object.

Examples

data(fit)
plot_biomass(fit)
plot_biomass(fit, biomass = FALSE, total = TRUE)
plot_biomass(fit, type = "area")
plot_biomass(fit, min_catch_length = 45)

Plot catches

Description

Plot catches

Usage

plot_catch(
  fit,
  type = "stock",
  biomass = TRUE,
  base_size = 8,
  return_data = FALSE,
  scale = c("kt", "Mt", "t")
)

Arguments

fit

A gadget fit object. See g3_fit.

type

Character specifying the data type: "stock" plots the catches by stock, "fleet" by fleet, "total" catches without separating to stock or fleet, and "hr" harvest rates by fleet.

biomass

Logical indicating whether biomass should be plotted instead of estimated abundance.

base_size

Base size parameter for ggplot. See ggtheme.

return_data

Logical indicating whether to return data for the plot instead of the plot itself.

scale

Character specifying the display unit of catch in biomass: "kt" (default), "Mt" or "t". Does not affect type = "hr" or catch in numbers (biomass = FALSE).

Value

A ggplot object.

Examples

data(fit)
plot_catch(fit)
plot_catch(fit, biomass = FALSE)
plot_catch(fit, type = "total")
plot_catch(fit, type = "fleet")
plot_catch(fit, type = "hr")

Plot catch distributions

Description

Plots the length distribution of each fit$catchdist.fleets$name

Usage

plot_catchdist(fit, type = "step", name = NULL, base_size = 8)

Arguments

fit

A gadget fit object. See g3_fit.

type

Character specifying the plot type: "step" uses stepwise lines to show the aggregation intervals. "line" uses lines through average values between lower and upper intervals.

name

A character vector specifying the unique(fit$catchdist.fleets$name) to plot. If NULL, all names with relevant data are plotted.

base_size

Base size parameter for ggplot. See ggtheme.

Value

A list of ggplot objects consisting of a separate plot for each of names.

Examples

data(fit)
# Only one data set to save space:
plot_catchdist(fit, name = "EggaN_ldist")
plot_catchdist(fit, name = "EggaN_ldist", type = "line")

Plot fishing mortality

Description

Plot fishing mortality

Usage

plot_f(
  fit,
  stocks = NULL,
  fbar_ages = NULL,
  return_data = FALSE,
  base_size = 8
)

Arguments

fit

A gadget fit object. See g3_fit.

stocks

Character specifying the substock to plot in fit. If NULL, all stocks are plotted. Not applicable if fbar_ages is defined.

fbar_ages

Either NULL or a numeric vector of ages to include to calculate Fbar (averaged F over age ranges) for selected ages instead of F for each stock.

return_data

Logical indicating whether to return data for the plot instead of the plot itself.

base_size

Base size parameter for ggplot. See ggtheme.

Details

The function calculates either average fishing mortality per substock or average fishing mortality over an age range depending on the fbar_ages argument.

Value

A ggplot object.

See Also

plot_hr

Examples

data(fit)
plot_f(fit)
plot_f(fit, fbar_ages = 5:10)

Plot of average growth for each stock

Description

Plot of average growth for each stock

Usage

plot_growth(
  fit,
  type = "annual",
  stdev = FALSE,
  add_models = FALSE,
  base_size = 8
)

Arguments

fit

A gadget fit object. See g3_fit.

type

Character specifying the plot type. Options: "annual", "mean" or "stdev". See Details.

stdev

Logical indicating whether standard deviation should be shown on both sides of mean for plots that use mean lengths.

add_models

Logical indicating whether growth models extracted from growth parameters should be plotted together with the data. Uses grep and does not always work.

base_size

Base size parameter for ggplot. See ggtheme.

Value

A ggplot object.

Examples

data(fit)
plot_growth(fit)
plot_growth(fit, add_models = TRUE, stdev = TRUE)
plot_growth(fit, type = "mean")
plot_growth(fit, type = "stdev")

Plot harvest rate

Description

Plot harvest rate

Usage

plot_hr(
  fit,
  stocks = NULL,
  min_catch_length = NULL,
  biomass = TRUE,
  model_selectivity = TRUE,
  base_size = 8,
  return_data = FALSE
)

Arguments

fit

A gadget fit object. See g3_fit.

stocks

Character specifying the substock to plot in fit. If NULL, all stocks are plotted. Not applicable if min_catch_length is defined.

min_catch_length

Numeric value defining the minimum catch length (size), which will be used to filter (>=) the model population before calculating harvest rates using catches. Combines all stocks. Turn of by setting to NULL (default). Set to 0 to get HR for the entire model population. See Details.

biomass

Logical indicating whether biomass should be used to calculate harvest rates instead of abundance.

model_selectivity

Logical indicating whether to use model selectivity when calculating harvest rates. FALSE will calculate harvest rate using the entire population, TRUE using the harvestable biomass following fleet suitabilities. Only applicable when using the stocks parameter or when min_catch_length = 0.

base_size

Base size parameter for ggplot. See ggtheme.

return_data

Logical indicating whether to return data for the plot instead of the plot itself.

Details

The function uses all catches without filtering by size (but allocates them to substocks) and varies denominator depending on the min_catch_length argument. If min_catch_length = NULL, the output represents harvest rate for each substock assuming model fleet selectivities (fetched from the harv.biomass column in fit$res.by.year). If min_catch_length = 0, the output represents harvest rate for the entire model population assuming model fleet selectivities (fetched from the harv.biomass column in fit$res.by.year, stocks are summed before calculating the harvest rate). Finally, if min_catch_length is any number > 0, the output represents harvest rate assuming flat selectivity for lengths >= min_catch_length. Note that the last IS NOT real model harvest rate. It should only be used for reporting results, never for finding target harvest rates in projections, for instance. The min_catch_length = 0 is for the latter case.

Value

A ggplot object.

See Also

plot_f

Examples

data(fit)
plot_hr(fit)
plot_hr(fit, model_selectivity = FALSE)
plot_hr(fit, min_catch_length = 45)

Plot central model output from a jitter analysis

Description

Plot central model output from a jitter analysis

Usage

plot_jitter(
  jitter_fit,
  vars = c("nll.summary", "total.biomass", "hr", "recruitment"),
  base_size = 8,
  ncol = NULL
)

Arguments

jitter_fit

A list of g3_fit objects originating from g3_jitter.

vars

Character vector giving the variables to plot. Only the default parameters are currently implemented.

base_size

Base size parameter for ggplot. See ggtheme.

ncol

Number of columns to be used in the plot. Set to NULL for standard layout.

Value

A ggplot object.


Plot model length distributions for stocks by year

Description

Plot model length distributions for stocks by year

Usage

plot_ldist(
  fit,
  type = "line",
  by_age = FALSE,
  stocks = NULL,
  scales = "fixed",
  ncol = NULL,
  years = NULL,
  base_size = 8
)

Arguments

fit

A gadget fit object. See g3_fit.

type

Character specifying the plot type. Options: "line", "bar", or "ggridges".

by_age

Logical indicating whether the length distributions should be grouped by age. Works only with type = "line".

stocks

Character specifying the substock to plot in fit. If NULL, all stocks are plotted.

scales

Character defining the facet_wrap scales argument to use.

ncol

Number of columns passed to facet_wrap

years

Numeric vector defining which years to plot. If NULL (default), all years are plotted.

base_size

Base size parameter for ggplot. See ggtheme.

Details

Do not trust the absolute numbers when by_age = TRUE. They are estimated from normal distributions by using number * dnorm(1:120, mean = mean_length, sd = stddev_length).

Value

A ggplot object or a list of such objects depending on the type argument.

Examples

data(fit)
plot_ldist(fit)
plot_ldist(fit, type = "bar")
plot_ldist(fit, type = "ggridges")
plot_ldist(fit, by_age = TRUE, years = 2021)

Plot central model output from a leave-out analysis

Description

Plot central model output from a leave-out analysis

Usage

plot_leaveout(
  lo_fit,
  vars = c("nll.summary", "total.biomass", "hr", "recruitment"),
  ncol = NULL,
  colors = NULL,
  base_size = 8,
  legend_title = "Left-out\ncomponent"
)

Arguments

lo_fit

A list of g3_fit objects originating from a leave-out analysis. See details.

vars

Character vector giving the variables to plot. Only the default parameters are currently implemented.

ncol

Number of columns to be used in the plot. Set to NULL for standard layout.

colors

Vector of colors to use for leave-out component names. If a named vector, the component names are sorted following the order in the legend.

base_size

Base size parameter for ggplot. See ggtheme.

legend_title

Character speficfying the title for legend (color mapping)

Value

A ggplot object.


Plot likelihood summary

Description

Plot likelihood summary

Usage

plot_likelihood(
  fit,
  type = "total",
  log_scale = FALSE,
  use_proportions = TRUE,
  base_size = 8
)

Arguments

fit

A gadget fit object. See g3_fit.

type

Character specifying the plot type. Options: "direct", "weighted" or "total". See Details.

log_scale

Logical indicating whether the value axis should be log10 transformed.

use_proportions

Logical indicating whether proportions of summed likelihood scores should be used instead of summed likelihood score values when type = "total".

base_size

Base size parameter for ggplot. See ggtheme.

Details

Possible plot types are:

direct

Plots direct comparisons of data with model output.

weighted

Plots the weighted likelihood value for each component.

total (or any other string)

Plots the sums of weighted and raw likelihood values by component.

Value

A ggplot object.

Examples

data(fit)
plot_likelihood(fit)
plot_likelihood(fit, use_proportions = FALSE, log_scale = TRUE)
plot_likelihood(fit, type = "weighted")

Plot parameter values relative to their boundaries

Description

Plot parameter values relative to their boundaries

Usage

plot_param(fit, out_only = FALSE, base_size = 8)

Arguments

fit

A gadget fit object or a data frame containing model parameters. See g3_fit.

out_only

Logical indicating whether only parameters outside their boundaries should be plotted.

base_size

Base size parameter for ggplot. See ggtheme.

Details

The default plot is likely busy. Use plotly::ggplotly() to make it easier to interpret. If you are after parameters that are outside their boundaries, the out_only argument will help.

Value

A ggplot object.

Examples

data(fit)
plot_param(fit)
plot_param(fit, out_only = TRUE)

Plot recruitment

Description

Plot recruitment

Usage

plot_rec(
  fit,
  panelrow = FALSE,
  stocks = NULL,
  return_data = FALSE,
  base_size = 8,
  scale = c("millions", "billions", "thousands")
)

Arguments

fit

A gadget fit object. See g3_fit.

panelrow

something here

stocks

Character specifying the stock to plot in fit. If NULL, all stocks are plotted. If "total", total recruitment will be plotted instead.

return_data

Logical indicating whether to return data for the plot instead of the plot itself.

base_size

Base size parameter for ggplot. See ggtheme.

scale

Character specifying the display unit of recruitment: "millions" (default), "billions" or "thousands".

Value

A ggplot object.

Examples

data(fit)
plot_rec(fit)
plot_rec(fit, stocks = "total")

Plot residuals for catch distributions

Description

Produces a residual plot for each catchdist.fleets component.

Usage

plot_resid(fit, base_size = 8)

Arguments

fit

A gadget fit object. See g3_fit.

base_size

Base size parameter for ggplot. See ggtheme.

Value

A ggplot object.

Examples

data(fit)
plot_resid(fit)

Plot model biomass from a retrospective analysis

Description

Plot model biomass from a retrospective analysis

Usage

plot_retro(
  retro_fit,
  var = "total.biomass",
  by_stock = TRUE,
  min_catch_length = NULL,
  base_size = 8,
  ncol = NULL
)

Arguments

retro_fit

A list of g3_fit objects that differ in their terminal year, i.e. the result of a retrospective analysis. The first object should have no years removed and the objects should be sorted chronologically with increasing number of years removed.

var

Character argument defining the variable to plot. Only "total.biomass" and "hr" are currently implemented.

by_stock

Logical indicating whether to produce plots by stock in addition to total biomass.

min_catch_length

Numeric value defining the minimum catch length (size), which will be used to filter (>=) the model population before calculating harvest rates using catches. Combines all stocks. Turn of by setting to NULL (default). Set to 0 to get HR for the entire model population. See Details.

base_size

Base size parameter for ggplot. See ggtheme.

ncol

Number of columns to be used in the plot.

Value

A ggplot object.


Plot survey indices

Description

Plot survey indices

Usage

plot_si(fit, type = "model_fit", base_size = 8)

Arguments

fit

A gadget fit object. See g3_fit.

type

Character specifying the plot type: "model_fit" plots the model fit to survey index data by year, "regression" plots regression lines together with logarithms of model biomass/abundance and observed index values, and "scatter" produces a scatter plot for the predicted and observed index using the same values than in "model_fit". See details.

base_size

Base size parameter for ggplot. See ggtheme.

Details

Relationship between a survey index (I) and model biomass or abundance (B) over a defined length range is expressed as I=eaBbI = e^a B^b, where eae^a is the catchability (also called q) and b the stock size dependent catchability (see type = "model_fit"). Whether I is compared to model biomass or abundance, depends on the units of I (i.e. column name of the data object; "number" -> abundance, "weight" -> biomass). The survey index I is called "observed" in the figure, and "predicted" is derived as exp(a+b  log(B))exp(a + b \; log(B)). The a and b can be visualized using a log-linear formula log(I)=a+b  log(B)log(I) = a + b \; log(B) (see type = "regression"; log-linear regressions shown using blue lines). The coefficient of determination R2R^2 is calculated using this regression. To compare the observed and predicted values in the model fit plot, use type = "scatter". The grey line represents a diagonal line with a slope of 1 and intercept of 0 (i.e. I=BI = B, a=0a = 0, b=1b = 1).

Value

A ggplot object.

Examples

data(fit)
plot_si(fit)
plot_si(fit, type = "regression")
plot_si(fit, type = "scatter")

Plot stock-recruitment relationship

Description

Plots spawning stock biomass (SSB) against recruitment with a lag

Usage

plot_sr(
  fit,
  spawning_stock = NULL,
  lag = 1,
  years = NULL,
  add_line = TRUE,
  base_size = 8
)

Arguments

fit

A gadget fit object. See g3_fit.

spawning_stock

Either character defining the name of the stock that should be understood as spawning stock, or numeric giving the minimum length of spawning fish. If NULL, all stocks are used.

lag

Integer giving the number of time steps that should be used as a lag between SSB and recruitment.

years

A vector of recruitment years to include. If NULL, all years will be used.

add_line

Add a line connecting years

base_size

Base size parameter for ggplot. See ggtheme.

Value

A ggplot object or a list of such objects depending on the stocks argument.

Examples

data(fit)
plot_sr(fit, spawning_stock = "ghl_female_mat")
plot_sr(fit, spawning_stock = 45)

Plot spawning stock biomass

Description

Plot spawning stock biomass

Usage

plot_ssb(fit, spawning_stock = NULL, base_size = 8)

Arguments

fit

A gadget fit object. See g3_fit.

spawning_stock

Character specifying the name of the spawning stock in the fit object (i.e. the female mature stock). If NULL, the correct stock is guessed.

base_size

Base size parameter for ggplot. See ggtheme.

Value

A ggplot object.

Examples

data(fit)
plot_ssb(fit, spawning_stock = "ghl_female_mat")

Plot model stock composition

Description

Plots proportions of stocks in the model by length or age

Usage

plot_stockcomp(fit, type = "line", by_age = FALSE, base_size = 8)

Arguments

fit

A gadget fit object. See g3_fit.

type

Character specifying the plot type. Options: "line" or "area". See examples.

by_age

Logical indicating whether age should be used on the x-axis instead of length

base_size

Base size parameter for ggplot. See ggtheme.

Value

A ggplot object or a list of such objects depending on the type argument.

Examples

data(fit)
plot_stockcomp(fit)
plot_stockcomp(fit, type = "area")
plot_stockcomp(fit, by_age = TRUE)

Plot stock distribution

Description

Plots proportions of stocks by length or age in fit$stockdist

Usage

plot_stockdist(
  fit,
  stocks = NULL,
  name = NULL,
  type = "step",
  show_intervals = FALSE,
  color_palette = "default",
  base_size = 8
)

Arguments

fit

A gadget fit object. See g3_fit.

stocks

Character vector specifying the stock to plot in fit. If NULL, all stocks are plotted in a single plot. If "separate", all stocks are plotted in separate plots.

name

Character vector specifying the likelihood component to plot in unique(fit$stockdist$name). If NULL, all components are plotted as a list.

type

Character specifying the plot type: "step" uses stepwise lines to show the aggregation intervals. "line" uses lines through average values between lower and upper intervals. If you want to show the aggregation intervals and to use average values (i.e. smooth lines), use the show_intervals argument.

show_intervals

Logical indicating whether length intervals should be plotted.

color_palette

A function defining the color palette or a vector of colors to be used for stocks.

base_size

Base size parameter for ggplot. See ggtheme.

Details

Plots model fit to data using likelihoods. Separate plot for each unique(fit$stockdist$name).

Value

A ggplot object or a list of such objects depending on the stocks argument.

Examples

data(fit)
# Only one dataset to save space:
plot_stockdist(fit, name = "EggaN_matp")
plot_stockdist(fit, name = "EggaN_matp", stocks = "separate",
               color_palette = NULL)
plot_stockdist(fit, name = "EggaN_matp", type = "line", show_intervals = TRUE)

Plot suitability

Description

Plot suitability

Usage

plot_suitability(
  fit,
  fleets = "all",
  add_models = TRUE,
  include_missing = TRUE,
  base_size = 8
)

Arguments

fit

A gadget fit object. See g3_fit.

fleets

Character vector specifying the fleets to plot in fit. If NULL, all fleets will be plotted in separate plots. Use "all" to plot all fleets to the same plot.

add_models

Logical indicating whether models using suitability parameters should be plotted together with the suitabilities estimated from data. The name of the parameter has to be similar to the fleet name. Uses grep and does not always work.

include_missing

Logical indicating whether years with missing catch data should be plotted.

base_size

Base size parameter for ggplot. See ggtheme.

Details

Fleets whose suitability depends on age (the suitability table has non-missing ages, e.g. a selectivity defined by age rather than length) are plotted against age instead of length, since such a fleet has one suitability value per age at every length. With fleets = "all" or several fleets, length- and age-based fleets cannot share an axis: if both are selected, the age-based ones are left out with a message.

Value

A ggplot object. If fleet = NULL, a list of ggplot objects.

Examples

data(fit)
plot_suitability(fit)
plot_suitability(fit, fleets = "EggaN_survey",
                 include_missing = FALSE)

Plot parameter weights

Description

Plot parameter weights

Usage

plot_weight(fit, log_scale = FALSE, base_size = 8)

Arguments

fit

A gadget fit object. See g3_fit.

log_scale

Logical indicating whether the value axis should be log10 transformed.

base_size

Base size parameter for ggplot. See ggtheme.

Value

A ggplot object.

Examples

data(fit)
plot_weight(fit)
plot_weight(fit, log_scale = TRUE)

Plot gadget.fit object

Description

A wrapper function to plot the results from a gadget.fit object.

Usage

## S3 method for class 'gadget.fit'
plot(x, param = "annual", ...)

Arguments

x

A gadget fit object. See g3_fit.

param

Character defining the parameter to plot. See Details.

...

Additional parameters passed to the separate plotting functions.

Details

A wrapper to plot the results from a gadget.fit object. The function produces a different plots defined by param argument and additional arguments passed to the respective functions.

Valid param options are:

annual

Annual summary of central model data. Uses plot_annual

biomass

Stock biomass. Uses plot_biomass

total

Stock biomass with total. Uses plot_biomass(..., total = TRUE)

abundance

Stock abundance. Uses plot_biomass(..., biomass = FALSE)

ssb

Spawning stock biomass. Uses plot_ssb

rec

Recruitment. Uses plot_rec

f

Fishing mortality. Uses plot_f

catch

Catches by stock. Uses plot_catch(..., type = "stock")

catch

Catches by fleet. Uses plot_catch(..., type = "fleet")

hr

Harvest rate. Uses plot_catch(..., type = "hr")

si

Survey indices. Uses plot_si

catchdist

Catch distribution comparison to data. Uses plot_catchdist

stockdist

Stock distribution comparison to data. Uses plot_stockdist

stockcomp

Model stock composition. Uses plot_stockcomp

suitablity

Suitability (fleet selection). Uses plot_suitability

growth

Average length by age. Uses plot_growth

agelength

Age-length (growth parameter) fit. Uses plot_agelength

agecomp

Age composition. Uses plot_agecomp

resid

Residuals. Uses plot_resid

likelihood

Likelihood scores. Uses plot_likelihood

weighted

Weighted likelihood scores. Uses plot_likelihood(..., type = "weighted")

pie

Proportion of summed weighted likelihood scores. Uses plot_likelihood(..., type = "pie")

weight

Parameter component weights

params

Parameter values relative to their boundaries

Value

Single or a list of ggplot objects depending on the arguments.


Sex input data to gadget

Description

Sex input data to gadget

Usage

sexratio_example

Format

Data frame with gadget attributes containing Greenland halibut sex distributions (i.e. sex at length data) from the Barents Sea Ecosystem Survey.

Source

Joint Russian-Norwegian Arctic Fisheries Working Group

See Also

Other datasets: aldist_example, example_catches, fit, ldist_example, stockdist_example


Maturity input data to gadget

Description

Maturity input data to gadget

Usage

stockdist_example

Format

Data frame with gadget attributes containing Greenland halibut stock distributions (i.e. maturity and sex at length data) from the Institute of Marine Research EggaNord survey.

Source

Joint Russian-Norwegian Arctic Fisheries Working Group

See Also

Other datasets: aldist_example, example_catches, fit, ldist_example, sexratio_example