Skip to content

Commit

Permalink
added plot_habs
Browse files Browse the repository at this point in the history
- PSP
- Alexandrium
  • Loading branch information
andybeet committed Dec 1, 2023
1 parent d86b5c6 commit 4a7b4db
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 10 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
export(geom_gls)
export(geom_lm)
export(geom_regime)
export(plot_HMS_species_distribution)
export(plot_SAV)
export(plot_bottom_temp_anomaly_glorys)
export(plot_bottom_temp_anomaly_space)
export(plot_bottom_temp_anomaly_survey)
Expand All @@ -11,6 +13,7 @@ export(plot_forage_anomaly)
export(plot_forage_index)
export(plot_function_template)
export(plot_habitat_diversity)
export(plot_habs)
export(plot_setup)
export(plot_sst)
export(plot_sst_anomaly)
Expand Down
16 changes: 8 additions & 8 deletions R/plot_habitat_diversity.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#'

plot_habitat_diversity <- function(shadedRegion = shadedRegion,
report="MidAtlantic",Var = "Diversity") {
report="MidAtlantic",varName = "Diversity") {

# generate plot setup list (same for all plot functions)
setup <- ecodata::plot_setup(shadedRegion = shadedRegion,
Expand All @@ -30,10 +30,10 @@ plot_habitat_diversity <- function(shadedRegion = shadedRegion,

# optional code to wrangle ecodata object prior to plotting
# e.g., calculate mean, max or other needed values to join below
if (Var == "Diversity") {
varName <- "Shannon"
if (varName == "Diversity") {
varNames <- "Shannon"
fix<- ecodata::habitat_diversity |>
dplyr::filter(Var == varName,
dplyr::filter(Var == varNames,
EPU %in% filterEPUs) |>
dplyr::group_by(EPU) |>
dplyr::mutate(mean = as.numeric(Value),
Expand All @@ -46,7 +46,7 @@ plot_habitat_diversity <- function(shadedRegion = shadedRegion,
# xmin = setup$x.shade.min , xmax = setup$x.shade.max
#
p <- ecodata::habitat_diversity |>
dplyr::filter(grepl(varName,Var)) |>
dplyr::filter(grepl(varNames,Var)) |>
dplyr::group_by(EPU) |>
dplyr::mutate(mean = as.numeric(Value),
Time = as.numeric(Time),
Expand All @@ -69,9 +69,9 @@ plot_habitat_diversity <- function(shadedRegion = shadedRegion,
ecodata::theme_title()

} else { # Richness
varName <- "Richness"
varNames <- "Richness"
fix<- ecodata::habitat_diversity |>
dplyr::filter(grepl(varName,Var),
dplyr::filter(grepl(varNames,Var),
EPU %in% filterEPUs) |>
tidyr::separate(Var, into = c("Var", "Richness"),sep = "-") |>
tidyr::pivot_wider(values_from = "Value", names_from = "Var") |>
Expand All @@ -88,7 +88,7 @@ plot_habitat_diversity <- function(shadedRegion = shadedRegion,
# xmin = setup$x.shade.min , xmax = setup$x.shade.max
#
p <- ecodata::habitat_diversity |>
dplyr::filter(grepl(varName,Var)) |>
dplyr::filter(grepl(varNames,Var)) |>
tidyr::separate(Var, into = c("Var", "Richness"),sep = "-") |>
tidyr::pivot_wider(values_from = "Value", names_from = "Var") |>
dplyr::group_by(EPU) |>
Expand Down
67 changes: 67 additions & 0 deletions R/plot_habs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#' plot harmful algal bloom
#'
#' Plots alexandrium counts, PSP
#'
#' @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 ("Alexandrium", "PSP")
#'
#' @return ggplot object
#'
#'
#' @export
#'

plot_habs <- function(shadedRegion = shadedRegion,
report="MidAtlantic",
varName = "Alexandrium") {

# 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","NE")
}

if (varName == "PSP"){
plotTitle <- "Percent PSP Samples in Blue Mussels"
plotylab <- "Percentage of samples that exceed the threshold"
plotLegend <- "State"
} else if(varName == "Alexandrium") {
plotTitle <- "Gulf of Maine Alexandrium Cyst Abundance"
plotylab <- expression("Cyst Abundance (10"^6*"Cells)")
plotLegend <- "Region"

}

# 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::habs |>
dplyr::filter(Source == varName,
EPU %in% filterEPUs) |>
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::theme_ts()+
ggplot2::scale_color_discrete(name = plotLegend)+
ecodata::theme_title()+
ggplot2::ylab(plotylab)+
ggplot2::xlab(ggplot2::element_blank())+
ggplot2::ggtitle(plotTitle)+
ecodata::theme_facet()


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.

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

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

2 changes: 1 addition & 1 deletion man/theme_map.Rd

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

0 comments on commit 4a7b4db

Please sign in to comment.