Skip to content

Commit

Permalink
add plot_hms_landings
Browse files Browse the repository at this point in the history
  • Loading branch information
sgaichas committed Dec 13, 2023
1 parent 9584d57 commit bc0b929
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export(plot_heatwave)
export(plot_heatwave_peak_date)
export(plot_heatwave_year)
export(plot_hms_cpue)
export(plot_hms_landings)
export(plot_ichthyo_diversity)
export(plot_long_term_sst)
export(plot_mab_inshore_survey)
Expand Down
114 changes: 114 additions & 0 deletions R/plot_hms_landings.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#' plot hms_landings
#'
#' Plot time series of Highly Migratory Species (HMS) commercial landings.
#'
#' @param shadedRegion Numeric vector. Years denoting the shaded region of the plot (most recent 10)
#' @param report Character string. Which SOE report ("MidAtlantic", "NewEngland").
#' HMS landings are by Mid Atlantic or New England, not EPU
#'
#' @return ggplot object
#'
#'
#' @export
#'

plot_hms_landings <- 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("NE")
}

# optional code to wrangle ecodata object prior to plotting
# e.g., calculate mean, max or other needed values to join below
apex<-ecodata::hms_landings |>
dplyr::filter(stringr::str_detect(Var, "Landings")) |>
tidyr::separate(Var, c("Var", "trash"), sep = "_") |>
dplyr::filter(EPU %in% filterEPUs) |>
dplyr::group_by(Var) |>
dplyr::mutate(hline = mean(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 <- apex |>
ggplot2::ggplot(ggplot2::aes(x = Time, y = Value, color = Var)) +
ggplot2::geom_line(size = setup$lwd) +
ggplot2::geom_point(size = setup$pcex) +
ggplot2::geom_hline(ggplot2::aes(yintercept = hline,
color = Var,
size = Var),
size = setup$hline.size,
alpha = setup$hline.alpha,
linetype = setup$hline.lty)+
ecodata::theme_facet() +
ggplot2::theme(strip.text=ggplot2::element_text(hjust=0),
legend.position = "bottom",
legend.direction = "horizontal",
legend.title = ggplot2::element_blank())+
ggplot2::ylab(expression("Landings (metric tons)")) +
ggplot2::xlab("Time")+
ggplot2::ggtitle(paste("HMS", setup$region, "Commercial Landings"))+
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(p)

# Paste commented original plot code chunk for reference
#Get data for plotting
# ## Apex pred
# apex<-ecodata::hms_landings %>%
# dplyr::filter(stringr::str_detect(Var, "Landings")) %>%
# #dplyr::mutate(Value = as.numeric(Value)) %>%
# separate(Var, c("Var", "trash"), sep = "_") #%>%
# #dplyr::filter(!Var == "Smoothhound Sharks")
#
# ##Plot
# p1<-apex %>%
# dplyr::filter(EPU == "NE") %>%
# dplyr::group_by(Var) %>%
# dplyr::mutate(hline = mean(Value)) %>%
#
# ggplot2::ggplot(aes(x = Time, y = Value, color = Var)) +
# ggplot2::annotate("rect", fill = shade.fill, alpha = shade.alpha,
# xmin = x.shade.min , xmax = x.shade.max,
# ymin = -Inf, ymax = Inf) +
# ggplot2::geom_line(size = lwd) +
# ggplot2::geom_point(size = pcex) +
# # ggplot2::geom_hline(aes(yintercept = hline,
# # color = Var,
# # size = Var),
# # size = hline.size,
# # alpha = hline.alpha,
# # linetype = hline.lty)+
# ecodata::theme_facet() +
# ggplot2::theme(strip.text=element_text(hjust=0),
# legend.position = "bottom",
# legend.direction = "horizontal",
# legend.title = element_blank())+
# ggplot2::ylab("Landings (metric tons)")+
# ggplot2::ggtitle("HMS Commercial Landings")
# ggplot2::xlab(element_blank())+
# ecodata::theme_title()
#
# p1
#

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

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

0 comments on commit bc0b929

Please sign in to comment.