Package 'stockplotr'

Title: Tables and Figures for Stock Assessments
Description: Creates exploratory and finished tables and figures for stock assessment documents from U.S. stock assessment model outputs. This packages addresses parts of the stock assessment workflow that interprets outputs of stock assessment models as well as allows the analyst to create report ready tables and figures, reducing the need to create their own and format then when adding into a report. This package is intended to be used in conjuction with 'asar', a partially automated template for writing various stock assessment reports. Throughout development, we will be creating a set of standardized figures and tables for a stock assessment report, developing functions to produce a variety of diagonostic plots, and other helpful materials. The advantage of using this package over others is that it applies to a range of stock assessment model outputs and standardizes them.
Authors: Samantha Schiano [aut, cre] (ORCID: <https://orcid.org/0009-0003-3744-6428>), Sophie Breitbart [aut, ctb] (ORCID: <https://orcid.org/0000-0001-9641-9786>), Steve Saul [aut], Kelli Johnson [ctb] (ORCID: <https://orcid.org/0000-0002-5149-451X>), Megumi Oshima [ctb] (ORCID: <https://orcid.org/0000-0002-8249-1442>)
Maintainer: Samantha Schiano <[email protected]>
License: MIT + file LICENSE
Version: 0.11.1.9000
Built: 2026-05-28 14:43:32 UTC
Source: https://github.com/nmfs-ost/stockplotr

Help Index


Add NOAA formatting to figure or table

Description

Add NOAA formatting to figure or table

Usage

add_theme(x, discrete = TRUE)

Arguments

x

table or figures object from ggplot, base r plot, gt table, flextable, or kable extra

discrete

TRUE/FALSE indicate if data input is discrete. Specifically applied to plots.

Default: TRUE

Details

Currently, the function is able to format objects from: ggplot (ggplot2), base r plot, flextable (flextable), gt tables (gt), and kable tables (kableExtra).

Value

Add the standard formatting for stock assessment reports for any figure or table.

Examples

add_theme(ggplot2::ggplot(data = cars, ggplot2::aes(x = speed, y = dist)) +
  ggplot2::geom_point())

Create loop to test for differences in column values

Description

Create loop to test for differences in column values

Usage

check_label_differences(dat, index_variables, id_group = NULL)

Arguments

dat

input data into process_table

index_variables

the index_variables vector created within process_table

id_group

the identifying index variable as a string

Default: NULL


Convert Output

Description

Format stock assessment output files to a standardized format.

Usage

convert_output(file, model = NULL, fleet_names = NULL, save_dir = NULL)

Arguments

file

Assessment model output file path

model

Assessment model used in evaluation

Default: NULL

Options: "ss3", "bam", "fims", "rceattle"

fleet_names

Names of fleets in the assessment model as shortened in the output file. If fleet names are not properly read, then indicate the fleets names as an acronym in a vector

Default: NULL

save_dir

File path to save the converted output file.

Default: NULL

Details

The resulting object is simply a transformed and machine readable version of a model output file. Converted data frame is always returned. It will also be saved if save_dir is not NULL.

Value

A reformatted and standardized version of assessment model results for application in building a stock assessment reports and to easily adapt results among regional assessments.

Author(s)

Samantha Schiano

Examples

## Not run: 
convert_output(
  file = here::here("model1", "Report.sso"),
  model = "ss3",
  fleet_names = c("TWL", "NONTWL"),
  save_dir = here::here("standard_output.rda")
)

## End(Not run)

Create the rda package for a plot or table

Description

Create the rda package for a plot or table

Usage

create_latex_table(data, caption, label)

Arguments

data

A dataframe-based table

caption

A string comprising the table caption

label

A string comprising the table label

Value

A table based in LaTeX.

Examples

create_latex_table(
  data = as.data.frame(head(mtcars, 6)),
  caption = "My caption",
  label = "My label"
)

Create the rda package for a plot or table

Description

Create the rda package for a plot or table

Usage

create_rda(
  object,
  topic_label,
  fig_or_table,
  dat,
  dir = getwd(),
  year = format(as.POSIXct(Sys.Date(), format = "%YYYY-%mm-%dd"), "%Y"),
  ref_line = "msy",
  scale_amount = 1,
  unit_label = "mt",
  table_df = NULL
)

Arguments

object

Table or plot object

topic_label

A string that names the object

fig_or_table

A string identifying if the object is a "table" or "figure"

dat

Data frame containing data which will fill in captions and alternative text for the object

dir

Directory to where the rda will be saved

Default: the working directory ('getwd()')

year

Assessment year

Default: the current year

ref_line

Reference line value

Default: "msy"

Options: Including, but not limited to: "msy", "target", "unfished"

scale_amount

A number describing how much to scale down the quantities shown on the y axis. For example, scale_amount = 100 would scale down a value from 500,000 –> 5,000. This scale will be reflected in the y axis label.

Default: 1

unit_label

A string containing a unit label for the y-axis

Default: "mt"

table_df

The data frame that the table will be made into for purposes of exporting a latex formatted table.

Value

An rda package for a plot or table object. Requires an object from the R environment such as a ggplot or flextable object.

See Also

[export_rda()], [extract_caps_alttext()]

Examples

## Not run: 
create_rda(
  object = my_plot,
  topic_label = "my_plot",
  fig_or_table = "figure",
  dat = my_data,
  dir = "path/to/save"
)

## End(Not run)

SS3 Example data

Description

Included data set that represents a Report.sso file converted using convert_output(). This example is from the 2022 Petrale sole stock assessment.

Usage

example_data

Format

A tibble with 591109 rows and 33 variables:

label

standard name for estimate or value name

estimate

actual value of the label

year

annual indexing value

fleet

names of fleets or surveys indexed by the data

sex

native reference to male, female, unknown, or none

area

specified areas by the model

growth_pattern

indexing column of data

uncertainty

value of uncertainty associated with the label column

uncertainty_label

uncertainty label or name associated with the label columns

module_name

name of keyword (SS3) or list indexing in the original model output for tracking purposes

time

time sometimes referenced in decimals to the year and month

era

"time" for current time series in model; "fore" representing the projected or forecasted years of the model

month

month factor

season

season usually associated with year

subseason

subseason when used

birthseas

birthseason found in SS3

initial

initial input value in the model when available associated with the label column

likelihood

likelihood value for the data point

platoon

platoon also an SS3 indexing value

age

age of fish

bio_pattern

indexing column of data

settlement

indexing column of data

morph

indexing column of data

type

indexing column of data

factor

indexing column of data

part

indexing column of data

kind

indexing column of data

nsim

indexing column of data

bin

indexing column of data

age_a

alternative age column

length_bins

length bins for composition or other length based data

count

indexing column of data

block

indexing column of data


Export updated key quantities template

Description

Export updated key quantities template

Usage

export_kqs(...)

Arguments

...

Key quantities whose values should be added to the exported "key_quantities.csv"

Value

Exports a file based on key quantities template, with values added next to the names of the key quantities specified as ellipsis arguments. File is saved as "key_quantities.csv" to the working directory.

See Also

[fill_in_kqs()], [insert_kqs()]

Examples

## Not run: 
export_kqs(
  F.min,
  F.max
)

## End(Not run)

Export a figure or table to rda

Description

Export a figure/table, and its caption and alternative text, to an rda object. Typically used after stockplotr::extract_caps_alttext().

Usage

export_rda(
  object = NULL,
  caps_alttext = NULL,
  figures_tables_dir = NULL,
  topic_label = NULL,
  fig_or_table = NULL,
  latex_table = NULL
)

Arguments

object

The final figure (ggplot) or table (flextable) object.

Default: NULL

caps_alttext

The object containing a figure's caption and alternative text, in a list, or a table's caption, likely generated with stockplotr::extract_caps_alttext().

Default: NULL

figures_tables_dir

If the user has already created folders containing figures and tables ("figures" and "tables"), figures_tables_dir represents the location of these folders. Otherwise, these two folders will be created automatically, then used to store the exported rda files.

Default: NULL

topic_label

A string that describes a figure or table's label. These labels are found in the "label" column of the "captions_alt_text.csv" file and are used to link the figure or table with its caption/alt text.

Default: NULL

fig_or_table

A string describing whether the plot is a figure or table.

Default: NULL

Options: "figure", "table"

latex_table

The object containing a LaTeX-based table.

Default: NULL

Value

An rda file with a figure's ggplot, caption, and alternative text, or a table's gt-based table, caption, and LaTeX-based table.

See Also

[create_rda()], [extract_caps_alttext()]

Examples

## Not run: 
export_rda(
  final = final_table_object,
  caps_alttext = caps_alttext_object,
  figures_tables_dir = here::here(),
  topic_label = "bnc",
  fig_or_table = "table",
  latex_table = "latex_table"
)

export_rda(
  final = final_figure_object,
  caps_alttext = another_caps_alttext_object,
  figures_tables_dir = "my_figures_tables_dir",
  topic_label = "landings",
  fig_or_table = "figure"
)

## End(Not run)

Extract captions and alternative texts

Description

Extract a figure or table's caption and alternative text for usage when generating a figure or table. Typically used before stockplotr::export_rda().

Usage

extract_caps_alttext(topic_label = NULL, fig_or_table = NULL, dir = getwd())

Arguments

topic_label

A string that describes a figure or table's label. These labels are found in the "label" column of the "captions_alt_text.csv" file and are used to link the figure or table with its caption/alt text.

Default: NULL

fig_or_table

A string describing whether the plot is a figure or table.

Default: NULL

dir

The directory containing the "captions_alt_text.csv" file.

Default: the working directory ('getwd()')

Value

A figure's caption and alternative text, in a list, or a table's caption.

See Also

[export_rda()], [create_rda()]

Examples

## Not run: 
extract_caps_alttext(
  topic_label = "biomass",
  fig_or_table = "figure",
  dir = here::here()
)

extract_caps_alttext(
  topic_label = "bnc",
  fig_or_table = "table",
  dir = getwd()
)

## End(Not run)

Substitute key quantities' values into template

Description

Substitute key quantities' values into template

Usage

fill_in_kqs(df, ...)

Arguments

df

Dataframe created by importing "key_quantity_template.csv" or "key_quantities.csv", empty or partially-filled templates with key quantity names and other associated information

...

Key quantity objects whose values will be added to the output dataframe

Details

The returned dataframe is input for [fill_in_kqs()].

Value

Dataframe based on key quantities template that contains newly-added values of key quantities indicated via ellipsis.

See Also

[export_kqs()], [insert_kqs()]

Examples

## Not run: 
fill_in_kqs(
  df = data,
  F.min,
  F.max
)

## End(Not run)

Filter data for input into aesthetics for ggplot2

Description

Filter data for input into aesthetics for ggplot2

Usage

filter_data(
  dat,
  label_name,
  module = NULL,
  era = NULL,
  geom,
  group = NULL,
  facet = NULL,
  scale_amount = 1,
  interactive = TRUE
)

Arguments

dat

A tibble or named list of tibbles (input as 'list()') returned from convert_output.

If inputting a list of tibbles, the first tibble's reference point defined in 'ref_line' is used to plot a reference line or calculate relative spawning biomass.

label_name

a string of the name of the label that is used to filter the data.

module

(Optional) A string indicating the module_name found in 'dat'. If selecting >1 module, place them in a vector like c("module1", "module2").

Default: NULL

If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso [filter_data()]

era

A string naming the era of data.

Default: "time"

Options: "early", "time", "fore" (forecast), or NULL (all data)

geom

A string stating the geom used for the plot.

Default: "line".

Options: "line", "point", or "area"

group

A string of a single column that groups the data.

Set group = "none" to summarize data over all indexing values.

Default: NULL Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", NULL

facet

A string or vector of strings of a column name.

Default: NULL

scale_amount

A number to scale the y-axis values.

Default: 1

interactive

A logical value indicating if the environment is interactive.

Default: 'FALSE'

Value

a data frame that is preformatted for plotting with ggplot2.

Examples

## Not run: 
filter_data(dat, "biomass", "line", group = "fleet")

## End(Not run)

Make an html file with all figures and tables

Description

Show all tables and figures in a single html file.

Usage

html_all_figs_tables(figures_tables_dir = getwd())

Arguments

figures_tables_dir

The location of the folder containing figures and tables ("figures" and "tables").

Default: The current working directory ('getwd()')

Value

A folder ("all_tables_figures") in your working directory containing html and qmd files that show all tables and figures.

See Also

asar::create_figures_doc(), asar::create_tables_doc()

Examples

## Not run: 
html_all_figs_tables()
html_all_figs_tables(figures_tables_dir = "my_figures_tables_dir")

## End(Not run)

Insert key quantities into the captions and alternative text file

Description

Insert key quantities into the captions and alternative text file

Usage

insert_kqs(...)

Arguments

...

Key quantities whose values should be added to the exported "captions_alt_text.csv"

Value

Exports a file ("captions_alt_text.csv") containing captions and alternative text for figures and tables, with key quantities inserted into the "captions_alt_text_template.csv" template's placeholders.

See Also

[fill_in_kqs()], [export_kqs()]

Examples

## Not run: 
insert_kqs(
  F.min,
  F.max
)

## End(Not run)

Rename columns and merge estimate and uncertainty columns for table presentation

Description

Rename columns and merge estimate and uncertainty columns for table presentation

Usage

merge_error(table_data, uncert_lab, fleets, label, unit_label)

Arguments

table_data

list of dataframes that will be eventually turned into tables

uncert_lab

uncertainty label. Typically inherited from another function but is the exact string of the uncertainty in the data (e.g., "sd", "se", "cv", "uncertainty").)

