-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,8 @@ Imports: | |
scales, | ||
sf, | ||
stringr, | ||
kableExtra | ||
kableExtra, | ||
ggrepel | ||
Suggests: | ||
knitr, | ||
rmarkdown, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#' plot stock_Status | ||
#' | ||
#' Kobe plots of regional stock status | ||
#' | ||
#' @param shadedRegion Numeric vector. Years denoting the shaded region of the plot (most recent 10) | ||
#' @param report Character string. Which SOE report ("MidAtlantic", "NewEngland") | ||
#' | ||
#' @return list of 2 items | ||
#' | ||
#' \item{p}{ggplot object} | ||
#' \item{unknown}{data frame listing stocks with unklnown status} | ||
#' | ||
#' | ||
#' @export | ||
#' | ||
|
||
plot_stock_status <- function(shadedRegion = shadedRegion, | ||
report="MidAtlantic") { | ||
|
||
# generate plot setup list (same for all plot functions) | ||
setup <- ecodata::plot_setup(shadedRegion = shadedRegion, | ||
report=report) | ||
|
||
# which report? this may be bypassed for some figures | ||
if (report == "MidAtlantic") { | ||
councils <- c("MAFMC","Both") | ||
} else { | ||
councils <- c("NEFMC","Both") | ||
} | ||
|
||
# optional code to wrangle ecodata object prior to plotting | ||
# e.g., calculate mean, max or other needed values to join below | ||
fix<- ecodata::stock_status |> | ||
dplyr::mutate(Code = dplyr::recode(Code, "Dogfish" = "Sp. Dogfish" ), | ||
Code = dplyr::recode(Code, "Mackerel" = "At. Mackerel")) | ||
fix <- tidyr::pivot_wider(fix,names_from=Var,values_from=Value) |> | ||
dplyr::filter(Council %in% councils) |> | ||
(\(.) { . ->> unfiltered})() |> | ||
dplyr::group_by(Stock) |> | ||
dplyr::mutate(score = dplyr::case_when( | ||
#(B.Bmsy < 0.5) ~"a", | ||
(F.Fmsy > 1 & B.Bmsy > 0.5 & B.Bmsy < 1) ~ "a", | ||
(F.Fmsy < 1 & B.Bmsy > 0.5 & B.Bmsy < 1) ~ "b", | ||
(F.Fmsy < 1 & B.Bmsy > 1) ~ "c", | ||
(F.Fmsy > 1 & B.Bmsy < 0.5) ~ "d", | ||
(F.Fmsy < 1 & B.Bmsy < 0.5) ~ "b", | ||
(F.Fmsy > 1 & B.Bmsy > 1) ~ "c")) |> | ||
dplyr::mutate(Council = dplyr::recode(Council, "Both" = "NEFMC/MAFMC")) |> | ||
dplyr::filter(!(is.na(F.Fmsy) | is.na(B.Bmsy))) | ||
|
||
unknown <- unfiltered |> | ||
dplyr::filter(is.na(F.Fmsy) | is.na(B.Bmsy)) |> | ||
dplyr::select(Stock,F.Fmsy,B.Bmsy) | ||
|
||
# code for generating plot object p | ||
# ensure that setup list objects are called as setup$... | ||
# e.g. fill = setup$shade.fill, alpha = setup$shade.alpha, | ||
# xmin = setup$x.shade.min , xmax = setup$x.shade.max | ||
# | ||
p <- fix |> | ||
ggplot2::ggplot()+ | ||
ggplot2::geom_vline(xintercept = 1, linetype = "dotted")+ | ||
ggplot2::geom_vline(xintercept = 0.5, linetype = "dashed")+ | ||
ggplot2::geom_hline(yintercept = 1, linetype = "dashed") + | ||
ggplot2::geom_point(ggplot2::aes(x = B.Bmsy, | ||
y = F.Fmsy, | ||
shape = Council, | ||
color = score)) + | ||
ggrepel::geom_text_repel(ggplot2::aes(x = B.Bmsy, #geom_text_repel auto-jitters text around points | ||
y = F.Fmsy, | ||
label = Code, | ||
color = score), | ||
show.legend = FALSE, nudge_y = -0.01, nudge_x = 0.05) + | ||
ggplot2::scale_color_brewer(palette = "Dark2", | ||
breaks = fix$score) + | ||
# ggplot2::ylim(0,y.max) + | ||
# ggplot2::xlim(0,x.max) + | ||
# ggplot2::geom_text(data = unknown, ggplot2::aes(x = x-0.5, y = y+0.2, label = text), #Custom legend for unknown stock status | ||
# size = c(4.75,rep(4,6))) + | ||
ggplot2::xlab(expression(~B/B[msy])) + | ||
ggplot2::ylab(expression(~F/F[msy])) + | ||
ggplot2::guides(color = "none") + | ||
ggplot2::ggtitle(paste0(report,": stock status"))+ | ||
ecodata::theme_ts()+ | ||
ecodata::theme_title() | ||
|
||
# # optional code for New England specific (2 panel) formatting | ||
# if (report == "NewEngland") { | ||
# p <- p + | ||
# ggplot2::theme(legend.position = "bottom", | ||
# legend.title = ggplot2::element_blank()) | ||
# | ||
# } | ||
|
||
return(list(p=p,unknown=unknown)) | ||
|
||
|
||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.