Skip to content

Commit

Permalink
Created new plot for Anchor River Optimum Yeild profile, that removes…
Browse files Browse the repository at this point in the history
… other panels and only shows 90% MSY line, and updates the escapement goal shading to 3200-6400. OYP_plotUpdate.R creates the new figure.

Updated plot_profile() function within the plot.R script, to include an option for selection 70,80,90 % MSY lines to include in figure. The old function is just commented out.
  • Loading branch information
lfwendling committed Sep 26, 2023
1 parent 42b47fa commit aca5593
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 2 deletions.
38 changes: 38 additions & 0 deletions Script/OYP_plotUpdate.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Update to Optimal Yeild Profile plot as requested 9/21/2023 -
# Removed other panels, updated Esc goal range to 3200-6400 , remove 70 & 80% lines


#### Import data and Function ####
packs <- c("jagsUI", "tidyverse")
lapply(packs, require, character.only = TRUE)

#source functions
function_files <- list.files(path=".\\functions")
lapply(function_files, function(x) source(paste0(".\\functions\\", x)))

#load datasets
data_names <- list.files(path=".\\data")
lapply(data_names, function(x) load(paste0(".\\data\\", x), .GlobalEnv))

post <- readRDS(".\\output\\post_1977on") #OUTPUT is currently located in S:\RTS\Reimer\Anchor_River_Chinook

####



#### Create Plot ####

profile_full <- get_profile(post)
OYP_update = plot_profile(profile_full,rug=FALSE ,goal_range = c(3200, 6400),profiles = c("OYP"),percent = c("90"))+
scale_x_continuous("Spawners", breaks = seq(0, 9000,800), labels = scales::comma)+theme(legend.position = "none")+
labs(caption = "
Probability of achieving sustained yield within 90 percent of maximum sustained yield for Anchor River Chinook salmon.
The shaded area represents to escapement goal recommendation of 3,200-6,400 Chinook salmon.
")+
theme(plot.caption = element_text(hjust=0))
OYP_update

####

#ggsave("OYP_update.png",height = 3,width = 9,units = "in")

53 changes: 51 additions & 2 deletions functions/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,56 @@ plot_horse_full <- function(post_dat, firstyr = 1977){
#' lapply(profiles, plot_profile)
#'
#' @export
plot_profile <- function(profile_dat, limit = NULL, rug = TRUE, goal_range = NA, profiles = c("OYP", "ORP", "OFP")){
temp <-unlist(lapply(profiles, function(x){paste0(x, c("70", "80", "90"))}))
# plot_profile <- function(profile_dat, limit = NULL, rug = TRUE, goal_range = NA, profiles = c("OYP", "ORP", "OFP")){
# temp <-unlist(lapply(profiles, function(x){paste0(x, c("70", "80", "90"))}))
# profile_label <- ggplot2::as_labeller(c('OYP' = "Optimum Yield Profile",
# 'OFP' = "Overfishing Profile",
# 'ORP' = "Optimum Recruitment Profile"))
# S.msy50 <- median(profile_dat$s[which.max(profile_dat$OYP90)]) #approximate
# rug_dat <- get_BEGbounds(S.msy50)
#
# if(is.null(limit)){
# xmax <- S.msy50 * 2.25
# }
# else xmax <- limit
#
# plot <- profile_dat %>%
# dplyr::select_("s", .dots = temp) %>%
# dplyr::group_by(s) %>%
# dplyr::filter(s <= xmax) %>%
# dplyr::summarise(across(starts_with("O"), function(x) mean(x, na.rm = TRUE))) %>%
# tidyr::gather("key", "prob", -s, factor_key = TRUE) %>%
# dplyr::mutate(profile = factor(stringr::str_extract(key, "[A-Z]+"),
# levels = c("OYP", "OFP", "ORP")),
# max_pct = stringr::str_extract(key, "[0-9]+")) %>%
# ggplot2::ggplot(ggplot2::aes(x = s, y = prob, linetype = max_pct)) +
# ggplot2::geom_line() +
# ggplot2::scale_x_continuous("Spawners", limits = c(0, xmax), labels = scales::comma) +
# ggplot2::scale_y_continuous("Probability", breaks = seq(0, 1, 0.2), limits = c(0, 1)) +
# ggplot2::scale_linetype_discrete(name = "Percent of Max.") +
# ggplot2::facet_grid(profile ~ ., labeller = profile_label) +
# ggplot2::theme_bw()
#
# if(rug == TRUE) {
# plot2 <- plot +
# ggplot2::geom_rug(ggplot2::aes(x = lb_Kenai), data = rug_dat, inherit.aes = FALSE, sides = "b", color = "darkgrey") +
# ggplot2::geom_rug(ggplot2::aes(x = ub_Kenai), data = rug_dat, inherit.aes = FALSE, sides = "b", color = "black")
# }
# else plot2 <- plot
#
# if(!anyNA(goal_range)) {
# plot2 + ggplot2::geom_rect(ggplot2::aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax),
# data.frame(xmin = goal_range[1], xmax = goal_range[2], ymin = -Inf, ymax = Inf),
# inherit.aes = FALSE, fill = "red", alpha = 0.2)
# }
# else plot2
# }

# # Version 2
## Adds the ability to select which %MSY curves to show.
plot_profile <- function(profile_dat, limit = NULL, rug = TRUE, goal_range = NA, profiles = c("OYP", "ORP", "OFP"),
percent = c("70","80","90")){
temp <-unlist(lapply(profiles, function(x){paste0(x, percent)}))
profile_label <- ggplot2::as_labeller(c('OYP' = "Optimum Yield Profile",
'OFP' = "Overfishing Profile",
'ORP' = "Optimum Recruitment Profile"))
Expand Down Expand Up @@ -474,6 +522,7 @@ plot_profile <- function(profile_dat, limit = NULL, rug = TRUE, goal_range = NA,
}



# State variable plot -----------------------------------------------------

#' State Variable Plot
Expand Down

0 comments on commit aca5593

Please sign in to comment.