fleets

Vector of fleet names.

label

Label name of target quantity that is being presented by the table.

unit_label

String. The units of the estimate being presented in the table.

Value

List of formatted dataframes that contain column names formatted for a table along with a merge of values in the estimate and error columns to reduce redundancy in the table.


Create "at-age" plot

Description

Create "at-age" plot

Usage

plot_aa(
  dat,
  x = "year",
  y = "age",
  z = "estimate",
  label = "Abundance",
  xlab = "Year",
  ylab = "Age",
  facet = NULL,
  proportional = TRUE,
  ...
)

Arguments

dat

filtered data frame from standard output file(s) preformatted for the target label from filter_data

x

a string of the column name of data used to plot on the x-axis

Default: "year"

y

a string of the column name of data used to plot on the y-axis

Default: "age"

z

a string of the column name of data used to control the size of the bubbles

Default: "estimate"

label

a string of the label for the size of the bubbles

Default: "Abundance"

xlab

a string of the x-axis label

Default: "Year"

ylab

a string of the y-axis label

Default: "Age"

facet

a string or vector of strings of a column that facets the data. It is not recommended to include more than one facet due to the complexity of the plot.

Default: NULL

Options: Including, but not limited to: "sex", "area", "fleet"

proportional

Set size of points relative to z when TRUE, point size are relative to one another while when set to FALSE, point size is relative to z

