plot_biomass: Plot biomass from MCMC output for one or more models....

View source: R/plot-biomass.R

plot_biomassR Documentation

Plot biomass from MCMC output for one or more models. Includes the virgin biomass, B0

Description

Plot biomass from MCMC output for one or more models. Includes the virgin biomass, B0

Create a plot of cohorts by age as a set of lines

Plot the relative spawning biomass with several forecast trajectories

Create a plot of exploitation fraction

Create a plot of fishing intensity

Create a plot of forecast value comparisons with the catch level on the x-axis and probability as the y axis value

Plot recruitment deviations from MCMC output for one or more models

Plot recruitment from MCMC output for one or more models

Plot relative biomass from MCMC output for one or more models

Plot recruitment from MCMC output for one or more models, relative to a particular year

Plot survey index fits from MCMC output for one or more models, for one of the acoustic surveys

Usage

plot_biomass(
  model_lst = NULL,
  model_names,
  d_obj = NULL,
  show_arrows = TRUE,
  xlim = c(1964, year(Sys.time())),
  x_breaks = 1966:year(Sys.time()),
  x_labs_mod = 5,
  x_expansion = 3,
  tick_prop = 1,
  vjust_x_labels = -0.25,
  ylim = c(0, 4.5),
  y_breaks = seq(ylim[1], ylim[2], by = 0.5),
  leg_pos = c(0.65, 0.83),
  leg_ncol = 1,
  leg_font_size = 12,
  dodge_bo = 3,
  rev_colors = TRUE,
  wrap_y_label = FALSE,
  alpha = ts_ribbon_alpha,
  point_size = ifelse(is_single_model, ts_single_model_pointsize, ts_pointsize),
  point_color = ts_single_model_pointcolor,
  point_shape = ifelse(is_single_model, ts_single_model_pointshape, ts_pointshape),
  point_stroke = ifelse(is_single_model, ts_single_model_pointstroke, ts_pointstroke),
  line_width = ifelse(is_single_model, ts_single_model_linewidth, ts_linewidth),
  line_gap = ts_linegap,
  single_ribbon_lines_color = ts_single_model_linecolor,
  single_ribbon_fill = ts_single_model_ribbon_fill,
  ribbon_line_type = ifelse(is_single_model, ts_single_model_ribbon_linetype,
    ts_ribbon_linetype),
  refpt_bo_linecolor = refpt_bo_linecolor,
  refpt_usr_linecolor = refpt_usr_linecolor,
  refpt_lrp_linecolor = refpt_lrp_linecolor,
  refpt_bo_linewidth = refpt_bo_linewidth,
  refpt_usr_linewidth = refpt_usr_linewidth,
  refpt_lrp_linewidth = refpt_lrp_linewidth,
  refpt_bo_linetype = refpt_bo_linetype,
  refpt_usr_linetype = refpt_usr_linetype,
  refpt_lrp_linetype = refpt_lrp_linetype
)

plot_cohort_catch(
  model,
  cohorts = c(1999, 2010, 2014, 2016, 2020),
  ages = 0:20,
  y_breaks = seq(0, 1250, 250),
  leg_pos = c(0.85, 0.5),
  leg_ncol = 1,
  leg_font_size = 12,
  axis_title_font_size = 14,
  axis_tick_font_size = 11,
  line_width = 1,
  show_arrowheads = TRUE,
  arrow_size = 0.03
)

plot_depl_fore_comparison(
  model,
  fore_inds = c(1, 2, model$ct_levels_vals$ct_actual_ind,
    model$ct_levels_vals$ct_tac_ind, model$ct_levels_vals$ct_default_policy_ind),
  xlim = c(max(forecast_yrs) - 16, max(forecast_yrs) - 1),
  x_breaks = xlim[1]:xlim[length(xlim)],
  x_labs_mod = 5,
  show_arrows = FALSE,
  x_expansion = 1,
  tick_prop = 1,
  vjust_x_labels = -2,
  ylim = c(0, 2),
  y_breaks = c(0, 0.1, 0.4, 0.5, 1, 1.5, 2),
  y_labels = expression("0", "0.1B"[0], "0.4B"[0], "0.5", "B"[0], "1.5", "2"),
  y_colors = c("black", "red", "green", "black", "blue", "black", "black"),
  alpha = 0.2,
  leg_pos = c(0.15, 0.83),
  leg_ncol = 1,
  leg_font_size = 12,
  forecast_yrs,
  point_size = ts_pointsize,
  point_shape = ts_pointshape
)

