Skip to content
Draft
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
45 changes: 23 additions & 22 deletions R/plot_spawning_biomass.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,41 +167,42 @@ 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#,
# ...
)
# Add reference line
# getting data set - an ifelse statement in the fxn wasn't working
final <- reference_line(
plot = plt,
dat = rp_dat,
era = era,
# era = era,
label_name = "spawning_biomass",
reference = ref_line,
relative = relative,
scale_amount = scale_amount
) + theme_noaa()

# Plot vertical lines if era is not filtering
if (is.null(era)) {
# Find unique era
eras <- unique(plot_data$era)
if (length(eras) > 1) {
year_vlines <- c()
for (i in 2:length(eras)) {
erax <- plot_data |>
dplyr::filter(era == eras[i]) |>
dplyr::pull(year) |>
min(na.rm = TRUE)
year_vlines <- c(year_vlines, erax)
}
}
final <- final +
ggplot2::geom_vline(
xintercept = year_vlines,
color = "#999999"
)
}
# Turning this out because I don't think it's relevant
# if (is.null(era)) {
# # Find unique era
# eras <- unique(plot_data$era)
# if (length(eras) > 1) {
# year_vlines <- c()
# for (i in 2:length(eras)) {
# erax <- plot_data |>
# dplyr::filter(era == eras[i]) |>
# dplyr::pull(year) |>
# min(na.rm = TRUE)
# year_vlines <- c(year_vlines, erax)
# }
# }
# final <- final +
# ggplot2::geom_vline(
# xintercept = year_vlines,
# color = "#999999"
# )
# }

### Make RDA ----
if (make_rda) {
Expand Down
7 changes: 2 additions & 5 deletions R/utils_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ cohort_line <- function(
reference_line <- function(
plot,
dat,
era = "time",
# era = "time",
label_name,
reference,
relative = FALSE,
Expand All @@ -517,9 +517,6 @@ reference_line <- function(
)
}

# Rename era arg
era_name <- era

# Add geom for ref line
plot +
ggplot2::geom_hline(
Expand All @@ -532,7 +529,7 @@ reference_line <- function(
ggplot2::annotate(
geom = "text",
# TODO: need to change this for general process
x = as.numeric(max(dat$year[dat$era == era_name], na.rm = TRUE)), # - as.numeric(max(dat$year[dat$era == "time"], na.rm = TRUE))/200,
x = as.numeric(max(ggplot2::ggplot_build(plot)@data[[2]][["x"]], na.rm = TRUE)), # - as.numeric(max(dat$year[dat$era == "time"], na.rm = TRUE))/200,
y = ref_line_val / ifelse(relative, ref_line_val, scale_amount),
label = glue::glue("{label_name}[{reference}]"), # list(bquote(label_name[.(reference)])),
parse = TRUE,
Expand Down
Loading