Default: 'TRUE'

...

inherited arguments from internal functions from geom_point

Value

Create a plot of abundance at age for a stock assessment report.

Examples

## Not run: 
plot_aa(dat)

## End(Not run)

Plot Abundance at Age

Description

Plot Abundance at Age

Usage

plot_abundance_at_age(
  dat,
  facet = NULL,
  unit_label = "fish",
  scale_amount = 1000,
  proportional = TRUE,
  make_rda = FALSE,
  figures_dir = getwd()
)

Arguments

dat

A data frame returned from convert_output

facet

a string or vector of strings of a column that facets the data. Set facet = "none" to summarize the data in a single plot.

Default: NULL

Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", NULL

unit_label

units for abundance

Default: "fish"

scale_amount

A number describing how much to scale down the abundance at age. Please choose a value ranging from 1-1,000,000,000 (one billion) in orders of magnitude (e.g., 1, 10, 100, 1000, etc.). For example, scale_amount = 100 would scale down a value from 500,000 –> 5,000 and would report abundance in hundreds of fish (if "fish" was the unit_label). This scale will be reflected in the legend label if proportional is set to FALSE.

Default: 1,000

proportional

Set size of points relative to z when TRUE, point size are relative to one another while when set to FALSE, point size is relative to z

Default: 'TRUE'

make_rda

TRUE/FALSE; indicate whether to produce an .rda file containing a list with the figure/table, caption, and alternative text (if figure). If TRUE, the .rda will be exported to the folder indicated in the argument "rda_dir".

Default: 'FALSE'

figures_dir

The location of the folder containing the generated .rda files ("rda_files") that will be created if the argument 'make_rda' = TRUE.

Default: the working directory ('getwd()')

Details

The input is from an assessment model output file translated to a standardized output (convert_output). There are options to return a 'ggplot2' object or export an .rda object containing associated caption and alternative text for the figure.

Value

A plot showing total abundance (or numbers) at age.

See Also

[convert_output()], [filter_data()], [process_data()], [plot_aa()], [export_kqs()], [insert_kqs()], [create_rda()]

Examples

plot_abundance_at_age(
  dat = stockplotr:::example_data,
  facet = "growth_pattern",
  unit_label = "fish",
  scale_amount = 1000,
  proportional = TRUE
)
plot_abundance_at_age(
  dat = stockplotr:::example_data,
  facet = "none",
  proportional = FALSE
)

Plot Total Biomass

Description

Plot Total Biomass

Usage

plot_biomass(
  dat,
  geom = "line",
  group = NULL,
  facet = NULL,
  ref_line = "msy",
  era = NULL,
  unit_label = "mt",
  module = NULL,
  scale_amount = 1,
  relative = FALSE,
  make_rda = FALSE,
  figures_dir = getwd(),
  interactive = TRUE,
  ...
)

Arguments

dat

A tibble or named list of tibbles (input as 'list()') returned from convert_output.

If inputting a list of tibbles, the first tibble's reference point defined in 'ref_line' is used to plot a reference line or calculate relative spawning biomass.

geom

A string stating the geom used for the plot.

Default: "line".

Options: "line", "point", or "area"

group

A string of a single column that groups the data.

Set group = "none" to summarize data over all indexing values.

Default: NULL Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", NULL

facet

A string or vector of strings of a column name.

Default: NULL

ref_line

A string specifying the type of reference you want to compare biomass to. The default '"msy"' looks for '"biomass_msy"' in the '"label"' column of 'dat'. The actual searching in 'dat' is case-agnostic and will work with either upper- or lower-case letters. However, you must use one of the options specified in the default list to ensure that the label on the figure looks correct regardless of how it is specified in 'dat'.

Default: "msy"

Options: Including, but not limited to: "target", "MSY", "unfished"

era

A string naming the era of data.

Default: "time"

Options: "early", "time", "fore" (forecast), or NULL (all data)

unit_label

units for biomass

Default: "mt"

module

(Optional) A string indicating the module_name found in 'dat'. If selecting >1 module, place them in a vector like c("module1", "module2").

Default: NULL

If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso [filter_data()]

scale_amount

A number to scale the y-axis values.

Default: 1

relative

A logical value specifying to set y-axis values relative to the ref_line value.

Default: 'FALSE'

make_rda

A logical value indicating whether to save the object and make an automated caption and alternative text in the form of an 'rda' object. If TRUE, the rda will be exported to the folder indicated in the argument "figures_dir".

Default: 'FALSE'.

figures_dir

A string indicating a path to the "figures" folder.

Default: 'getwd()'

The folder is created within the path if it does not exist.

interactive

A logical value indicating if the environment is interactive.

Default: 'FALSE'

...

Arguments called from geom_line or geom_point

Details

The input is from an assessment model output file translated to a standardized output (convert_output). There are options to return a 'ggplot2' object or export an .rda object containing associated caption and alternative text for the figure.

Value

A plot showing total biomass.

See Also

[convert_output()], [plot_timeseries()], [calculate_reference_point()], [reference_line()], [filter_data()], [process_data()], [export_kqs()], [insert_kqs()], [create_rda()]

Examples

plot_biomass(
  dat = stockplotr:::example_data,
  unit_label = "mt",
  ref_line = c("target" = 20000),
  scale_amount = 100,
  module = "TIME_SERIES",
  figures_dir = getwd()
)
plot_biomass(
  dat = stockplotr:::example_data,
  ref_line = NULL,
  module = "TIME_SERIES",
  figures_dir = getwd()
)

Plot Total Biomass at Age (BAA)

Description

Plot Total Biomass at Age (BAA)

Usage

plot_biomass_at_age(
  dat,
  facet = NULL,
  unit_label = "mt",
  scale_amount = 1000,
  proportional = TRUE,
  interactive = TRUE,
  make_rda = FALSE,
  figures_dir = getwd()
)

Arguments

dat

A data frame returned from convert_output

facet

a string or vector of strings of a column that facets the data. Set facet = "none" to summarize the data in a single plot.

Default: NULL

Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", NULL

unit_label

units for abundance

Default: "fish"

scale_amount

A number describing how much to scale down the biomass at age. For example, scale_amount = 100 would scale down a value from 500,000 –> 5,000. This scale will be reflected in the legend label if proportion is set to FALSE.

Default: 1,000

proportional

Set size of points relative to z when TRUE, point size are relative to one another while when set to FALSE, point size is relative to z

Default: 'TRUE'

interactive

TRUE/FALSE; indicate whether the environment in which the function is operating is interactive. This bypasses some options for filtering when preparing data for the plot.

Default: 'TRUE'

make_rda

TRUE/FALSE; indicate whether to produce an .rda file containing a list with the figure/table, caption, and alternative text (if figure). If TRUE, the .rda will be exported to the folder indicated in the argument "rda_dir".

Default: 'FALSE'

figures_dir

The location of the folder containing the generated .rda files ("rda_files") that will be created if the argument 'make_rda' = TRUE.

Default: the working directory ('getwd()')

Details

The input is from an assessment model output file translated to a standardized output (convert_output). There are options to return a 'ggplot2' object or export an .rda object containing associated caption and alternative text for the figure.

Value

A plot showing total biomass at age.

See Also

[convert_output()], [filter_data()], [process_data()], [plot_aa()], [export_kqs()], [insert_kqs()], [create_rda()]

Examples

