-
Notifications
You must be signed in to change notification settings - Fork 6
[feat]: enable user to add a reference line to the plot for each input dat #315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e912c0a
c7acf3a
12348bc
ed04eef
7b6170d
711627c
98286c2
6cb15b4
b47e247
1ac2b74
222f420
1f44495
0ba22c4
64b6e7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -76,14 +76,19 @@ plot_fishing_mortality <- function( | |||||||||||
| facet = facet, | ||||||||||||
| ... | ||||||||||||
| ) | ||||||||||||
| # Add reference line and theme | ||||||||||||
| final <- reference_line( | ||||||||||||
| plot = plt, | ||||||||||||
| dat = dat, | ||||||||||||
| label_name = "fishing_mortality", | ||||||||||||
| reference = ref_line, | ||||||||||||
| scale_amount = 1 | ||||||||||||
| ) + theme_noaa() | ||||||||||||
| # Add reference line | ||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this information should be added to the |
||||||||||||
| # Conditions for ref line | ||||||||||||
| # 1. all are comparing same value = msy, target, unfished... | ||||||||||||
| # 2. custom input vector = c("sable23_msy"=30, "sable25_msy"=40) -- user must indicate which model in label otherwise it will assign in order of dat | ||||||||||||
| # 3. input vector of labels = c("msy", "target") | ||||||||||||
| # getting data set - an ifelse statement in the fxn wasn't working | ||||||||||||
|
Comment on lines
+80
to
+84
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(this is repeated in utils_plot.R) |
||||||||||||
| final <- plt + | ||||||||||||
| add_reference_line( | ||||||||||||
| dat = dat, | ||||||||||||
| ref_line = ref_line, | ||||||||||||
| label = "fishing_mortality" | ||||||||||||
| ) + | ||||||||||||
| theme_noaa() | ||||||||||||
|
|
||||||||||||
| ### Make RDA ---- | ||||||||||||
| if (make_rda) { | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,12 +145,6 @@ plot_spawning_biomass <- function( | |
| ) | ||
| } | ||
| ) | ||
| # Pull first df if in a list to find reference point | ||
| if (!is.data.frame(dat)) { | ||
| rp_dat <- dat[[1]] | ||
| } else { | ||
| rp_dat <- dat | ||
| } | ||
|
|
||
| if (relative & scale_amount > 1) { | ||
| cli::cli_alert_warning("Scale amount is not applicable when relative = TRUE. Resetting scale_amount to 1.") | ||
|
|
@@ -202,41 +196,23 @@ plot_spawning_biomass <- function( | |
| ylab = spawning_biomass_label, | ||
| group = group, | ||
| # add check in case facet is returned as character(0) | ||
| facet = if (length(facet) > 0) facet else NULL, | ||
| ... | ||
| facet = if (length(facet) > 0) facet else NULL#, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are the comments leftover from testing? |
||
| # ... | ||
| ) | ||
| # Add reference line | ||
| # getting data set - an ifelse statement in the fxn wasn't working | ||
| if (relative) { | ||
| # don't add any reference line here and just add theme for final plot | ||
| final <- plt + theme_noaa() | ||
| } else { | ||
| if ("unfished" %in% c(names(ref_line), ref_line)) { | ||
| # find the minimum x axis value from the plot | ||
| min_year <- min <- ggplot2::ggplot_build(plt)[["data"]][[2]] |> | ||
| as.data.frame() |> | ||
| dplyr::pull(x) |> | ||
| min() |> | ||
| round(digits = 2) | ||
| # find the reference point value for unfished | ||
| ref_point <- calculate_reference_point( | ||
| dat = rp_dat, | ||
| reference_name = "spawing_biomass_unfished" | ||
| ) / scale_amount | ||
| # add point to plot and add theme | ||
| final <- plt + | ||
| ggplot2::geom_point(ggplot2::aes(x = min_year - 1, y = ref_point)) + # should I keep -1 or set as first year? | ||
| theme_noaa() | ||
| } else { | ||
| final <- reference_line( | ||
| plot = plt, | ||
| dat = rp_dat, | ||
| final <- plt + | ||
| add_reference_line( | ||
| dat = dat, | ||
| ref_line = ref_line, | ||
| label = "spawning_biomass", | ||
| lbs = lbs, | ||
| label_name = "spawning_biomass", | ||
| reference = ref_line, | ||
| scale_amount = scale_amount | ||
| ) + theme_noaa() | ||
| } | ||
| ) + | ||
| theme_noaa() | ||
| } | ||
|
|
||
| ### Make RDA ---- | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the messages shown when a ref line isn't found. Here, it shows up for one model but not both, even though zero ref lines are shown (i.e., no message warning about a lack of ref line for the stockplotr example data, but it's not shown):
plot_biomass(dat = list("petrale" = dat, "skate" = skate), module = "TIME_SERIES")! biomass_msy not found for skate
Warning messages:
1: Removed 1 row containing missing values or values
outside the scale range (
geom_hline()).2: Removed 1 row containing missing values or values
outside the scale range (
geom_text()).