plot_exploitation_fraction(
  model,
  show_arrows = TRUE,
  xlim = c(1964, year(Sys.time()) - 1),
  x_breaks = 1966:year(Sys.time()),
  x_labs_mod = 5,
  x_expansion = 1,
  tick_prop = 1,
  ylim = c(0, 0.25),
  y_breaks = seq(ylim[1], ylim[2], by = 0.05),
  point_size = ts_single_model_pointsize,
  point_color = ts_single_model_pointcolor,
  point_shape = ts_single_model_pointshape,
  point_stroke = ts_single_model_pointstroke,
  line_width = ts_single_model_linewidth,
  line_color = ts_single_line_color
)

plot_fishing_intensity(
  model,
  show_arrows = TRUE,
  xlim = c(1964, year(Sys.time()) - 1),
  x_breaks = 1966:year(Sys.time()),
  x_labs_mod = 5,
  x_expansion = 1,
  tick_prop = 1,
  ylim = c(0, 1.4),
  y_breaks = seq(ylim[1], ylim[2], by = 0.2),
  point_size = ts_single_model_pointsize,
  point_color = ts_single_model_pointcolor,
  point_shape = ts_single_model_pointshape,
  point_stroke = ts_single_model_pointstroke,
  line_width = ts_single_model_linewidth,
  line_color = ts_single_line_color,
  fspr40_text_x = xlim[1] + 2,
  fspr40_text_y = 1.05
)

plot_fore_compare(
  model,
  forecast_yrs,
  fore_yr,
  colors = c("black", "blue", "green", "orange", "red", "tan"),
  shapes = c(16, 17, 17, 17, 15, 18),
  x_expansion = 40,
  leg_font_size = 8,
  leg_pos = NULL,
  leg_ncol = 1,
  remove_x_val = NULL,
  show_50_line = TRUE,
  short = FALSE
)

plot_recdevs(
  model_lst = NULL,
  model_names = NULL,
  d_obj = NULL,
  show_arrows = TRUE,
  xlim = c(1946, year(Sys.time())),
  x_breaks = xlim[1]:xlim[2],
  x_labs_mod = 5,
  x_expansion = 2,
  tick_prop = 1,
  vjust_x_labels = -1,
  ylim = c(-5, 5),
  y_breaks = seq(ylim[1], ylim[2], by = 1),
  leg_pos = c(0.65, 0.83),
  leg_ncol = 1,
  leg_font_size = 12,
  alpha = 1,
  point_color = ts_single_model_pointcolor,
  point_size = ifelse(is_single_model, ts_single_model_pointsize, ts_pointsize),
  point_shape = ifelse(is_single_model, ts_single_model_pointshape, ts_pointshape),
  point_stroke = ifelse(is_single_model, ts_single_model_pointstroke, ts_pointstroke),
  line_width = ifelse(is_single_model, ts_single_model_linewidth, ts_linewidth),
  line_type = ts_single_model_linetype,
  line_color = ts_single_model_linecolor,
  dodge_val = 1,
  rev_colors = FALSE,
  ...
)

plot_recruitment(
  model_lst = NULL,
  model_names = NULL,
  show_arrows = TRUE,
  inc_means = FALSE,
  relative = FALSE,
  xlim = c(1966, year(Sys.time())),
  x_breaks = xlim[1]:xlim[2],
  x_labs_mod = 5,
  x_expansion = 2,
  tick_prop = 1,
  vjust_x_labels = -1,
  ylim = c(0, 40),
  y_breaks = seq(ylim[1], ylim[2], by = 10),
  y_labels = y_breaks,
  y_colors = rep("black", length(y_breaks)),
  alpha = 0.3,
  leg_pos = c(0.65, 0.83),
  leg_ncol = 1,
  leg_font_size = 12,
  point_size = ifelse(is_single_model, ts_single_model_pointsize, ts_pointsize),
  color = ts_single_model_pointcolor,
  point_shape = ifelse(is_single_model, ts_single_model_pointshape, ts_pointshape),
  point_stroke = ifelse(is_single_model, ts_single_model_pointstroke, ts_pointstroke),
  line_width = ifelse(is_single_model, ts_single_model_linewidth, ts_linewidth),
  horizontal_line_color = "darkgreen",
  crossbar_width = 0,
  dodge_val = 0.5,
  rev_colors = TRUE,
  d_obj = NULL
)