plot_biomass_at_age(
  dat = stockplotr:::example_data,
  unit_label = "mt",
  scale_amount = 100,
  proportional = FALSE, # displays legend
  make_rda = FALSE
)
plot_biomass_at_age(
  dat = stockplotr:::example_data,
  unit_label = "mt",
  facet = "none",
  proportional = FALSE
)

Plot catch composition

Description

Plot catch composition

Usage

plot_catch_comp(
  dat,
  facet = NULL,
  era = "time",
  unit_label = "mt",
  scale_amount = 1,
  proportional = TRUE,
  interactive = TRUE,
  module = NULL,
  make_rda = FALSE,
  figures_dir = getwd()
)

Arguments

dat

A data frame returned from convert_output

facet

a string or vector of strings of a column that facets the data. Set facet = "none" to summarize the data in a single plot.

Default: NULL

Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", NULL

era

A string naming the era of data.

Default: "time"

Options: "early", "time", "fore" (forecast), or NULL (all data)

unit_label

indicate the name of the units of catch as to label the axis

Default: "mt"

scale_amount

A number describing how much to scale down the catch at age. Please choose a value ranging from 1-1,000,000,000 (one billion) in orders of magnitude (e.g., 1, 10, 100, 1000, etc.). For example, scale_amount = 100 would scale down a value from 500,000 –> 5,000 and would report catch in hundreds of the 'unit_label'. This scale will be reflected in the legend label if proportional is set to FALSE.

Default: 1

proportional

Set size of points relative to z when TRUE, point size are relative to one another while when set to FALSE, point size is relative to z

Default: 'TRUE'

interactive

A logical value indicating if the environment is interactive.

Default: 'FALSE'

module

(Optional) A string indicating the module_name found in 'dat'. If selecting >1 module, place them in a vector like c("module1", "module2").

Default: NULL

If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso [filter_data()]

make_rda

TRUE/FALSE; indicate whether to produce an .rda file containing a list with the figure/table, caption, and alternative text (if figure). If TRUE, the .rda will be exported to the folder indicated in the argument "rda_dir".

Default: 'FALSE'

figures_dir

The location of the folder containing the generated .rda files ("rda_files") that will be created if the argument 'make_rda' = TRUE.

Default: the working directory ('getwd()')

Details

This plot is made only when catch or landings are explicitly named in the output file. The current plot function does not combine all sources of catch. The input is from an assessment model output file translated to a standardized output (convert_output). There are options to return a 'ggplot2' object or export an .rda object containing associated caption and alternative text for the figure.

Value

A plot showing catch or landings composition.

See Also

[convert_output()], [filter_data()], [process_data()], [plot_aa()], [export_kqs()], [insert_kqs()], [create_rda()]

Examples

plot_catch_comp(
  dat = stockplotr:::example_data,
  facet = "fleet",
  unit_label = "mt",
  scale_amount = 100,
  interactive = FALSE,
  make_rda = FALSE,
  figures_dir = getwd()
)

plot_catch_comp(
  dat = stockplotr:::example_data,
  facet = "none",
  unit_label = "mt",
  scale_amount = 100,
  interactive = FALSE,
  era = "fore",
  proportional = FALSE
)

Create plot with error

Description

Create plot with error

Usage

plot_error(
  dat,
  x = "year",
  y = "estimate",
  geom = "point",
  group = NULL,
  facet = NULL,
  xlab = "Year",
  ylab = NULL,
  hline = TRUE,
  ...
)

Arguments

dat

filtered data frame from standard output file(s) preformatted for the target label from filter_data

x

a string of the column name of data used to plot on the x-axis

Default: "year"

y

a string of the column name of data used to plot on the y-axis

Default: "estimate"

geom

type of geom to use for plotting found in ggplot2 (e.g. "point", "line", etc.).

Default: "line"

Options: "point" and "area"

group

a string of a single column that groups the data. Currently can only have one level of grouping.

Default: NULL Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", NULL

facet

a string or vector of strings of a column that facets the data (e.g. "year", "area", etc.)

Default: NULL

xlab

a string of the x-axis label

Default: "Year"

ylab

a string of the y-axis label. If NULL, it will be set to the name of 'y'.

Default: NULL

hline

indicate true or false to place a horizontal line at 1

Default: 'TRUE'

...

inherited arguments from internal functions from ggplot2::geom_xx

Details

The user can create a line, point, or area plot, where the x-axis is year and y can vary for any time series quantity. Currently, grouping is restricted to one group where faceting can be any number of facets.

Value

Create a plot with error for a stock assessment report.


Plot fishing mortality timeseries

Description

Plot fishing mortality timeseries

Usage

plot_fishing_mortality(
  dat,
  geom = "line",
  group = NULL,
  facet = NULL,
  ref_line = "msy",
  era = NULL,
  module = NULL,
  make_rda = FALSE,
  figures_dir = getwd(),
  interactive = TRUE,
  ...
)

Arguments

dat

A tibble or named list of tibbles (input as 'list()') returned from convert_output.

If inputting a list of tibbles, the first tibble's reference point defined in 'ref_line' is used to plot a reference line or calculate relative spawning biomass.

geom

A string stating the geom used for the plot.

Default: "line".

Options: "line", "point", or "area"

group

A string of a single column that groups the data.

Set group = "none" to summarize data over all indexing values.

Default: NULL Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", NULL

facet

A string or vector of strings of a column name.

Default: NULL

ref_line

A string specifying a reference point name.

Default: "target"

Options: (including, but not limited to) "target", "msy", and "unfished" If the reference point is not found in the data, set ref_line = c("name" = value).

era

A string naming the era of data.

Default: "time"

Options: "early", "time", "fore" (forecast), or NULL (all data)

module

(Optional) A string indicating the module_name found in 'dat'. If selecting >1 module, place them in a vector like c("module1", "module2").

Default: NULL

If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso [filter_data()]

make_rda

A logical value indicating whether to save the object and make an automated caption and alternative text in the form of an 'rda' object. If TRUE, the rda will be exported to the folder indicated in the argument "figures_dir".

Default: 'FALSE'.

figures_dir

A string indicating a path to the "figures" folder.

Default: 'getwd()'

The folder is created within the path if it does not exist.

interactive

A logical value indicating if the environment is interactive.

Default: 'FALSE'

...

Arguments called from geom_line or geom_point

Details

The input is from an assessment model output file translated to a standardized output (convert_output). There are options to return a 'ggplot2' object or export an .rda object containing associated caption and alternative text for the figure.

Value

A plot showing fishing mortality over time.

See Also

[convert_output()], [filter_data()], [process_data()], [plot_timeseries()], [reference_line()], [export_kqs()], [insert_kqs()], [create_rda()]

Examples

plot_fishing_mortality(
  dat = stockplotr:::example_data,
  ref_line = c("target" = 0.2),
  group = "fleet",
  interactive = FALSE,
  module = "TIME_SERIES"
)
plot_fishing_mortality(
  dat = stockplotr:::example_data,
  ref_line = c("target" = 0.2),
  group = "none",
  interactive = FALSE,
  module = "TIME_SERIES"
)

Plot Index of Abundance

Description

Plot Index of Abundance

Usage

plot_indices(
  dat,
  unit_label = "",
  group = NULL,
  facet = NULL,
  interactive = TRUE,
  module = NULL,
  focus = NULL,
  make_rda = FALSE,
  figures_dir = getwd(),
  ...
)

Arguments

dat

A tibble or named list of tibbles (input as 'list()') returned from convert_output.

If inputting a list of tibbles, the first tibble's reference point defined in 'ref_line' is used to plot a reference line or calculate relative spawning biomass.

