Skip to content

Commit

Permalink
add plot_harborporpoise
Browse files Browse the repository at this point in the history
  • Loading branch information
sgaichas committed Dec 11, 2023
1 parent 609af70 commit fff302b
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export(plot_grayseal)
export(plot_gsi)
export(plot_habitat_diversity)
export(plot_habs)
export(plot_harborporpoise)
export(plot_ichthyo_diversity)
export(plot_long_term_sst)
export(plot_mab_inshore_survey)
Expand Down
89 changes: 89 additions & 0 deletions R/plot_harborporpoise.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#' plot harborporpoise
#'
#'Time series of annual and 5 year rolling mean harbor porpoise bycatch with potential
#' biological removal (PRB) threshold. Same plot for both regions.
#'
#' @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 ggplot object
#'
#'
#' @export
#'

plot_harborporpoise <- 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") {
filterEPUs <- c("MAB")
} else {
filterEPUs <- c("GB", "GOM")
}

# optional code to wrangle ecodata object prior to plotting
# e.g., calculate mean, max or other needed values to join below
ribbon<- ecodata::harborporpoise |>
tidyr::pivot_wider(names_from = Var, values_from = Value)

# 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 <- ecodata::harborporpoise |>
dplyr::filter(Var %in% c("pbr", "totalest5y", "totalest1y")) |>
ggplot2::ggplot()+
ggplot2::geom_line(ggplot2::aes(x = Time, y = Value, linetype = Var, color = Var))+
ggplot2::geom_ribbon(data = ribbon, ggplot2::aes(ymin = total5yLCI, ymax =total5yUCI, x = Time), fill = "blue", alpha = 0.2)+
ggplot2::ggtitle("Harbor Porpoise Bycatch")+
ggplot2::ylab("Estimated Bycatch (n)")+
ggplot2::scale_linetype_manual(name="",
values=c(1,2,1),
labels = c("PBR", "Annual Estimates", "5yr rolling mean and CI"))+
ggplot2::scale_color_manual(name="",values = c('red', 'black','blue'),
labels = c("PBR", "Annual Estimates", "5yr rolling mean and CI"))+
ggplot2::theme(#legend.position = "none",
legend.title = ggplot2::element_blank(),
legend.position = c(0.75, 0.8),
legend.text = ggplot2::element_text(size = 8),
legend.background = ggplot2::element_rect(
colour = "transparent", fill = "transparent"))+
#ggplot2::guides(color = "none")+
ecodata::theme_ts()+
ecodata::theme_title()

return(p)

# Paste commented original plot code chunk for reference
# ribbon<- ecodata::harborporpoise %>%
# tidyr::pivot_wider(names_from = Var, values_from = Value)
#
# ecodata::harborporpoise %>%
# dplyr::filter(Var %in% c("pbr", "totalest5y", "totalest1y")) %>%
# ggplot2::ggplot()+
# ggplot2::geom_line(aes(x = Time, y = Value, linetype = Var, color = Var))+
# ggplot2::geom_ribbon(data = ribbon, aes(ymin = total5yLCI, ymax =total5yUCI, x = Time), fill = "blue", alpha = 0.2)+
# ggplot2::ggtitle("Harbor Porpoise Bycatch")+
# ggplot2::ylab("Estimated Bycatch (n)")+
# ggplot2::scale_color_manual(name = element_blank(), values = c('red', 'black','blue'))+
# ggplot2::scale_linetype_manual(values=c(1,2,1),
# labels = c("PBR", "Annual Estimates", "5yr rolling mean and CI"))+
# ggplot2::theme(#legend.position = "none",
# legend.title = element_blank(),
# legend.position = c(0.75, 0.8),
# legend.text = element_text(size = 8),
# legend.background = element_rect(
# colour = "transparent", fill = "transparent"))+
# guides(color = FALSE)+
# ecodata::theme_ts()+
# ecodata::theme_title()
#
#

}
20 changes: 20 additions & 0 deletions man/plot_harborporpoise.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fff302b

Please sign in to comment.