| 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.13.0 |
| Built: | 2026-07-24 14:35:08 UTC |
| Source: | https://github.com/nmfs-ost/stockplotr |
Calculate key quantities
calc_kqs( returned_kq, prepared_data = NULL, dat = NULL, final = NULL, relative = NULL, ... )calc_kqs( returned_kq, prepared_data = NULL, dat = NULL, final = NULL, relative = NULL, ... )
returned_kq |
String. Key quantity to be returned. |
prepared_data |
Data frame. The prepared_data object. |
dat |
Data frame. The original data object. |
final |
ggplot2 object. The final figure. |
relative |
Logical. TRUE/FALSE; specify whether to set y-axis values relative to the ref_line value. |
... |
Additional arguments to be passed to the function. |
The value of the specified key quantity.
## Not run: calc_kqs( returned_kq = "F.min", dat = dat ) ## End(Not run)## Not run: calc_kqs( returned_kq = "F.min", dat = dat ) ## End(Not run)
Create loop to test for differences in column values
check_label_differences(dat, index_variables, id_group = NULL)check_label_differences(dat, index_variables, id_group = NULL)
dat |
Data frame. Input data into process_table |
index_variables |
Character vector. The index_variables vector created within process_table |
id_group |
String. The identifying index variable as a string Default: NULL |
Format stock assessment output files to a standardized format.
convert_output(file, model = NULL, fleet_names = NULL, save_dir = NULL)convert_output(file, model = NULL, fleet_names = NULL, save_dir = NULL)
file |
Path. Assessment model output file path |
model |
String. Assessment model used in evaluation Default: NULL Options: "ss3", "bam", "fims", "rceattle" |
fleet_names |
Character vector. 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 |
Path. File path to save the converted output file. Default: NULL |
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.
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.
Samantha Schiano
## 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)## 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
create_latex_table(data, caption, label)create_latex_table(data, caption, label)
data |
Data frame. A dataframe-based table |
caption |
String. Table caption |
label |
String. Table label |
A table based in LaTeX.
create_latex_table( data = as.data.frame(head(mtcars, 6)), caption = "My caption", label = "My label" )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
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 )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 )
object |
Object. Table or plot object |
topic_label |
String. Name of the object |
fig_or_table |
String. Indicates whether the object is a "table" or "figure" |
dat |
Data frame. Data which will fill in captions and alternative text for the object |
dir |
Path. Directory to where the rda will be saved Default: the working directory ('getwd()') |
year |
Number. Assessment year Default: the current year |
ref_line |
String. Reference line value Default: "msy" Options: Including, but not limited to: "msy", "target", "unfished" |
scale_amount |
Number. 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 |
String. Unit label for the y-axis Default: "mt" |
table_df |
Data frame. The data frame that the table will be made into for purposes of exporting a latex formatted table. |
An rda package for a plot or table object. Requires an object from the R environment such as a ggplot or flextable object.
[export_rda()], [extract_caps_alttext()]
## 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)## 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)
Included data set that represents a Report.sso file converted using convert_output(). This example is from the 2022 Petrale sole stock assessment.
example_dataexample_data
A tibble with 591109 rows and 33 variables:
Standard name for estimate or value name
Actual value of the label
Annual indexing value
Names of fleets or surveys indexed by the data
Native reference to male, female, unknown, or none
Specified areas by the model
Indexing column of data
Value of uncertainty associated with the label column
Uncertainty label or name associated with the label columns
Name of keyword (SS3) or list indexing in the original model output for tracking purposes
Time sometimes referenced in decimals to the year and month
"time" for current time series in model; "fore" representing the projected or forecasted years of the model
Month factor
Season usually associated with year
Subseason when used
Birthseason found in SS3
Initial input value in the model when available associated with the label column
Likelihood value for the data point
Platoon also an SS3 indexing value
Age of fish
Indexing column of data
Indexing column of data
Indexing column of data
Indexing column of data
Indexing column of data
Indexing column of data
Indexing column of data
Indexing column of data
Indexing column of data
Alternative age column
Length bins for composition or other length based data
Indexing column of data
Indexing column of data
Export updated key quantities template
export_kqs(...)export_kqs(...)
... |
Key quantities whose values should be added to the exported "key_quantities.csv" |
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.
[fill_in_kqs()], [insert_kqs()]
## Not run: export_kqs( F.min, F.max ) ## End(Not run)## Not run: export_kqs( F.min, F.max ) ## End(Not run)
Export a figure/table, and its caption and alternative text, to an rda object. Typically used after stockplotr::extract_caps_alttext().
export_rda( object = NULL, caps_alttext = NULL, figures_tables_dir = NULL, topic_label = NULL, fig_or_table = NULL, latex_table = NULL )export_rda( object = NULL, caps_alttext = NULL, figures_tables_dir = NULL, topic_label = NULL, fig_or_table = NULL, latex_table = NULL )
object |
Object. The final figure (ggplot) or table (flextable) object. Default: NULL |
caps_alttext |
Data frame or list. 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 |
Path. 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 |
String. Figure or table 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 |
String. Indicates whether the plot is a figure or table. Default: NULL Options: "figure", "table" |
latex_table |
Table object. The object containing a LaTeX-based table. Default: NULL |
An rda file with a figure's ggplot, caption, and alternative text, or a table's gt-based table, caption, and LaTeX-based table.
[create_rda()], [extract_caps_alttext()]
## 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)## 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 a figure or table's caption and alternative text for usage when generating a figure or table. Typically used before stockplotr::export_rda().
extract_caps_alttext(topic_label = NULL, fig_or_table = NULL, dir = getwd())extract_caps_alttext(topic_label = NULL, fig_or_table = NULL, dir = getwd())
topic_label |
String. Figure or table 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 |
String. Indicates whether the plot is a figure or table. Default: NULL |
dir |
Path. The directory containing the "captions_alt_text.csv" file. Default: the working directory ('getwd()') |
A figure's caption and alternative text, in a list, or a table's caption.
[export_rda()], [create_rda()]
## 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)## 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
fill_in_kqs(df, ...)fill_in_kqs(df, ...)
df |
Data frame. 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 |
The returned dataframe is input for [fill_in_kqs()].
Dataframe based on key quantities template that contains newly-added values of key quantities indicated via ellipsis.
[export_kqs()], [insert_kqs()]
## Not run: fill_in_kqs( df = data, F.min, F.max ) ## End(Not run)## Not run: fill_in_kqs( df = data, F.min, F.max ) ## End(Not run)
Filter data for input into aesthetics for ggplot2
filter_data( dat, label_name, module = NULL, era = NULL, geom, group = NULL, facet = NULL, scale_amount = 1, interactive = TRUE )filter_data( dat, label_name, module = NULL, era = NULL, geom, group = NULL, facet = NULL, scale_amount = 1, interactive = TRUE )
dat |
Data frame or list. 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 |
String. Name of the label used to filter the data. |
module |
Character vector. (Optional) 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 |
String. Era of data. Default: "time" Options: "early", "time", "fore" (forecast), or NULL (all data) |
geom |
String. Geom used for the plot. Default: "line". Options: "line", "point", or "area" |
group |
String. 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 |
Character vector. Column name or names used for faceting. Default: NULL |
scale_amount |
Number. A number to scale the y-axis values. Default: 1 |
interactive |
Logical. TRUE/FALSE; indicate whether the environment is interactive. Default: 'FALSE' |
a data frame that is preformatted for plotting with ggplot2.
## Not run: filter_data(dat, "biomass", "line", group = "fleet") ## End(Not run)## Not run: filter_data(dat, "biomass", "line", group = "fleet") ## End(Not run)
Show all tables and figures in a single html file.
html_all_figs_tables(figures_tables_dir = getwd())html_all_figs_tables(figures_tables_dir = getwd())
figures_tables_dir |
Path. The location of the folder containing figures and tables ("figures" and "tables"). Default: The current working directory ('getwd()') |
A folder ("all_tables_figures") in your working directory containing html and qmd files that show all tables and figures.
asar::create_figures_doc(),
asar::create_tables_doc()
## Not run: html_all_figs_tables() html_all_figs_tables(figures_tables_dir = "my_figures_tables_dir") ## End(Not run)## 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
insert_kqs(...)insert_kqs(...)
... |
Key quantities whose values should be added to the exported "captions_alt_text.csv" |
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.
[fill_in_kqs()], [export_kqs()]
## Not run: insert_kqs( F.min, F.max ) ## End(Not run)## Not run: insert_kqs( F.min, F.max ) ## End(Not run)
Rename columns and merge estimate and uncertainty columns for table presentation
merge_error(table_data, id_col_vals, unit_label, uncert_lab)merge_error(table_data, id_col_vals, unit_label, uncert_lab)
table_data |
List of dataframes that will be eventually turned into tables |
id_col_vals |
List. A list of variables identifying grouping of the data and their unique values. |
unit_label |
String. The units of the estimate being presented in the table. |
uncert_lab |
String. Uncertainty label. Typically inherited from another function but is the exact string of the uncertainty in the data (e.g., "sd", "se", "cv", "uncertainty").) |
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
plot_aa( dat, x = "year", y = "age", z = "estimate", label = "Abundance", xlab = "Year", ylab = "Age", facet = NULL, proportional = TRUE, ... )plot_aa( dat, x = "year", y = "age", z = "estimate", label = "Abundance", xlab = "Year", ylab = "Age", facet = NULL, proportional = TRUE, ... )
dat |
Data frame. Filtered data frame from standard output file(s) preformatted for the target label from filter_data |
x |
String. Column name of data used to plot on the x-axis Default: "year" |
y |
String. Column name of data used to plot on the y-axis Default: "age" |
z |
String. Column name of data used to control the size of the bubbles Default: "estimate" |
label |
String. Label for the size of the bubbles Default: "Abundance" |
xlab |
String. X-axis label Default: "Year" |
ylab |
String. Y-axis label Default: "Age" |
facet |
Character vector. Column name or names used for faceting. 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 |
Logical. TRUE/FALSE; 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 |
Create a plot of abundance at age for a stock assessment report.
## Not run: plot_aa(dat) ## End(Not run)## Not run: plot_aa(dat) ## End(Not run)
Plot Abundance at Age
plot_abundance_at_age( dat, facet = NULL, unit_label = "fish", scale_amount = 1000, proportional = TRUE, module = NULL, interactive = TRUE, make_rda = FALSE, figures_dir = getwd() )plot_abundance_at_age( dat, facet = NULL, unit_label = "fish", scale_amount = 1000, proportional = TRUE, module = NULL, interactive = TRUE, make_rda = FALSE, figures_dir = getwd() )
dat |
Data frame. A data frame returned from convert_output |
facet |
Character vector. Column name or names used for faceting. 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 |
String. Abundance units Default: "fish" |
scale_amount |
Number. 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 |
Logical. TRUE/FALSE; 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' |
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 |
Logical. 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 |
Path. Folder containing the generated .rda files ("rda_files") that will be created if the argument 'make_rda' = TRUE. Default: the working directory ('getwd()') |
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.
A plot showing total abundance (or numbers) at age.
[convert_output()], [filter_data()], [process_data()], [plot_aa()], [export_kqs()], [insert_kqs()], [create_rda()]
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_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
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, ... )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, ... )
dat |
Data frame or list. 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 |
String. Geom used for the plot. Default: "line". Options: "line", "point", or "area" |
group |
String. 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 |
Character vector. Column name or names used for faceting. Default: NULL |
ref_line |
String. Type of reference point 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 |
String. Era of data. Default: "time" Options: "early", "time", "fore" (forecast), or NULL (all data) |
unit_label |
String. Biomass units Default: "mt" |
module |
Character vector. (Optional) 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 |
Number. A number to scale the y-axis values. Default: 1 |
relative |
Logical. TRUE/FALSE; specify whether to set y-axis values relative to the ref_line value. Default: 'FALSE' |
make_rda |
Logical. TRUE/FALSE; indicate 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 |
Path. Path to the "figures" folder. Default: 'getwd()' The folder is created within the path if it does not exist. |
interactive |
Logical. TRUE/FALSE; indicate whether the environment is interactive. Default: 'FALSE' |
... |
Arguments called from geom_line or geom_point |
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.
A plot showing total biomass.
[convert_output()], [plot_timeseries()], [calculate_reference_point()], [reference_line()], [filter_data()], [process_data()], [export_kqs()], [insert_kqs()], [create_rda()]
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_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)
plot_biomass_at_age( dat, facet = NULL, unit_label = "mt", scale_amount = 1000, proportional = TRUE, module = NULL, interactive = TRUE, make_rda = FALSE, figures_dir = getwd() )plot_biomass_at_age( dat, facet = NULL, unit_label = "mt", scale_amount = 1000, proportional = TRUE, module = NULL, interactive = TRUE, make_rda = FALSE, figures_dir = getwd() )
dat |
Data frame. A data frame returned from convert_output |
facet |
Character vector. Column name or names used for faceting. 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 |
String. Abundance units Default: "fish" |
scale_amount |
Number. 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 |
Logical. TRUE/FALSE; 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' |
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 |
Logical. 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 |
Logical. 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 |
Path. Folder containing the generated .rda files ("rda_files") that will be created if the argument 'make_rda' = TRUE. Default: the working directory ('getwd()') |
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.
A plot showing total biomass at age.
[convert_output()], [filter_data()], [process_data()], [plot_aa()], [export_kqs()], [insert_kqs()], [create_rda()]
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_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
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() )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() )
dat |
Data frame. A data frame returned from convert_output |
facet |
Character vector. Column name or names used for faceting. 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 |
String. Era of data. Default: "time" Options: "early", "time", "fore" (forecast), or NULL (all data) |
unit_label |
String. Units of catch used to label the axis Default: "mt" |
scale_amount |
Number. 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 |
Logical. TRUE/FALSE; 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 |
Logical. TRUE/FALSE; indicate whether the environment is interactive. Default: 'FALSE' |
module |
Character vector. (Optional) 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 |
Logical. 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 |
Path. Folder containing the generated .rda files ("rda_files") that will be created if the argument 'make_rda' = TRUE. Default: the working directory ('getwd()') |
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.
A plot showing catch or landings composition.
[convert_output()], [filter_data()], [process_data()], [plot_aa()], [export_kqs()], [insert_kqs()], [create_rda()]
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 )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
plot_error( dat, x = "year", y = "estimate", geom = "point", group = NULL, facet = NULL, xlab = "Year", ylab = NULL, hline = TRUE, ... )plot_error( dat, x = "year", y = "estimate", geom = "point", group = NULL, facet = NULL, xlab = "Year", ylab = NULL, hline = TRUE, ... )
dat |
Data frame. Filtered data frame from standard output file(s) preformatted for the target label from filter_data |
x |
String. Column name of data used to plot on the x-axis Default: "year" |
y |
String. Column name of data used to plot on the y-axis Default: "estimate" |
geom |
String. Type of geom to use for plotting found in ggplot2 (e.g. "point", "line", etc.). Default: "line" Options: "point" and "area" |
group |
String. 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 |
Character vector. Column name or names used for faceting (e.g. "year", "area", etc.) Default: NULL |
xlab |
String. X-axis label Default: "Year" |
ylab |
String. Y-axis label. If NULL, it will be set to the name of 'y'. Default: NULL |
hline |
Logical. TRUE/FALSE; indicate whether to place a horizontal line at 1 Default: 'TRUE' |
... |
Inherited arguments from internal functions from ggplot2::geom_xx |
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.
Create a plot with error for a stock assessment report.
Plot fishing mortality timeseries
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, ... )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, ... )
dat |
Data frame or list. 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 |
String. Geom used for the plot. Default: "line". Options: "line", "point", or "area" |
group |
String. 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 |
Character vector. Column name or names used for faceting. Default: NULL |
ref_line |
String. 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 |
String. Era of data. Default: "time" Options: "early", "time", "fore" (forecast), or NULL (all data) |
module |
Character vector. (Optional) 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 |
Logical. TRUE/FALSE; indicate 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 |
Path. Path to the "figures" folder. Default: 'getwd()' The folder is created within the path if it does not exist. |
interactive |
Logical. TRUE/FALSE; indicate whether the environment is interactive. Default: 'FALSE' |
... |
Arguments called from geom_line or geom_point |
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.
A plot showing fishing mortality over time.
[convert_output()], [filter_data()], [process_data()], [plot_timeseries()], [reference_line()], [export_kqs()], [insert_kqs()], [create_rda()]
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_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
plot_index( dat, unit_label = "", group = NULL, facet = NULL, interactive = TRUE, module = NULL, focus = NULL, make_rda = FALSE, figures_dir = getwd(), ... )plot_index( dat, unit_label = "", group = NULL, facet = NULL, interactive = TRUE, module = NULL, focus = NULL, make_rda = FALSE, figures_dir = getwd(), ... )
dat |
Data frame or list. 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 |
String. Index of abundance/CPUE units Default: "" |
group |
String. 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 |
Character vector. Column name or names used for faceting. "fleet" is always added on to any faceting selections Default: NULL Options: May include, but is not limited to: "fleet", "year", "area", NULL |
interactive |
Logical. TRUE/FALSE; indicate whether the environment is interactive. Default: 'FALSE' |
module |
Character vector. (Optional) 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 |
Character vector. Column name or names used to filter data. (i.e. select names of fleets to zoom into the plot) Default: NULL |
make_rda |
Logical. TRUE/FALSE; indicate 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 |
Path. 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 |
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.
A plot showing the expected and predicted index.
[convert_output()], [filter_data()], [process_data()], [plot_obsvpred()], [export_kqs()], [insert_kqs()], [create_rda()]
plot_index( dat = stockplotr::example_data, unit_label = "fish/hr", interactive = FALSE )plot_index( dat = stockplotr::example_data, unit_label = "fish/hr", interactive = FALSE )
Plot observed landings
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(), ... )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(), ... )
dat |
Data frame or list. 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 |
String. Spawning biomass unit. Default: "mt" |
geom |
String. Geom used for the plot. Default: "line". Options: "line", "point", or "area" |
group |
String. 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 |
Character vector. Column name or names used for faceting. Default: NULL |
lbs |
Logical. TRUE/FALSE; indicate 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 |
String. Era of data. Default: "time" Options: "early", "time", "fore" (forecast), or NULL (all data) |
scale_amount |
Number. A number to scale the y-axis values. Default: 1 |
module |
Character vector. (Optional) 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 |
Logical. TRUE/FALSE; indicate whether the environment is interactive. Default: 'FALSE' |
make_rda |
Logical. TRUE/FALSE; indicate 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 |
Path. 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 |
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.
A plot showing cumulative landings over time.
[convert_output()], [filter_data()], [process_data()], [plot_timeseries()], [export_kqs()], [insert_kqs()], [create_rda()]
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_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
plot_natural_mortality( dat, group = NULL, facet = NULL, era = NULL, interactive = TRUE, module = NULL, make_rda = FALSE, figures_dir = getwd(), ... )plot_natural_mortality( dat, group = NULL, facet = NULL, era = NULL, interactive = TRUE, module = NULL, make_rda = FALSE, figures_dir = getwd(), ... )
dat |
Data frame or list. 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 |
String. 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 |
Character vector. Column name or names used for faceting. Default: NULL |
era |
String. Era of data. Default: "time" Options: "early", "time", "fore" (forecast), or NULL (all data) |
interactive |
Logical. TRUE/FALSE; indicate whether the environment is interactive. Default: 'FALSE' |
module |
Character vector. (Optional) 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 |
Logical. TRUE/FALSE; indicate 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 |
Path. 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 |
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.
A plot showing natural mortality at age.
[convert_output()], [filter_data()], [process_data()], [plot_timeseries()], [export_kqs()], [insert_kqs()], [create_rda()]
plot_natural_mortality( dat = stockplotr:::example_data, module = "Natural_Mortality", interactive = FALSE )plot_natural_mortality( dat = stockplotr:::example_data, module = "Natural_Mortality", interactive = FALSE )
Plot observed vs. predicted data
plot_obsvpred( dat, x = "year", y = "estimate", observed_label = "observed", predicted_label = "predicted", geom = "line", xlab = "Year", ylab = NULL, group = NULL, facet = NULL, ... )plot_obsvpred( dat, x = "year", y = "estimate", observed_label = "observed", predicted_label = "predicted", geom = "line", xlab = "Year", ylab = NULL, group = NULL, facet = NULL, ... )
dat |
Data frame. Filtered data frame from standard output file(s) preformatted for the target label from filter_data |
x |
String. Column name of data used to plot on the x-axis Default: "year" |
y |
String. Column name of data used to plot on the y-axis Default: "estimate" |
observed_label |
String. Label used to filter the observed data Default: "observed" |
predicted_label |
String. Label used to filter the predicted data Default: "predicted" |
geom |
String. Type of geom to use for plotting found in ggplot2 (e.g. "point", "line", etc.). Default: "line" Options: "point" and "area" |
xlab |
String. X-axis label Default: "Year" |
ylab |
String. Y-axis label. If NULL, it will be set to the name of 'y'. Default: NULL |
group |
String. 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 |
Character vector. Column name or names used for faceting (e.g. "year", "area", etc.) Default: NULL |
... |
Inherited arguments from internal functions from ggplot2::geom_xx |
A plot of observed vs. predicted data for a stock assessment report.
Plot Recruitment
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(), ... )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(), ... )
dat |
Data frame or list. 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 |
String. Units for recruitment Default: "mt" |
scale_amount |
Number. A number to scale the y-axis values. Default: 1 |
era |
String. Era of data. Default: "time" Options: "early", "time", "fore" (forecast), or NULL (all data) |
group |
String. 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 |
Character vector. Column name or names used for faceting. Default: NULL |
interactive |
Logical. TRUE/FALSE; indicate whether the environment is interactive. Default: 'FALSE' |
module |
Character vector. (Optional) 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 |
Logical. TRUE/FALSE; indicate 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 |
Path. 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 |
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.
A plot showing recruitment over time.
[convert_output()], [filter_data()], [process_data()], [plot_timeseries()], [export_kqs()], [insert_kqs()], [create_rda()]
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( 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
plot_recruitment_deviations( dat, module = NULL, era = NULL, interactive = TRUE, make_rda = FALSE, figures_dir = getwd(), ... )plot_recruitment_deviations( dat, module = NULL, era = NULL, interactive = TRUE, make_rda = FALSE, figures_dir = getwd(), ... )
dat |
Data frame or list. 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 |
Character vector. (Optional) 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 |
String. Era of data. Default: "time" Options: "early", "time", "fore" (forecast), or NULL (all data) |
interactive |
Logical. TRUE/FALSE; indicate whether the environment is interactive. Default: 'FALSE' |
make_rda |
Logical. TRUE/FALSE; indicate 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 |
Path. 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 |
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.
A plot showing recruitment deviations relative to one, over time.
All plotting functions automatically recognize indexing variables and will use them in groupings and/or facetting.
[convert_output()], [plot_error()], [filter_data()], [process_data()], [export_kqs()], [insert_kqs()], [create_rda()]
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_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 with a reference line as a dashed line. The figure can also be made relative to this reference line rather than in absolute units.
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, ... )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, ... )
dat |
Data frame or list. 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 |
String. Geom used for the plot. Default: "line". Options: "line", "point", or "area" |
group |
String. 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 |
Character vector. Column name or names used for faceting. Default: NULL |
ref_line |
String. 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 |
String. Spawning biomass unit. Default: "mt" |
era |
String. Era of data. Default: "time" Options: "early", "time", "fore" (forecast), or NULL (all data) |
lbs |
Logical. TRUE/FALSE; indicate 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 |
Character vector. (Optional) 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 |
Number. A number to scale the y-axis values. Default: 1 |
relative |
Logical. TRUE/FALSE; specify whether to set y-axis values relative to the ref_line value. Default: 'FALSE' |
make_rda |
Logical. TRUE/FALSE; indicate 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 |
Path. Path to the "figures" folder. Default: 'getwd()' The folder is created within the path if it does not exist. |
interactive |
Logical. TRUE/FALSE; indicate whether the environment is interactive. Default: 'FALSE' |
... |
Arguments called from geom_line or geom_point |
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.
A plot showing spawning biomass over time.
All plotting functions automatically recognize indexing variables and will use them in groupings and/or facetting. @seealso [process_data()].
[convert_output()], [plot_timeseries()], [calculate_reference_point()], [reference_line()], [filter_data()], [process_data()], [export_kqs()], [insert_kqs()], [create_rda()]
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_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
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() )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() )
dat |
Data frame or list. 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 |
String. Units for spawning biomass Default: "mt" |
recruitment_label |
String. Units for recruitment Default: "mt" |
interactive |
Logical. TRUE/FALSE; 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 |
String. Era of data. Default: "time" Options: "early", "time", "fore" (forecast), or NULL (all data) |
module |
Character vector. (Optional) 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 |
Number. A number to scale the y-axis values. Default: 1 |
make_rda |
Logical. TRUE/FALSE; indicate 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 |
Path. Path to the "figures" folder. Default: 'getwd()' The folder is created within the path if it does not exist. |
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.
A plot showing the stock recruitment relationship.
[convert_output()], [filter_data()], [process_data()], [plot_timeseries()], [export_kqs()], [insert_kqs()], [create_rda()]
plot_stock_recruitment( dat = stockplotr:::example_data, interactive = FALSE, spawning_biomass_label = "metric tons", recruitment_label = "metric tons", module = "DERIVED_QUANTITIES" )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
plot_timeseries( dat, x = "year", y = "estimate", geom = "line", xlab = "Year", ylab = NULL, group = NULL, facet = NULL, ... )plot_timeseries( dat, x = "year", y = "estimate", geom = "line", xlab = "Year", ylab = NULL, group = NULL, facet = NULL, ... )
dat |
Data frame. Filtered data frame from standard output file(s) preformatted for the target label from filter_data |
x |
String. Column name of data used to plot on the x-axis Default: "year" |
y |
String. Column name of data used to plot on the y-axis Default: "estimate" |
geom |
String. Type of geom to use for plotting found in ggplot2 (e.g. "point", "line", etc.). Default: "line" Options: "point" and "area" |
xlab |
String. X-axis label Default: "Year" |
ylab |
String. Y-axis label. If NULL, it will be set to the name of 'y'. Default: NULL |
group |
String. 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 |
Character vector. Column name or names used for faceting (e.g. "year", "area", etc.) Default: NULL |
... |
Inherited arguments from internal functions from ggplot2::geom_xx |
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.
Create a time series plot for a stock assessment report.
## Not run: plot_timeseries(dat, x = "year", y = "estimate", geom = "line", xlab = "Year", ylab = "Biomass", group = "fleet", facet = "area" ) ## End(Not run)## 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
process_data(dat, group = NULL, facet = NULL, lbs = FALSE, method = "sum")process_data(dat, group = NULL, facet = NULL, lbs = FALSE, method = "sum")
dat |
Data frame. Pre-filtered data from filter_data following a long format data. |
group |
String. 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 |
Character vector. Faceting variable(s) of the data. Default: NULL |
lbs |
Logical. TRUE/FALSE; indicate 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 |
String. Method for summarizing data when group is set to "none". Default: "sum" Options: "sum" or "mean" |
Automatically detects potential grouping and faceting data from a dataframe output from filter_data.
List of 3 objects:
data |
A data frame of the processed data ready for plotting. |
group |
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 |
Faceting variable(s) identifying the 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. |
{ filtered <- stockplotr::filter_data( dat = stockplotr:::example_data, label_name = "fishing_mortality$", geom = "line", module = "TIME_SERIES" ) process_data(dat = filtered, method = "sum") }{ 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
process_table(dat, group = NULL, method = "sum", label = NULL, digits = 2)process_table(dat, group = NULL, method = "sum", label = NULL, digits = 2)
dat |
Data frame. Pre-filtered data from filter_data following a long format data. |
group |
String. 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 |
String. Method for summarizing data when group is set to "none". Default: "sum" Options: "sum" or "mean" |
label |
String. Label value or values used to filter the data. Default: NULL |
digits |
Number. Numeric value indicating the number of rounding digits. Default: 2 |
Input is an object created with filter_data.
A dataframe of processed data ready for formatting into a table.
{ filtered <- filter_data( dat = stockplotr:::example_data, label = "landings", geom = "line", era = "time" ) process_table(dat = filtered, method = "sum") }{ filtered <- filter_data( dat = stockplotr:::example_data, label = "landings", geom = "line", era = "time" ) process_table(dat = filtered, method = "sum") }
Preformatted reference line
reference_line(plot, dat, label_name, reference, scale_amount = 1, lbs = FALSE)reference_line(plot, dat, label_name, reference, scale_amount = 1, lbs = FALSE)
plot |
Plot object. A ggplot2 object where the reference line will be added |
dat |
Data frame. Standard data frame where reference point should be extracted |
label_name |
String. 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 |
Number. A number to scale the y-axis values. Default: 1 |
lbs |
Logical. TRUE/FALSE; indicate 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' |
A ggplot2 geom_hline object for a reference point that can be added to a plot
## Not run: reference_line(dat, "biomass", "msy") ## End(Not run)## Not run: reference_line(dat, "biomass", "msy") ## End(Not run)
Export all figures and tables to Rda files within one function.
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", index_unit_label = "", biomass_unit_label = "mt", catch_unit_label = "mt", catch_scale_amount = 1 )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", index_unit_label = "", biomass_unit_label = "mt", catch_unit_label = "mt", catch_scale_amount = 1 )
dat |
Data frame or list. 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 |
String. Recruitment units Default: "mt" |
recruitment_scale_amount |
Number. 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 |
Logical. TRUE/FALSE; specify whether to set y-axis values relative to the ref_line value. Default: 'FALSE' |
proportional |
Logical. TRUE/FALSE; scale size of bubble plots Default: 'TRUE' |
interactive |
Logical. TRUE/FALSE; indicate whether the environment is interactive. Default: 'FALSE' |
figures_tables_dir |
Path. The location of the folder containing figures and tables ("figures" and "tables"). Default: the working directory ('getwd()') |
ref_line |
String. Type of reference point 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 |
Number. 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 |
String. Landings units Default: "mt" |
spawning_biomass_label |
String. Spawning biomass units Default: "mt" |
spawning_biomass_scale_amount |
Number. 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 |
String. Same 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 |
Number. 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 |
String. Abbreviated abundance at age units Default: "fish" |
biomass_at_age_scale_amount |
Number. 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 |
String. Abbreviated biomass at age units Default: "mt" |
index_unit_label |
String. Index of abundance/CPUE units Default: "" |
biomass_unit_label |
String. Abbreviated biomass units Default: "mt" |
catch_unit_label |
String. Abbreviated catch units Default: "mt" |
catch_scale_amount |
Number. A number describing how much to scale down the catch quantities shown via bubble size. See 'recruitment_scale_amount'. Default: 1 |
The input is from an assessment model output file translated to a standardized output (convert_output).
Rda files for each figure/table.
[convert_output()], [create_rda()]
## Not run: save_all_plots(dat, ref_line = "unfished", ref_line_sb = "target", index_unit_label = "CPUE", biomass_at_age_scale_amount = 1, biomass_at_age_unit_label = "metric tons" ) ## End(Not run)## Not run: save_all_plots(dat, ref_line = "unfished", ref_line_sb = "target", index_unit_label = "CPUE", biomass_at_age_scale_amount = 1, biomass_at_age_unit_label = "metric tons" ) ## End(Not run)
Index of abundance table
table_index( dat, era = NULL, interactive = TRUE, group = NULL, method = "sum", module = NULL, label = NULL, digits = 2, make_rda = FALSE, tables_dir = getwd() )table_index( dat, era = NULL, interactive = TRUE, group = NULL, method = "sum", module = NULL, label = NULL, digits = 2, make_rda = FALSE, tables_dir = getwd() )
dat |
Data frame or list. 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. |
era |
String. Era of data. Default: "time" Options: "early", "time", "fore" (forecast), or NULL (all data) |
interactive |
Logical. TRUE/FALSE; indicate whether the environment is interactive. Default: 'FALSE' |
group |
String. 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 |
String. Method for summarizing data when group is set to "none". Default: "sum" Options: "sum" or "mean" |
module |
Character vector. (Optional) 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 |
String. 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: "index_weight", "index_numbers", "index_expected", "index_predicted", "index". Default: NULL |
digits |
Number. Numeric value indicating the number of digits values in the table will be rounded to. Default: 2 |
make_rda |
Logical. TRUE/FALSE; indicate 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 |
Path. 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()') |
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.
A table of observed annual index of abundance plus error, stratified by fleet.
[convert_output()], [filter_data()], [process_table()], [export_kqs()], [insert_kqs()], [create_rda()]
## Not run: table_index(dat) table_index( dat, make_rda = TRUE, tables_dir = getwd() ) ## End(Not run)## Not run: table_index(dat) table_index( dat, make_rda = TRUE, tables_dir = getwd() ) ## End(Not run)
Landed catch by fleet and year table
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() )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() )
dat |
Data frame or list. 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 |
String. Abbreviated landings units Default: "mt" |
era |
String. Era of data. Default: "time" Options: "early", "time", "fore" (forecast), or NULL (all data) |
interactive |
Logical. TRUE/FALSE; indicate whether the environment is interactive. Default: 'FALSE' |
group |
String. 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 |
String. Method for summarizing data when group is set to "none". Default: "sum" Options: "sum" or "mean" |
module |
Character vector. (Optional) 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 |
String. 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 |
Number. Numeric value indicating the number of digits values in the table will be rounded to. Default: 2 |
scale_amount |
Number. A number to scale the y-axis values. Default: 1 |
make_rda |
Logical. TRUE/FALSE; indicate 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 |
Path. 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()') |
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.
A table ready of landed catch by fleet and year.
[convert_output()], [filter_data()], [process_table()], [export_kqs()], [insert_kqs()], [create_rda()]
table_landings(stockplotr::example_data) table_landings( stockplotr::example_data, unit_label = "landings label", group = "fleet" )table_landings(stockplotr::example_data) table_landings( stockplotr::example_data, unit_label = "landings label", group = "fleet" )
The palette is from the 'viridis' package, which contains palettes distinguishable by those with color vision deficiency.
theme_noaa(discrete = TRUE, ...)theme_noaa(discrete = TRUE, ...)
discrete |
Logical. TRUE/FALSE; indicate whether the color or fill aesthetic is discrete. Default: TRUE |
... |
Arguments passed to 'ggplot2::theme()'. |
A list applying a theme to a ggplot2 object.
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)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)
Add NOAA formatting to a table
theme_table(x)theme_table(x)
x |
Object. Table from gt, flextable, or kableExtra |
Currently, the function can format table objects from: flextable (flextable package, when installed), gt (gt), and kable (kableExtra).
Add the standard formatting for stock assessment reports for any table.
theme_table(cars |> gt::gt()) theme_table(cars |> kableExtra::kable())theme_table(cars |> gt::gt()) theme_table(cars |> kableExtra::kable())