unit_label

units for index of abundance/CPUE

Default: ""

group

A string of a single column that groups the data.

Set group = "none" to summarize data over all indexing values.

Default: NULL Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", NULL

facet

a string or vector of strings of a column that facets the data. "fleet" is always added on to any faceting selections

Default: NULL

Options: May include, but is not limited to: "fleet", "year", "area", NULL

interactive

A logical value indicating if the environment is interactive.

Default: 'FALSE'

module

(Optional) A string indicating the module_name found in 'dat'. If selecting >1 module, place them in a vector like c("module1", "module2").

Default: NULL

If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso [filter_data()]

focus

a string or vector of strings indicating how data should be filtered. (i.e. select names of fleets to zoom into the plot)

Default: NULL

make_rda

A logical value indicating whether to save the object and make an automated caption and alternative text in the form of an 'rda' object. If TRUE, the rda will be exported to the folder indicated in the argument "figures_dir".

Default: 'FALSE'.

figures_dir

A string indicating a path to the "figures" folder.

Default: 'getwd()'

The folder is created within the path if it does not exist.

...

Arguments called from geom_line or geom_point

Details

The input is from an assessment model output file translated to a standardized output (convert_output). There are options to return a 'ggplot2' object or export an .rda object containing associated caption and alternative text for the figure.

Value

A plot showing the expected and predicted indices.

See Also

[convert_output()], [filter_data()], [process_data()], [plot_obsvpred()], [export_kqs()], [insert_kqs()], [create_rda()]

Examples

plot_indices(
  dat = stockplotr:::example_data,
  unit_label = "fish/hr",
  interactive = FALSE
)

Plot observed landings

Description

Plot observed landings

Usage

plot_landings(
  dat,
  unit_label = "mt",
  geom = "line",
  group = NULL,
  facet = NULL,
  lbs = FALSE,
  era = NULL,
  scale_amount = 1,
  module = NULL,
  interactive = TRUE,
  make_rda = FALSE,
  figures_dir = getwd(),
  ...
)

Arguments

dat

A tibble or named list of tibbles (input as 'list()') returned from convert_output.

If inputting a list of tibbles, the first tibble's reference point defined in 'ref_line' is used to plot a reference line or calculate relative spawning biomass.

unit_label

A string specifying spawning biomass unit.

Default: "mt"

geom

A string stating the geom used for the plot.

Default: "line".

Options: "line", "point", or "area"

group

A string of a single column that groups the data.

Set group = "none" to summarize data over all indexing values.

Default: NULL Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", NULL

facet

A string or vector of strings of a column name.

Default: NULL

lbs

A logical value indicating whether to convert the y-axis values from kilograms to pounds. The default units match the default in the unit_label argument - 'mt'.

Default: 'FALSE'

era

A string naming the era of data.

Default: "time"

Options: "early", "time", "fore" (forecast), or NULL (all data)

scale_amount

A number to scale the y-axis values.

Default: 1

module

(Optional) A string indicating the module_name found in 'dat'. If selecting >1 module, place them in a vector like c("module1", "module2").

Default: NULL

If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso [filter_data()]

interactive

A logical value indicating if the environment is interactive.

Default: 'FALSE'

make_rda

A logical value indicating whether to save the object and make an automated caption and alternative text in the form of an 'rda' object. If TRUE, the rda will be exported to the folder indicated in the argument "figures_dir".

Default: 'FALSE'.

figures_dir

A string indicating a path to the "figures" folder.

Default: 'getwd()'

The folder is created within the path if it does not exist.

...

Arguments called from geom_line or geom_point

Details

The input is from an assessment model output file translated to a standardized output (convert_output). There are options to return a 'ggplot2' object or export an .rda object containing associated caption and alternative text for the figure.

Value

A plot showing cumulative landings over time.

See Also

[convert_output()], [filter_data()], [process_data()], [plot_timeseries()], [export_kqs()], [insert_kqs()], [create_rda()]

Examples

plot_landings(
  dat = stockplotr:::example_data,
  unit_label = "metric tons",
  group = "fleet",
  interactive = FALSE,
  make_rda = FALSE
)
plot_landings(
  dat = stockplotr:::example_data,
  unit_label = "metric tons",
  facet = "fleet",
  interactive = FALSE,
  make_rda = FALSE
)

Plot natural mortality (M) at age

Description

Plot natural mortality (M) at age

Usage

plot_natural_mortality(
  dat,
  group = NULL,
  facet = NULL,
  era = NULL,
  interactive = TRUE,
  module = NULL,
  make_rda = FALSE,
  figures_dir = getwd(),
  ...
)

Arguments

dat

A tibble or named list of tibbles (input as 'list()') returned from convert_output.

If inputting a list of tibbles, the first tibble's reference point defined in 'ref_line' is used to plot a reference line or calculate relative spawning biomass.

group

A string of a single column that groups the data.

Set group = "none" to summarize data over all indexing values.

Default: NULL Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", NULL

facet

A string or vector of strings of a column name.

Default: NULL

era

A string naming the era of data.

Default: "time"

Options: "early", "time", "fore" (forecast), or NULL (all data)

interactive

A logical value indicating if the environment is interactive.

Default: 'FALSE'

module

(Optional) A string indicating the module_name found in 'dat'. If selecting >1 module, place them in a vector like c("module1", "module2").

Default: NULL

If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso [filter_data()]

make_rda

A logical value indicating whether to save the object and make an automated caption and alternative text in the form of an 'rda' object. If TRUE, the rda will be exported to the folder indicated in the argument "figures_dir".

Default: 'FALSE'.

figures_dir

A string indicating a path to the "figures" folder.

Default: 'getwd()'

The folder is created within the path if it does not exist.

...

Arguments called from geom_line or geom_point

Details

The input is from an assessment model output file translated to a standardized output (convert_output). There are options to return a 'ggplot2' object or export an .rda object containing associated caption and alternative text for the figure.

Value

A plot showing natural mortality at age.

See Also

[convert_output()], [filter_data()], [process_data()], [plot_timeseries()], [export_kqs()], [insert_kqs()], [create_rda()]

Examples

plot_natural_mortality(
  dat = stockplotr:::example_data,
  module = "Natural_Mortality",
  interactive = FALSE
)

Plot observed vs. predicted data

Description

Plot observed vs. predicted data

Usage

plot_obsvpred(
  dat,
  x = "year",
  y = "estimate",
  observed_label = "observed",
  predicted_label = "predicted",
  geom = "line",
  xlab = "Year",
  ylab = NULL,
  group = NULL,
  facet = NULL,
  ...
)

Arguments

dat

filtered data frame from standard output file(s) preformatted for the target label from filter_data

x

a string of the column name of data used to plot on the x-axis

Default: "year"

y

a string of the column name of data used to plot on the y-axis

Default: "estimate"

observed_label

a string of the label used to filter the observed data

Default: "observed"

predicted_label

a string of the label used to filter the predicted data Default: "predicted"

geom

type of geom to use for plotting found in ggplot2 (e.g. "point", "line", etc.).

Default: "line"

Options: "point" and "area"

xlab

a string of the x-axis label

Default: "Year"

ylab

a string of the y-axis label. If NULL, it will be set to the name of 'y'.

Default: NULL

group

a string of a single column that groups the data. Currently can only have one level of grouping.

Default: NULL Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", NULL

facet

a string or vector of strings of a column that facets the data (e.g. "year", "area", etc.)

Default: NULL

...

inherited arguments from internal functions from ggplot2::geom_xx

Value

