Package 'satf'

Title: Stock Assessment Tables and Figures
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, Bai Li, Steve Saul, Kelli F. Johnson, & Megumi Oshima
Maintainer: Samantha Schiano <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2024-11-26 16:30:27 UTC
Source: https://github.com/nmfs-ost/satf

Help Index


Add NOAA formatting to figure or table

Description

Add NOAA formatting to figure or table

Usage

add_theme(x)

Arguments

x

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

Value

Add the standard formatting for stock assessment reports for any figure or table. Currently, the function is able to format objects from: ggplot (ggplot2), base r plot, flextable (flextable), gt tables (gt), and kable tables (kableExtra).

Examples

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

Export figure and alternative text

Description

Function to export a specified plot object, and its alternative text, from the R environment.

Usage

exp_fig_accessible(figure, alt_text, path, width = 5, height = 5, units = "cm")

Arguments

figure

Plot object in the R environment to export.

alt_text

Alternative text for the figure.

path

Directory in which "exported" folder should be saved.

width

Plot width, in units (see argument below). Default is 5.

height

Plot height, in units (see argument below). Default is 5.

units

Plot size units (options: "in", "cm", "mm", "px"). Default is "cm".

Value

A folder containing exported plots and associated alternative text as .png and .csv objects, respectively.

Examples

## Not run: 
model_data <- read.csv(here::here("data/Petrale_sole_std_res_2023.csv"))

fig1 <- satf::plot_spawning_biomass(model_data)

exp_fig_accessible(figure = fig1,
                   alt_text = "my alt text",
                   path = here::here(),
                   width = 5,
                   height = 5,
                   units = "cm")


## End(Not run)

Plot Total Biomass

Description

Plot Total Biomass

Usage

plot_biomass(
  dat,
  unit_label = "metric tons",
  scale_amount = 1,
  ref_line = c("target", "MSY", "msy", "unfished"),
  end_year = NULL,
  relative = FALSE
)

Arguments

dat

A data frame returned from 'asar::convert_output()'.

unit_label

units for recruitment

scale_amount

indicate the exact amount of scale (i.e. 1000)

ref_line

A string specifying the type of reference you want to compare biomass to. The default is '"target"', which looks for '"biomass_target"' 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'.

end_year

last year of assessment

relative

A logical value specifying if the resulting figures should be relative spawning biomass. The default is 'FALSE'. 'ref_line' indicates which reference point to use.

Value

Plot total biomass from a stock assessment model as found in a NOAA stock assessment report. Units of total biomass can either be manually added or will be extracted from the provided file if possible. In later releases, model will not


Plot observed landings by fleet

Description

Plot observed landings by fleet

Usage

plot_landings(dat, unit_label = "metric tons")

Arguments

dat

A data frame returned from 'asar::convert_output()'.

unit_label

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

Value

Create a plot ready for a stock assessment report of cumulative landings over time by fleet.Includes options to plot by fleet, total observed landings with and without predicted landings. Indicate if fleet should be faceted or on one plot (default). Warning: i


Plot Recruitment

Description

Plot Recruitment

Usage

plot_recruitment(
  dat,
  unit_label = "metric tons",
  scale_amount = 1,
  end_year = NULL,
  n_projected_years = 10,
  relative = FALSE
)

Arguments

dat

A data frame returned from 'asar::convert_output()'.

unit_label

units for recruitment

scale_amount

indicate the exact amount of scale (i.e. 1000)

end_year

last year of assessment

n_projected_years

Number of years spawning biomass is projected for. By default this number is set to 10

relative

A logical value specifying if the resulting figures should be relative spawning biomass. The default is 'FALSE'. 'ref_line' indicates which reference point to use.

Value

Plot recruitment over time from an assessment model output file translated to a standardized output. There are options to return a ggplot2 object or export an rda object containing associated caption and alternative text for the figure.


Plot Recruitment Deviations

Description

@inheritParams plot_recruitment

Usage

plot_recruitment_deviations(
  dat = NULL,
  end_year = NULL,
  n_projected_years = 10
)

Value

Plot recruitment deviations relative to one over time from an assessment model output file translated to a standardized output. There are options to return a ggplot2 object or export an .rda object containing associated caption and alternative text for the figure.


Plot Spawn-Recruit Curve

Description

@inheritParams plot_recruitment @param spawning_biomass_label Units for spawning biomass @param recruitment_label units for recruitment

Usage

plot_spawn_recruitment(
  dat = NULL,
  spawning_biomass_label = "metric tons",
  recruitment_label = "metric tons",
  end_year = NULL
)

Value

Plot spawning recruitment relationship from a standardized output file originating from asar::convert_output()


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,
  unit_label = "metric ton",
  scale_amount = 1,
  ref_line = c("target", "unfished", "msy"),
  end_year = NULL,
  relative = FALSE,
  n_projected_years = 10
)

Arguments

dat

A data frame returned from 'asar::convert_output()'.

unit_label

units for recruitment

scale_amount

indicate the exact amount of scale (i.e. 1000)

ref_line

A string specifying the type of reference you want to compare spawning biomass to. The default is '"target"', which looks for '"spawning_biomass_target"' 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'.

end_year

last year of assessment

relative

A logical value specifying if the resulting figures should be relative spawning biomass. The default is 'FALSE'. 'ref_line' indicates which reference point to use.

n_projected_years

Number of years spawning biomass is projected for. By default this number is set to 10

Value

Plot spawning biomass from the results of an assessment model translated to the standard output. The ggplot2 object is returned for further modifications if needed.


Create Indices of Abundance Table

Description

Create Indices of Abundance Table

Usage

table_indices(dat)

Arguments

dat

A data frame returned from 'asar::convert_output()'.

Value

Create table of observed annual indices of abundance plus error stratified by fleet.


Write captions and alternative text

Description

Function to create captions and alternative text that contain key quantities from the model results file.

Usage

write_captions(dat, dir = NULL, year = NULL)

Arguments

dat

A data frame returned from 'asar::convert_output()'.

dir

Directory where the output captions and alt text file should be saved

year

the last year of the data or the current year this function is being performed

Value

Exports .csv with captions and alt text for figures and tables that contain key quantities (e.g., an assessment's start year) that are automatically extracted from the converted model results file.