Skip to content

Commit

Permalink
added plot_trans_dates to replace
Browse files Browse the repository at this point in the history
- plot_sst_transition_dates
- plot_sst_tranition_length
  • Loading branch information
andybeet committed Dec 5, 2023
1 parent 8dfbca7 commit 0f70448
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 163 deletions.
3 changes: 1 addition & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export(plot_seasonal_bt_anomaly_gridded)
export(plot_seasonal_oisst_anom)
export(plot_seasonal_sst_anomaly_gridded)
export(plot_setup)
export(plot_sst_transition_dates)
export(plot_sst_transition_dates_length)
export(plot_trans_dates)
export(plot_zoo_diversity)
export(plot_zoo_regime)
export(theme_facet)
Expand Down
2 changes: 1 addition & 1 deletion R/plot_habitat_diversity.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#'
#' @param shadedRegion Numeric vector. Years denoting the shaded region of the plot (most recent 10)
#' @param report Character string. Which SOE report ("MidAtlantic", "NewEngland")
#' @param Var Character string. Which Variable to plot ("Diversity","Richness")
#' @param varName Character string. Which Variable to plot ("Diversity","Richness")
#'
#' @return ggplot object
#'
Expand Down
6 changes: 5 additions & 1 deletion R/plot_setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#'
#' @export
#'
plot_setup <- function(shadedRegion=shadedRegion,
plot_setup <- function(shadedRegion = shadedRegion,
report = report){

#library(sf) # now needed in function for filter to work on sf object? https://github.com/r-spatial/sf/issues/1381
Expand Down Expand Up @@ -59,6 +59,10 @@ plot_setup <- function(shadedRegion=shadedRegion,
x.shade.min <- shadedRegion[1]
x.shade.max <- shadedRegion[2]

## Additional parameters for 4 panel maps eg. plot_seasonal_sst_anomaly_gridded
###################################################
###################################################

#Define constants for figure plot
series.col <- c("indianred","black")

Expand Down
43 changes: 0 additions & 43 deletions R/plot_sst_transition_dates.R

This file was deleted.

56 changes: 0 additions & 56 deletions R/plot_sst_transition_dates_length.R

This file was deleted.

90 changes: 90 additions & 0 deletions R/plot_trans_dates.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#' plot SST transition dates and timing
#'
#' uses ecodata::trans_dates
#'
#' @param shadedRegion Numeric vector. Years denoting the shaded region of the plot (most recent 10)
#' @param report Character string. Which SOE report ("MidAtlantic", "NewEngland")
#' @param varName Character string. Which Variable to plot ("timing","length")
#'
#' @return ggplot object
#'
#' @export

plot_trans_dates <- function(shadedRegion = shadedRegion,
report="MidAtlantic",
varName = "timing") {


setup <- ecodata::plot_setup(shadedRegion = shadedRegion,
report=report)

if (report == "MidAtlantic") {
filterEPUs <- c("MAB")
} else {
filterEPUs <- c("GB", "GOM")
}

if (varName == "timing") {

fix <- ecodata::trans_dates |>
dplyr::filter(EPU %in% filterEPUs,
Var %in% c("falltrans", "sprtrans","maxday"),
!Value == "NA",
!Var == "NA",
!Time == "NA") |>
dplyr::mutate(Var = dplyr::recode(Var, "falltrans"="Fall",
"sprtrans" = "Spring",
"maxday" = "Max"))

p <- fix |>

ggplot2::ggplot(ggplot2::aes(x= Time, y = Value, color = Var)) +
ggplot2::annotate("rect", fill = setup$shade.fill, alpha = setup$shade.alpha,
xmin = setup$x.shade.min , xmax = setup$x.shade.max,
ymin = -Inf, ymax = Inf) +
ggplot2::geom_point() +
ggplot2::geom_line() +
ecodata::geom_gls() +
# ggplot2::theme(strip.text=ggplot2::element_text(hjust=0),
# plot.title = ggplot2::element_text(size = 12)) +
ecodata::theme_title("") +
ggplot2::ylab("Day of Year") +
ggplot2::facet_wrap(.~EPU) +
ecodata::theme_facet() +
ggplot2::xlab(ggplot2::element_blank()) +
ggplot2::ggtitle(paste0(report,": SST transition dates"))

} else if (varName == "length") {
fix <- ecodata::trans_dates |>
dplyr::filter(EPU %in% filterEPUs,
Var == "sumlen",
!Value == "NA")
p <- fix |>
#dplyr::filter(Var %in% season) %>%
ggplot2::ggplot(ggplot2::aes(x= Time, y = Value))+
ggplot2::annotate("rect", fill = setup$shade.fill, alpha = setup$shade.alpha,
xmin = setup$x.shade.min , xmax = setup$x.shade.max,
ymin = -Inf, ymax = Inf) +
ggplot2::geom_point()+
ggplot2::geom_line()+
ecodata::geom_gls() +
# ggplot2::theme(strip.text=ggplot2::element_text(hjust=0),
# plot.title = ggplot2::element_text(size = 12))+
ecodata::theme_title()+
ggplot2::ylab("Number of Days")+
ggplot2::ggtitle(paste0(report,": Number of days between spring and fall transition dates")) +
#ggplot2::xlab(ggplot2::element_blank())+
ecodata::theme_ts()+
ggplot2::facet_wrap(.~EPU)+
ecodata::theme_facet()





} else {
stop("Transition date `timing` or `length` allowed")
}

return(p)
}
2 changes: 1 addition & 1 deletion man/plot_habitat_diversity.Rd

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

19 changes: 0 additions & 19 deletions man/plot_sst_transition_dates.Rd

This file was deleted.

40 changes: 0 additions & 40 deletions man/plot_sst_transition_dates_length.Rd

This file was deleted.

25 changes: 25 additions & 0 deletions man/plot_trans_dates.Rd

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

0 comments on commit 0f70448

Please sign in to comment.