A plot of observed vs. predicted data for a stock assessment report.


Plot Recruitment

Description

Plot Recruitment

Usage

plot_recruitment(
  dat,
  unit_label = "mt",
  scale_amount = 1,
  era = NULL,
  group = NULL,
  facet = NULL,
  interactive = TRUE,
  module = NULL,
  make_rda = FALSE,
  figures_dir = getwd(),
  ...
)

Arguments

dat

A tibble or named list of tibbles (input as 'list()') returned from convert_output.

If inputting a list of tibbles, the first tibble's reference point defined in 'ref_line' is used to plot a reference line or calculate relative spawning biomass.

unit_label

units for recruitment

Default: "mt"

scale_amount

A number to scale the y-axis values.

Default: 1

era

A string naming the era of data.

Default: "time"

Options: "early", "time", "fore" (forecast), or NULL (all data)

group

A string of a single column that groups the data.

Set group = "none" to summarize data over all indexing values.

Default: NULL Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", NULL

facet

A string or vector of strings of a column name.

Default: NULL

interactive

A logical value indicating if the environment is interactive.

Default: 'FALSE'

module

(Optional) A string indicating the module_name found in 'dat'. If selecting >1 module, place them in a vector like c("module1", "module2").

Default: NULL

If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso [filter_data()]

make_rda

A logical value indicating whether to save the object and make an automated caption and alternative text in the form of an 'rda' object. If TRUE, the rda will be exported to the folder indicated in the argument "figures_dir".

Default: 'FALSE'.

figures_dir

A string indicating a path to the "figures" folder.

Default: 'getwd()'

The folder is created within the path if it does not exist.

...

Arguments called from geom_line or geom_point

Details

The input is from an assessment model output file translated to a standardized output (convert_output). There are options to return a 'ggplot2' object or export an .rda object containing associated caption and alternative text for the figure.

Value

A plot showing recruitment over time.

See Also

[convert_output()], [filter_data()], [process_data()], [plot_timeseries()], [export_kqs()], [insert_kqs()], [create_rda()]

Examples

plot_recruitment(
  dat = stockplotr:::example_data,
  unit_label = "metric tons",
  scale_amount = 100,
  interactive = TRUE,
  module = "TIME_SERIES",
  make_rda = FALSE
)
plot_recruitment(
  dat = stockplotr:::example_data,
  era = "fore",
  module = "TIME_SERIES",
  make_rda = FALSE
)

Plot recruitment deviations

Description

Plot recruitment deviations

Usage

plot_recruitment_deviations(
  dat,
  module = NULL,
  era = NULL,
  interactive = TRUE,
  make_rda = FALSE,
  figures_dir = getwd(),
  ...
)

Arguments

dat

A tibble or named list of tibbles (input as 'list()') returned from convert_output.

If inputting a list of tibbles, the first tibble's reference point defined in 'ref_line' is used to plot a reference line or calculate relative spawning biomass.

module

(Optional) A string indicating the module_name found in 'dat'. If selecting >1 module, place them in a vector like c("module1", "module2").

Default: NULL

If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso [filter_data()]

era

A string naming the era of data.

Default: "time"

Options: "early", "time", "fore" (forecast), or NULL (all data)

interactive

A logical value indicating if the environment is interactive.

Default: 'FALSE'

make_rda

A logical value indicating whether to save the object and make an automated caption and alternative text in the form of an 'rda' object. If TRUE, the rda will be exported to the folder indicated in the argument "figures_dir".

Default: 'FALSE'.

figures_dir

A string indicating a path to the "figures" folder.

Default: 'getwd()'

The folder is created within the path if it does not exist.

...

Arguments called from geom_line or geom_point

Details

The input is from an assessment model output file translated to a standardized output (convert_output). There are options to return a 'ggplot2' object or export an .rda object containing associated caption and alternative text for the figure.

Value

A plot showing recruitment deviations relative to one, over time.

Note

All plotting functions automatically recognize indexing variables and will use them in groupings and/or facetting.

See Also

[convert_output()], [plot_error()], [filter_data()], [process_data()], [export_kqs()], [insert_kqs()], [create_rda()]

Examples

plot_recruitment_deviations(
  dat = stockplotr:::example_data,
  interactive = FALSE,
  size = 1.5
)
plot_recruitment_deviations(
  dat = stockplotr:::example_data,
  era = "early",
  interactive = FALSE,
  shape = 2
)

Plot spawning biomass (SB)

Description

Plot spawning biomass with a reference line as a dashed line. The figure can also be made relative to this reference line rather than in absolute units.

Usage

plot_spawning_biomass(
  dat,
  geom = "line",
  group = NULL,
  facet = NULL,
  ref_line = "msy",
  unit_label = "mt",
  era = NULL,
  lbs = FALSE,
  module = NULL,
  scale_amount = 1,
  relative = FALSE,
  make_rda = FALSE,
  figures_dir = getwd(),
  interactive = TRUE,
  ...
)

Arguments

dat

A tibble or named list of tibbles (input as 'list()') returned from convert_output.

If inputting a list of tibbles, the first tibble's reference point defined in 'ref_line' is used to plot a reference line or calculate relative spawning biomass.

geom

A string stating the geom used for the plot.

Default: "line".

Options: "line", "point", or "area"

group

A string of a single column that groups the data.

Set group = "none" to summarize data over all indexing values.

Default: NULL Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", NULL

facet

A string or vector of strings of a column name.

Default: NULL

ref_line

A string specifying a reference point name.

Default: "target"

Options: (including, but not limited to) "target", "msy", and "unfished" If the reference point is not found in the data, set ref_line = c("name" = value).

unit_label

A string specifying spawning biomass unit.

Default: "mt"

era

A string naming the era of data.

Default: "time"

Options: "early", "time", "fore" (forecast), or NULL (all data)

lbs

A logical value indicating whether to convert the y-axis values from kilograms to pounds. The default units match the default in the unit_label argument - 'mt'.

Default: 'FALSE'

module

(Optional) A string indicating the module_name found in 'dat'. If selecting >1 module, place them in a vector like c("module1", "module2").

Default: NULL

If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso [filter_data()]

scale_amount

A number to scale the y-axis values.

Default: 1

relative

A logical value specifying to set y-axis values relative to the ref_line value.

Default: 'FALSE'

make_rda

A logical value indicating whether to save the object and make an automated caption and alternative text in the form of an 'rda' object. If TRUE, the rda will be exported to the folder indicated in the argument "figures_dir".

Default: 'FALSE'.

figures_dir

A string indicating a path to the "figures" folder.

Default: 'getwd()'

The folder is created within the path if it does not exist.

interactive

A logical value indicating if the environment is interactive.

Default: 'FALSE'

...

Arguments called from geom_line or geom_point

Details

The input is from an assessment model output file translated to a standardized output (convert_output). There are options to return a 'ggplot2' object or export an .rda object containing associated caption and alternative text for the figure.

Value

A plot showing spawning biomass over time.

Note

All plotting functions automatically recognize indexing variables and will use them in groupings and/or facetting. @seealso [process_data()].

See Also

[convert_output()], [plot_timeseries()], [calculate_reference_point()], [reference_line()], [filter_data()], [process_data()], [export_kqs()], [insert_kqs()], [create_rda()]

Examples

plot_spawning_biomass(
  dat = stockplotr:::example_data,
  geom = "line",
  ref_line = "msy",
  unit_label = "mt",
  scale_amount = 1000,
  interactive = FALSE,
  module = "TIME_SERIES",
  linewidth = 1.5
)
plot_spawning_biomass(
  dat = stockplotr:::example_data,
  ref_line = c("target" = 10),
  interactive = FALSE,
  module = "TIME_SERIES"
)