plot_rel_biomass(
  model_lst = NULL,
  model_names = NULL,
  d_obj = NULL,
  show_arrows = TRUE,
  xlim = c(1966, year(Sys.time())),
  x_breaks = xlim[1]:xlim[2],
  x_labs_mod = 5,
  x_expansion = 3,
  tick_prop = 1,
  vjust_x_labels = -2,
  hjust_y_labels = 0,
  ylim = c(0, 3.5),
  y_breaks = seq(ylim[1], ylim[2], by = 0.5),
  leg_pos = c(0.65, 0.83),
  leg_ncol = 1,
  leg_font_size = 12,
  rev_colors = TRUE,
  wrap_y_label = FALSE,
  alpha = ts_ribbon_alpha,
  point_color = ts_single_model_pointcolor,
  point_size = ifelse(is_single_model, ts_single_model_pointsize, ts_pointsize),
  point_shape = ifelse(is_single_model, ts_single_model_pointshape, ts_pointshape),
  point_stroke = ifelse(is_single_model, ts_single_model_pointstroke, ts_pointstroke),
  line_width = ifelse(is_single_model, ts_single_model_linewidth, ts_linewidth),
  line_gap = ts_linegap,
  single_ribbon_lines_color = ts_single_model_linecolor,
  single_ribbon_fill = ts_single_model_ribbon_fill,
  ribbon_line_type = ifelse(is_single_model, ts_single_model_ribbon_linetype,
    ts_ribbon_linetype),
  refpt_bo_linecolor = ts_refpt_bo_linecolor,
  refpt_usr_linecolor = ts_refpt_usr_linecolor,
  refpt_lrp_linecolor = ts_refpt_lrp_linecolor,
  refpt_bo_linewidth = ts_refpt_bo_linewidth,
  refpt_usr_linewidth = ts_refpt_usr_linewidth,
  refpt_lrp_linewidth = ts_refpt_lrp_linewidth,
  refpt_bo_linetype = ts_refpt_bo_linetype,
  refpt_usr_linetype = ts_refpt_usr_linetype,
  refpt_lrp_linetype = ts_refpt_lrp_linetype,
  ...
)

plot_rel_recruitment(
  model_lst = NULL,
  model_names,
  rel_yr = 2010,
  inc_means = FALSE,
  xlim = c(1966, year(Sys.time())),
  x_breaks = xlim[1]:xlim[2],
  x_labs_mod = 5,
  x_expansion = 3,
  ylim = c(0, 1.2),
  y_breaks = seq(ylim[1], ylim[2], by = 0.1),
  y_labels = y_breaks,
  y_colors = rep("black", length(y_breaks)),
  alpha = 0.2,
  leg_pos = c(0.65, 0.83),
  leg_ncol = 1,
  leg_font_size = 12,
  axis_title_font_size = 14,
  axis_tick_font_size = 11,
  point_size = 1.5,
  line_width = 0.5,
  clip_cover = 2,
  single_point_color = "black",
  single_line_color = "black",
  crossbar_width = 0,
  dodge_val = 0.5,
  rev_colors = FALSE,
  d_obj = NULL
)

plot_survey_index_fits(
  model,
  model_lst = NULL,
  model_names = NULL,
  d_obj = NULL,
  show_arrows = TRUE,
  survey_type = c("age1", "age2"),
  xlim = c(1995, 2021),
  x_breaks = xlim[1]:xlim[2],
  x_labs_mod = 5,
  x_expansion = 3,
  tick_prop = 1,
  vjust_x_labels = -0.25,
  ylim = c(0, 3),
  y_breaks = seq(ylim[1], ylim[2], by = 0.5),
  leg_pos = c(0.65, 0.83),
  leg_ncol = 1,
  leg_font_size = 12,
  alpha = 1,
  point_color = ts_single_model_pointcolor,
  point_size = ifelse(is_single_model, ts_single_model_pointsize, ts_pointsize),
  point_shape = ifelse(is_single_model, ts_single_model_pointshape, ts_pointshape),
  line_width = ifelse(is_single_model, ts_single_model_linewidth, ts_linewidth),
  line_type = ts_single_model_linetype,
  line_color = ts_single_model_linecolor,
  obs_point_shape = 17,
  obs_point_size = point_size * 2,
  obs_line_type = "dashed",
  obs_line_width = 1.25,
  obs_err_line_type = "solid",
  obs_err_line_width = 1,
  obs_color = "black",
  dodge_val = 0.5,
  rev_colors = FALSE,
  ...
)

Arguments

model_lst

A list of models, each created by create_rds_file()

model_names

A vector of model names,the same length as models_lst

d_obj

If not NULL this is a list which has been pre-processed to contain all models in a format that is ready to plot. Essentially the first steps of this function have been replicated outside the function (The code inside the ⁠if(is.null(d_obj))⁠) is done to stop the Rmd process from taking forever

show_arrows

Logical. If TRUE, show arrow that point toward medians lying outside the plotting area. Also allow the lines toward those median points to be plotted outside the plotting area. If FALSE, truncate the medians that lie outside the plotting area to the maximum (or minimum) y limit and draw the lines to go through those new values

xlim

The year limits to plot

x_breaks

The year value tick marks to show for the x axis

x_labs_mod

Value for major X-axis tick marks. Every Nth tick will be longer and have a label. The first and last will be shown regardless of what this number is

