-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
thermal_habitat_area_annual get function and plot function
- Loading branch information
1 parent
8222238
commit 513db43
Showing
6 changed files
with
9,097 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
||
|
Oops, something went wrong.