Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 6 additions & 25 deletions R/plot_biomass.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,37 +141,18 @@ plot_biomass <- function(
...
)
# 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 = stockplotr::example_data,
reference_name = "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,
label_name = "biomass",
reference = ref_line,
final <- plt +

Copy link
Copy Markdown
Collaborator

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()).

Image

add_reference_line(
dat = dat,
ref_line = ref_line,
label = "biomass",
scale_amount = scale_amount
) +
theme_noaa()
}
theme_noaa()
}

### Make RDA ----
Expand Down
21 changes: 13 additions & 8 deletions R/plot_fishing_mortality.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this information should be added to the ref_line documentation so that people know what to expect when adding multiple reference lines. Adding an example with multiple models and reference lines would help clarify these rules too, as would adding a section to the FAQs about how to add reference lines in a few different situations

# 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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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

(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) {
Expand Down
42 changes: 9 additions & 33 deletions R/plot_spawning_biomass.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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#,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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 ----
Expand Down
Loading