Plot Stock Recruit Relationship

Description

Plot Stock Recruit Relationship

Usage

plot_stock_recruitment(
  dat,
  spawning_biomass_label = "mt",
  recruitment_label = "mt",
  interactive = TRUE,
  era = NULL,
  module = NULL,
  scale_amount = 1,
  make_rda = FALSE,
  figures_dir = getwd()
)

Arguments

dat

A tibble or named list of tibbles (input as 'list()') returned from convert_output.

If inputting a list of tibbles, the first tibble's reference point defined in 'ref_line' is used to plot a reference line or calculate relative spawning biomass.

spawning_biomass_label

Units for spawning biomass

Default: "mt"

recruitment_label

units for recruitment

Default: "mt"

interactive

Indicate whether the environment the plot is being made in is interactive. By default, this is set to false. If true, dependent on your data, a option menu will pop-up.

Default: TRUE

era

A string naming the era of data.

Default: "time"

Options: "early", "time", "fore" (forecast), or NULL (all data)

module

(Optional) A string indicating the module_name found in 'dat'. If selecting >1 module, place them in a vector like c("module1", "module2").

Default: NULL

If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso [filter_data()]

scale_amount

A number to scale the y-axis values.

Default: 1

make_rda

A logical value indicating whether to save the object and make an automated caption and alternative text in the form of an 'rda' object. If TRUE, the rda will be exported to the folder indicated in the argument "figures_dir".

Default: 'FALSE'.

figures_dir

A string indicating a path to the "figures" folder.

Default: 'getwd()'

The folder is created within the path if it does not exist.

Details

The input is from an assessment model output file translated to a standardized output (convert_output). There are options to return a 'ggplot2' object or export an .rda object containing associated caption and alternative text for the figure.

Value

A plot showing the stock recruitment relationship.

See Also

[convert_output()], [filter_data()], [process_data()], [plot_timeseries()], [export_kqs()], [insert_kqs()], [create_rda()]

Examples

plot_stock_recruitment(
  dat = stockplotr:::example_data,
  interactive = FALSE,
  spawning_biomass_label = "metric tons",
  recruitment_label = "metric tons",
  module = "DERIVED_QUANTITIES"
)

Plot time series trends

Description

Plot time series trends

Usage

plot_timeseries(
  dat,
  x = "year",
  y = "estimate",
  geom = "line",
  xlab = "Year",
  ylab = NULL,
  group = NULL,
  facet = NULL,
  ...
)

Arguments

dat

filtered data frame from standard output file(s) preformatted for the target label from filter_data

x

a string of the column name of data used to plot on the x-axis

Default: "year"

y

a string of the column name of data used to plot on the y-axis

Default: "estimate"

geom

type of geom to use for plotting found in ggplot2 (e.g. "point", "line", etc.).

Default: "line"

Options: "point" and "area"

xlab

a string of the x-axis label

Default: "Year"

ylab

a string of the y-axis label. If NULL, it will be set to the name of 'y'.

Default: NULL

group

a string of a single column that groups the data. Currently can only have one level of grouping.

Default: NULL Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", NULL

facet

a string or vector of strings of a column that facets the data (e.g. "year", "area", etc.)

Default: NULL

...

inherited arguments from internal functions from ggplot2::geom_xx

Details

The user can create a line, point, or area plot, where the x-axis is year and y can vary for any time series quantity. Currently, grouping is restricted to one group where faceting can be any number of facets.

Value

Create a time series plot for a stock assessment report.

Examples

## Not run: 
plot_timeseries(dat,
  x = "year",
  y = "estimate",
  geom = "line",
  xlab = "Year",
  ylab = "Biomass",
  group = "fleet",
  facet = "area"
)

## End(Not run)

Processing for figures

Description

Processing for figures

Usage

process_data(dat, group = NULL, facet = NULL, lbs = FALSE, method = "sum")

Arguments

dat

Pre-filtered data from filter_data following a long format data.

group

A string identifying the indexing variable of the data. To remove any groups and summarize data across all factors, set group = "none". Setting group = NULL will keep any grouping variables identified in the data by the function.

Default: NULL

Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", NULL

facet

A string or vector of strings identifying the faceting variable(s) of the data.

Default: NULL

lbs

A logical value indicating whether to convert the y-axis values from kilograms to pounds. The default units match the default in the unit_label argument - 'metric tons'.

Default: 'FALSE'

method

A string describing the method of summarizing data when group is set to "none".

Default: "sum"

Options: "sum" or "mean"

Details

Automatically detects potential grouping and faceting data from a dataframe output from filter_data.

Value

List of 3 objects:

data

A data frame of the processed data ready for plotting.

group

A string identifying the grouping variable of the data. If NULL, no grouping variable is identified. If not NULL, the function will verify that the data is indexed by this variables, otherwise it will overwrite it to a different, valid indexed variable or NULL.

facet

A string or vector of strings identifying the faceting variable(s) of the data. If NULL, no faceting variable is identified. Any identified indexed variables found in this function will be added to facet.

Examples

{
  filtered <- stockplotr::filter_data(
    dat = stockplotr:::example_data,
    label_name = "fishing_mortality$",
    geom = "line",
    module = "TIME_SERIES"
  )
  process_data(dat = filtered, method = "sum")
}

Processing for tables

Description

Processing for tables

Usage

process_table(dat, group = NULL, method = "sum", label = NULL, digits = 2)

Arguments

dat

Pre-filtered data from filter_data following a long format data.

group

A string identifying the indexing variable of the data. To remove any groups and summarize data across all factors, set group = "none". Setting group = NULL will keep any grouping variables identified in the data by the function.

Default: NULL

Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", NULL

method

A string describing the method of summarizing data when group is set to "none".

Default: "sum"

Options: "sum" or "mean"

label

A string or vector of strings identifying the label values to filter the data.

Default: NULL

digits

Numeric value indicating the number of rounding digits.

Default: 2

Details

Input is an object created with filter_data.

Value

A dataframe of processed data ready for formatting into a table.

Examples

{
  filtered <- filter_data(
    dat = stockplotr:::example_data,
    label = "landings",
    geom = "line",
    era = "time"
  )
  process_table(dat = filtered, method = "sum")
}

Preformatted reference line

Description

Preformatted reference line

Usage

reference_line(plot, dat, label_name, reference, scale_amount = 1, lbs = FALSE)

Arguments

plot

a ggplot2 object where the reference line will be added

dat

standard data frame where reference point should be extracted

label_name

string of the name of the quantity that users want to extract the reference point from

reference

string of the reference point

Options: Including, but not limited to: "msy", "unfished", "target"

scale_amount

A number to scale the y-axis values.

Default: 1

lbs

A logical value indicating whether to convert the y-axis values from kilograms to pounds. The default units match the default in the unit_label argument - 'mt'.

Default: 'FALSE'

Value

A ggplot2 geom_hline object for a reference point that can be added to a plot

Examples

## Not run: 
reference_line(dat, "biomass", "msy")

## End(Not run)

Export all figures and tables

Description

Export all figures and tables to Rda files within one function.

Usage

