Skip to content

plot_landings() and plot_discards(): predicted as lines with ribbons, observed as points,… - #511

Merged
Schiano-NOAA merged 3 commits into
nmfs-ost:mainfrom
ericward-noaa:refactor-507
Nov 18, 2026
Merged

Schiano-NOAA merged 3 commits into
nmfs-ost:mainfrom
ericward-noaa:refactor-507

Conversation

@ericward-noaa

@ericward-noaa ericward-noaa commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

… bar option

What is the feature?

How have you implemented the solution?

  • Added observed data as points, predicted as lines
  • Optionally stacked bar graph (or side by side)
  • Optional threshold (default 0.1%, like r4ss)

Does the PR impact any other area of the project, maybe another repo?

PR contribution checklist

Thank you for contributing to stockplotr! Please check the boxes below to confirm this pull request (PR) is ready for review. Edit this PR description to add the release indicator and any explanations.

  • I have read and adhered to the contributor guide.
  • I have kept this PR focused on one plot where applicable. For multiple features, I have used separate PRs (stacked PRs are welcome if needed).
  • I have aimed to keep this PR to no more than 750 lines, excluding tests and example data (for example, up to 750 lines for a new function).
  • If I have provided an example dataset, I have explained why the existing sample datasets are not sufficient.
  • I have tested that my changes are compatible with all example outputs in the "data" folder (example_data.rda; pollock.rda; ss3_simple.rda; vermilion_snapper.rda).
  • If I didn't follow the development workflow, I have explained why in this PR.
  • If applicable, I've added the plot to save_all_plots() and updated the associated tests in test-save_all_plots.R.
  • After opening this PR, I have checked that my own tests and spellcheck pass (spelling::spell_check_package()). If other checks fail, I have flagged them for the package maintainers to help diagnose and remedy.
  • I have requested review from one package maintainer (Sam or Sophie).

@ericward-noaa

Copy link
Copy Markdown
Contributor Author

Here's the new behavior to deal with #507

library(stockplotr)
dat <- stockplotr::vermilion_snapper

# 1. Default: predicted landings as lines with 95% ribbons, observed as points,
#    all fleets on one panel colored by fleet
plot_landings(dat, interactive = FALSE)

# 2. One panel per fleet, with 80% intervals instead of 95%
plot_landings(dat, facet = "fleet", interval = 0.8, interactive = FALSE)

# 3. Observed landings by fleet as side-by-side bars for each year
plot_landings(dat, geom = "bar", interactive = FALSE)

# 4. The same bars stacked, like r4ss::SSplotCatch()
plot_landings(dat, geom = "bar", position = "stack", interactive = FALSE)

# 5. The 0.1% rule: vermilion's observed and predicted landings differ by about
#    1.4%, so the fit is shown at the default tolerance = 0.001. With a looser
#    tolerance they count as matching: observed landings are drawn as lines,
#    with a message.
plot_landings(dat, tolerance = 0.05, interactive = FALSE)
#> ℹ The observed and predicted landings differ by less than `tolerance` (5% of the largest observed landings); plotting the observed landings only.
#> Ignoring unknown labels:
#> • linetype : "Fleet"
#> • shape : "Fleet"

Created on 2026-11-17 with reprex v2.1.1

@ericward-noaa

Copy link
Copy Markdown
Contributor Author

@sbreitbart-NOAA @Schiano-NOAA this fix ready for review

Drop checks that retest index_observed_interval() or ggplot2 internals and
the argument-validation errors.
@sbreitbart-NOAA

Copy link
Copy Markdown
Collaborator

These plots are beautiful. Should this new setup apply to other plots using the plot_obsvpred() step, such as plot_index() and plot_discard()?

@ericward-noaa

Copy link
Copy Markdown
Contributor Author

@sbreitbart-NOAA thanks! Happy to do that here, or in another PR

@sbreitbart-NOAA

sbreitbart-NOAA commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

@sbreitbart-NOAA thanks! Happy to do that here, or in another PR

@ericward-noaa please put the changes in this PR and change the PR title to reflect those changes. Thanks!

@ericward-noaa

ericward-noaa commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

@sbreitbart-NOAA @Schiano-NOAA and tagging @iantaylor-NOAA Something to get feedback on:

I think applying these to the index plots in plot_index is probably the trickiest. Right now, this PR has ribbons on landings, which represents the uncertainty around the estimate. But plot_index() shows vertical lines on observed points (how uncertain each point is -- this is observation error,

#' @param interval Number. Coverage of intervals around the observed index
) ) -- so the uncertainty represents different things. Or maybe I'm misunderstanding this and need to dig into it more.

@Schiano-NOAA

Copy link
Copy Markdown
Collaborator

Yeah on second thought I think this wouldn't apply to the plot_index, but I think it is for plot_discard

…ngs():

geom: “line”, “bar” or “point”.
predicted = TRUE.
interval = 0.95.
tolerance = 0.001.
facet = "fleet" now gives one panel per fleet.

- helpers out of plot_landings.R into a new file, R/utils_plot_fit.R
- new test-plot_discard.R
- example_data has no ribbons, because its discard uncertainty is labeled std
@ericward-noaa ericward-noaa changed the title plot_landings(): predicted as lines with ribbons, observed as points,… plot_landings() and plot_discards(): predicted as lines with ribbons, observed as points,… Nov 18, 2026
@ericward-noaa

Copy link
Copy Markdown
Contributor Author

@Schiano-NOAA @sbreitbart-NOAA Ok, I think this is ready - changed applied to plot_discards() too

@Schiano-NOAA

Copy link
Copy Markdown
Collaborator

@ericward-noaa awesome! Thank you

@Schiano-NOAA

Copy link
Copy Markdown
Collaborator

These changes look great. Much appreciated improvement thanks!

@Schiano-NOAA
Schiano-NOAA merged commit 6c2c678 into nmfs-ost:main Nov 18, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants