Skip to content

Commit

Permalink
thermal_habitat_area_annual get function and plot function
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaracappa1 committed Dec 23, 2024
1 parent 8222238 commit 513db43
Show file tree
Hide file tree
Showing 6 changed files with 9,097 additions and 1 deletion.
63 changes: 63 additions & 0 deletions R/plot_thermal_habitiat_area_annual.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#' plot thermal habitat area
#'
#' plots thermal_habitat_area data set.
#'
#' @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 EPU Character string. Which EPU for New England report ("GB", "GOM") Mid will always be MAB
#'
#' @return ggplot object
#'
#' @export

#'

plot_thermal_habitat_area_annual <- function(shadedRegion = NULL,
report="MidAtlantic",
EPU = "MAB") {

# 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 {
if (!(EPU %in% c("GB","GOM"))) {
stop("For NewEngland the epu must be either 'GB' or 'GOM'")
}
filterEPUs <- EPU
}

# optional code to wrangle ecodata object prior to plotting
# e.g., calculate mean, max or other needed values to join below


fix <- ecodata::thermal_habitat_area_annual |>
dplyr::filter(EPU == filterEPUs)

limits <- fix |>
dplyr::group_by(Var,Time) |>
dplyr::summarise(areaMinProportion = min(Value),
areaMaxProportion = max(Value),
.groups = "drop")

fix <- fix |>
dplyr::left_join(limits,by=c("Var","Time"))

p <- ggplot2::ggplot()+
# ggplot2::geom_line(data=fix, ggplot2::aes(x = temp.threshold, ymin = areaMinProportion, ymax = areaMaxProportion))+
ggplot2::geom_line(data=fix,ggplot2::aes(x = temp.threshold, y= Value,group = Time,color = Time),alpha = 0.7,size =1)+
ggplot2::scale_color_gradient(name = "Year",low = 'grey70',high ='blue2')+
ggplot2::geom_line(data=dplyr::filter(fix,Time == max(Time)),ggplot2::aes(x = temp.threshold, y= Value),color = 'black',alpha = 0.7,size =2)+
ggplot2::theme_bw()+
ggplot2::xlab('Temperature Threshold (\u00B0C)')+
ggplot2::ylab('Proportion of EPU Area above threshold') +
ggplot2::ggtitle(filterEPUs)+
ggplot2::theme(plot.title = ggplot2::element_text(hjust = 0.5))


return(p)

}
21 changes: 21 additions & 0 deletions data-raw/get_thermal_habitat_area_annual.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
### Thermal Habitat Area - Joe Caracappa

# library(dplyr)
# library(usethis)

get_thermal_habitat_area_annual <- function(save_clean = F){

thermal_habitat_area_annual<-readr::read_csv(here::here("data-raw/thermal_threshold_annual_area_SOE2025.csv"),
show_col_types = F) |>
dplyr::relocate(Time,EPU,Var,Value,Source)

if (save_clean){
usethis::use_data(thermal_habitat_area_annual, overwrite = T)
} else {
return(thermal_habitat_area_annual)
}
}
get_thermal_habitat_area_annual(save_clean = T)



Loading

0 comments on commit 513db43

Please sign in to comment.