save_all_plots(
  dat,
  recruitment_unit_label = "mt",
  recruitment_scale_amount = 1,
  relative = FALSE,
  proportional = TRUE,
  interactive = FALSE,
  figures_tables_dir = getwd(),
  ref_line = "msy",
  biomass_scale_amount = 1,
  landings_unit_label = "mt",
  spawning_biomass_label = "mt",
  spawning_biomass_scale_amount = 1,
  ref_line_sb = "msy",
  abundance_at_age_scale_amount = 1,
  abundance_at_age_unit_label = "fish",
  biomass_at_age_scale_amount = 1,
  biomass_at_age_unit_label = "mt",
  indices_unit_label = "",
  biomass_unit_label = "mt",
  catch_unit_label = "mt",
  catch_scale_amount = 1
)

Arguments

dat

A tibble or named list of tibbles (input as 'list()') returned from convert_output.

If inputting a list of tibbles, the first tibble's reference point defined in 'ref_line' is used to plot a reference line or calculate relative spawning biomass.

recruitment_unit_label

Units for recruitment

Default: "mt"

recruitment_scale_amount

A number describing how much to scale down the recruitment quantities shown on the y axis. For example, recruitment_scale_amount = 100 would scale down a value from 500,000 –> 5,000. This scale will be reflected in the y axis label.

Default: 1

relative

A logical value specifying to set y-axis values relative to the ref_line value.

Default: 'FALSE'

proportional

T/F to scale size of bubble plots

Default: 'TRUE'

interactive

A logical value indicating if the environment is interactive.

Default: 'FALSE'

figures_tables_dir

The location of the folder containing figures and tables ("figures" and "tables").

Default: the working directory ('getwd()')

ref_line

A string specifying the type of reference you want to compare biomass to. The default is '"msy"', which looks for '"biomass_msy"' in the '"label"' column of 'dat'. The actual searching in 'dat' is case agnostic and will work with either upper- or lower-case letters but you must use one of the options specified in the default list to ensure that the label on the figure looks correct regardless of how it is specified in 'dat'. Other possibilities may include "target", "MSY", and "unfished". When the reference cannot be found, indicate the reference line in the form c("label" = value).

Default: "msy"

Options: Including, but not limited to: "target", "MSY", "unfished"

biomass_scale_amount

A number describing how much to scale down the biomass quantities shown on the y axis. See 'recruitment_scale_amount'.

Default: 1

landings_unit_label

Units for landings

Default: "mt"

spawning_biomass_label

Units for spawning biomass

Default: "mt"

spawning_biomass_scale_amount

A number describing how much to scale down the spawning biomass quantities shown on the y axis. See 'recruitment_scale_amount'.

Default: 1

ref_line_sb

Identical definition as 'ref_line', but this argument is applied to plot_spawning_biomass.

Default: "msy"

Options: Including, but not limited to: "target", "MSY", "unfished"

abundance_at_age_scale_amount

A number describing how much to scale down the abundance quantities shown via bubble size. See 'recruitment_scale_amount'.

Default: 1

abundance_at_age_unit_label

Abbreviated units for abundance at age

Default: "fish"

biomass_at_age_scale_amount

A number describing how much to scale down the biomass quantities shown via bubble size. See 'recruitment_scale_amount'.

Default: 1

biomass_at_age_unit_label

Abbreviated units for biomass at age

Default: "mt"

indices_unit_label

Units for index of abundance/CPUE

Default: ""

biomass_unit_label

Abbreviated units for biomass

Default: "mt"

catch_unit_label

Abbreviated units for catch

Default: "mt"

catch_scale_amount

A number describing how much to scale down the catch quantities shown via bubble size. See 'recruitment_scale_amount'.

Default: 1

Details

The input is from an assessment model output file translated to a standardized output (convert_output).

Value

Rda files for each figure/table.

See Also

[convert_output()], [create_rda()]

Examples

## Not run: 
save_all_plots(dat,
  ref_line = "unfished",
  ref_line_sb = "target",
  indices_unit_label = "CPUE",
  biomass_at_age_scale_amount = 1,
  biomass_at_age_unit_label = "metric tons"
)

## End(Not run)

Landed catch by fleet and year table

Description

Landed catch by fleet and year table

Usage

table_landings(
  dat,
  unit_label = "mt",
  era = NULL,
  interactive = TRUE,
  group = NULL,
  method = "sum",
  module = NULL,
  label = NULL,
  digits = 2,
  scale_amount = 1,
  make_rda = FALSE,
  tables_dir = getwd()
)

Arguments

dat

A tibble or named list of tibbles (input as 'list()') returned from convert_output.

If inputting a list of tibbles, the first tibble's reference point defined in 'ref_line' is used to plot a reference line or calculate relative spawning biomass.

unit_label

Abbreviated units of landings

Default: "mt"

era

A string naming the era of data.

Default: "time"

Options: "early", "time", "fore" (forecast), or NULL (all data)

interactive

A logical value indicating if the environment is interactive.

Default: 'FALSE'

group

A string of a single column that groups the data.

Set group = "none" to summarize data over all indexing values.

Default: NULL Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", NULL

method

A string describing the method of summarizing data when group is set to "none".

Default: "sum"

Options: "sum" or "mean"

module

(Optional) A string indicating the module_name found in 'dat'. If selecting >1 module, place them in a vector like c("module1", "module2").

Default: NULL

If the interactive and >1 module_name is found, user will select the module_name in the console. @seealso [filter_data()]

label

The label that will be chosen from the input file. If unspecified, the function will search the "label" column and use the first matching label in this ordered list: "landings_weight", "landings_numbers", "landings_expected", "landings_predicted", "landings".

Default: NULL

digits

Numeric value indicating the number of digits values in the table will be rounded to.

Default: 2

scale_amount

A number to scale the y-axis values.

Default: 1

make_rda

A logical value indicating whether to save the object and make an automated caption and alternative text in the form of an 'rda' object. If TRUE, the rda will be exported to the folder indicated in the argument "figures_dir".

Default: 'FALSE'.

tables_dir

The location of the folder containing the generated table rda files ("tables") that will be created if the argument 'make_rda' = TRUE.

Default: the working directory ('getwd()')

Details

The input is from an assessment model output file translated to a standardized output (convert_output). There are options to return a [gt::gt()] object or export an rda object containing a gt-based table, caption, and LaTeX-based table.

Value

A table ready of landed catch by fleet and year.

See Also

[convert_output()], [filter_data()], [process_table()], [export_kqs()], [insert_kqs()], [create_rda()]

Examples

table_landings(stockplotr::example_data)

table_landings(
  stockplotr::example_data,
  unit_label = "landings label",
  group = "fleet"
)

Add NOAA theming to ggplot2 object. The palette is from the 'viridis' package, which contains palettes distinguishable by those with color vision deficiency.

Description

Add NOAA theming to ggplot2 object. The palette is from the 'viridis' package, which contains palettes distinguishable by those with color vision deficiency.

Usage

theme_noaa(discrete = TRUE, ...)

Arguments

discrete

Variable indicating whether the color or fill aesthetic is discrete.

Default: TRUE

...

Arguments passed to 'ggplot2::theme()'.

Value

A list applying a theme to a ggplot2 object.

Examples

ggplot2::ggplot(
  data = OrchardSprays,
  ggplot2::aes(
    x = rowpos,
    y = decrease,
    color = treatment
  )
) +
  ggplot2::geom_point() +
  theme_noaa()

ggplot2::ggplot(
  data = OrchardSprays,
  ggplot2::aes(
    x = rowpos,
    y = decrease,
    color = decrease
  )
) +
  ggplot2::geom_point() +
  theme_noaa(discrete = FALSE)
## Not run: 
ggplot2::theme_set(stockplotr::theme_noaa())

## End(Not run)