x_expansion

Amount to expand the x axis. See the expand argument in ggplot2::scale_x_continuous()

tick_prop

A value that the length of the major tick marks are multiplied by. This proportion must be set by trial and error. Make sure to change vjust_x_labels so the labels are not overlapping the lines or are too far away from the lines

vjust_x_labels

Adjustment to move the x-axis tick labels and label up or down. Negative numbers move down

ylim

The y-axis minimum and maximum limits for the plot

y_breaks

The tick mark values to show for the y-axis

leg_pos

The position of the legend inside the plot. If NULL, NA, or "none", the legend will not be shown

leg_ncol

The number of columns to show in the legend

leg_font_size

The legend font size labels

dodge_bo

A value to adjust the spacing between multiple B0 points and errorbars in the case of more than one model being plotted

rev_colors

Logical. If TRUE, reverse the order of the colors in the plot. Only applies if more than one model is plotted

wrap_y_label

Logical. If TRUE, adds a newline to the y-axis label so that it doesn't get cut off

alpha

The transparency for the ribbons (credible intervals)

point_size

The size of the points used for the median lines (See ggplot2::geom_point() for more details)

point_color

The R color for the points used for the median lines (See ggplot2::geom_point() for more details)

point_shape

The R shape number for the points used for the median lines (See ggplot2::geom_point() for more details)

point_stroke

The stroke value for the points used for the median lines (See ggplot2::geom_point() for more details)

line_width

Width of the median line and errorbar line (for the B0 value) (See ggplot2::geom_path() for more details)

line_gap

Gap between the connecting lines and points for each line. See the mult parameter of ggh4x::geom_pointpath()

single_ribbon_lines_color

Line color for the ribbon limit lines (credible interval) for the case where there is only a single model to plot

single_ribbon_fill

The ribbon fill color if there is only a single model

ribbon_line_type

Line type for ribbon edges; use 0 for no line.

refpt_bo_linecolor

The line color for the B0 horizontal line

refpt_usr_linecolor

The line color for the Upper stock reference horizontal line

refpt_lrp_linecolor

The line color for the Limit Reference point horizontal line

refpt_bo_linewidth

The line width for the B0 horizontal line

refpt_usr_linewidth

The line width for the Upper stock reference horizontal line

refpt_lrp_linewidth

The line width for the Limit Reference point horizontal line

refpt_bo_linetype

The line type for the B0 horizontal line

refpt_usr_linetype

The line type for the Upper stock reference horizontal line

refpt_lrp_linetype

The line type for the Limit Reference point horizontal line

model

A model, created by create_rds_file()

cohorts

A vector of cohorts to make lines for

ages

A vector of ages to show

show_arrowheads

Logical. If TRUE show arrowheads on the ends of the lines

arrow_size

size of the arrow heads, npc units. See grid::unit() For description of npc

fore_inds

Indices of the model$ct_levels list to include as forecast catch streams in the plot

y_labels

Labels for the tick marks on the y-axis

y_colors

Colors for the tick labels on the y-axis

forecast_yrs

A vector of the forecast years

fspr40_text_x

X-axis value for the location of the FSPR=40% text

fspr40_text_y

Y-axis value for the location of the FSPR=40% text

fore_yr

The forecast year to use in the plot. Must be in forecast_yrs

colors

Colors to use for the lines in the plot

shapes

Shapes to use for the points in the plot. Must be the same length as colors

remove_x_val

A vector of values to remove labels for on the x axis. Plot first leaving this as NULL, then add values to this that overlap others

show_50_line

Logical. If TRUE, draw a horizontal line at 50\%

short

Logical. If TRUE, draw only 3 lines (decline, under B40, under B10)

dodge_val

The amount to separate lines between unique models multiple model plots

...

Arguments passed to ggplot2::geom_pointrange()

inc_means

Logical. If TRUE include the mean values in the plot. Used for recruitment plot only

relative

Logical. If TRUE, create a relative recruitment plot using the r_rel_lower, r_rel_med, r_rel_upper, r_rel_mean, and r_rel_init elements of mcmccalcs which are created in the function calc_mcmc(). In that function, the relative year is set. It is 2010 by default. To change it, edit the year in the calc_mcmc() function, and then create_rds_file() needs to be run again to create the RDS file for the model

horizontal_line_color

for relative plot, colour of the dashed line at 1

survey_type

Either age1 or age2. Used for survey index plots only

ax_title_font_size

Size of the font for the X and Y axis labels

ax_tick_font_size

Size of the font for the X and Y axis tick labels

ax_label_color

Color of the font for the X and Y axis tick and title labels

Value

a ggplot2::ggplot() object


pacific-hake/hake-assessment documentation built on Jan. 14, 2025, 9:12 p.m.