Skip to content

Commit

Permalink
Merge pull request #108 from NOAA-EDAB/dev
Browse files Browse the repository at this point in the history
updated ecodata data and plot functions
  • Loading branch information
sgaichas authored Jan 18, 2024
2 parents 87d431f + 3b6d39a commit e7a5810
Show file tree
Hide file tree
Showing 39 changed files with 72,181 additions and 3,221 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export(plot_blue_runner)
export(plot_bottom_temp)
export(plot_bottom_temp_comp)
export(plot_bottom_temp_glorys)
export(plot_bottom_temp_seasonal_gridded)
export(plot_calanus_stage)
export(plot_ch_bay_sal)
export(plot_ch_bay_temp)
Expand Down
6 changes: 4 additions & 2 deletions R/plot_bennet.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#' plot Bennet indicator
#' plot Bennett indicator
#'
#' Stacked bar charts of price and volume components of revenue by feeding guild.
#'
#' @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 plottype Character string. Which plot ("revenue", "??","???)
#'
#' @return ggplot object
#'
Expand All @@ -12,7 +13,8 @@
#'

plot_bennet <- function(shadedRegion = NULL,
report="MidAtlantic") {
report="MidAtlantic",
plottype="revenue") {

# generate plot setup list (same for all plot functions)
setup <- ecodata::plot_setup(shadedRegion = shadedRegion,
Expand Down
111 changes: 111 additions & 0 deletions R/plot_bottom_temp_seasonal_gridded.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#' plot bottom temperature seasonal gridded data
#'
#' plots bottom_temp_seasonal_gridded data set
#'
#' @param shadedRegion Numeric vector. Years denoting the shaded region of the plot (most recent 10), passed from plot function
#' @param report Character string. Which SOE report ("MidAtlantic", "NewEngland"), passed from plot function
#'
#'
#' @return ggplot object
#'
#' @export

plot_bottom_temp_seasonal_gridded <- function(shadedRegion = NULL,
report = "MidAtlantic") {


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

if (report == "MidAtlantic") {
filterEPUs <- c("MAB")

xmin = -77
xmax = -66
ymin = 35.5
ymax = 43
xlims <- c(xmin, xmax)
ylims <- c(ymin, ymax)


} else {
filterEPUs <- c("GB", "GOM")
# Set lat/lon window for maps
xmin = -73
xmax = -65
ymin = 39
ymax = 45
xlims <- c(xmin, xmax)
ylims <- c(ymin, ymax)
}


#EPU shapefile
ne_epu_sf <- ecodata::epu_sf |>
dplyr::filter(EPU %in% filterEPUs)


fix <- ecodata::bottom_temp_seasonal_gridded |>
dplyr::filter(Time == max(Time)) |>
dplyr::select(-Time) |>
dplyr::as_tibble() |>
dplyr::rename(Var = Season) |>
dplyr::mutate(Var = factor(Var, levels = c("winter","spring","summer","fall")))


p <- ggplot2::ggplot(data = fix)+
ggplot2::geom_tile(ggplot2::aes(x = Longitude, y = Latitude, fill = Value)) +
#ggplot2::coord_sf(xlim = xlims, ylim = ylims) +

#ggplot2::geom_sf(data = ecodata::coast, size = setup$map.lwd) +
#ggplot2::geom_sf(data = ne_epu_sf, fill = "transparent", size = setup$map.lwd) +
ggplot2::facet_wrap(Var~.)+
ecodata::theme_map() +
#ggplot2::scale_fill_viridis_c(option = 'A',name = 'Bottom \n Temp')+
ggplot2::ggtitle('Seasonal Mean Bottom Temperature')+
ggplot2::xlab("Longitude") +
ggplot2::ylab("Latitude") +
ggplot2::theme(panel.border = ggplot2::element_rect(colour = "black", fill=NA, linewidth=0.75),
legend.key = ggplot2::element_blank(),
axis.title = ggplot2::element_text(size = 11),
strip.background = ggplot2::element_blank(),
strip.text=ggplot2::element_text(hjust=0),
axis.text = ggplot2::element_text(size = 8),
axis.title.y = ggplot2::element_text(angle = 90))+
ecodata::theme_title() +
ecodata::theme_ts()


return(p)
}

attr(plot_bottom_temp_seasonal_gridded,"report") <- c("MidAtlantic","NewEngland")



# p <-
# ggplot2::ggplot() +
# ggplot2::geom_tile(data = sst, ggplot2::aes(x = Longitude, y = Latitude,fill = Value)) +
# ggplot2::geom_sf(data = ecodata::coast, size = setup$map.lwd) +
# ggplot2::geom_sf(data = ne_epu_sf, fill = "transparent", size = setup$map.lwd) +
# ggplot2::scale_fill_gradient2(name = "Temp.\nAnomaly (C)",
# low = scales::muted("blue"),
# mid = "white",
# high = scales::muted("red"),
# limits = c(-5,5),
# labels = c("<-5", "-2", "0", "2", ">5")) +
# ggplot2::coord_sf(xlim = xlims, ylim = ylims) +
# ggplot2::facet_wrap(Season~.) +
# ecodata::theme_map() +
# ggplot2::ggtitle("SST anomaly") +
# ggplot2::xlab("Longitude") +
# ggplot2::ylab("Latitude") +
# ggplot2::theme(panel.border = ggplot2::element_rect(colour = "black", fill=NA, size=0.75),
# legend.key = ggplot2::element_blank(),
# axis.title = ggplot2::element_text(size = 11),
# strip.background = ggplot2::element_blank(),
# strip.text=ggplot2::element_text(hjust=0),
# axis.text = ggplot2::element_text(size = 8),
# axis.title.y = ggplot2::element_text(angle = 90))+
#
# ecodata::theme_title()
2 changes: 1 addition & 1 deletion R/plot_ch_bay_sal.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ plot_ch_bay_sal <- function(shadedRegion = NULL,
ggplot2::geom_ribbon(ggplot2::aes(x = Time, ymin = minLTA, ymax = maxLTA), fill = "grey", alpha = 0.5)+

ggplot2::geom_line(ggplot2::aes(x = Time, y = YearLTA, color= "Long Term Average 2010-2020")) +
ggplot2::geom_line(ggplot2::aes(x = Time, y = Year, color = "Daily 2022")) +
ggplot2::geom_line(ggplot2::aes(x = Time, y = Year, color = "Daily (Current Year)")) +
ggplot2::ylab("Salinity") +
ggplot2::ggtitle("Chesapeake Bay Salinity") +
ggplot2::theme(legend.position = "bottom",
Expand Down
14 changes: 11 additions & 3 deletions R/plot_gsi.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
#'
#' @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 ("gsi","westgsi")
#' @return ggplot object
#'
#'
#' @export
#'

plot_gsi <- function(shadedRegion = NULL,
report="MidAtlantic") {
report="MidAtlantic",
varName = "gsi") {

# generate plot setup list (same for all plot functions)
setup <- ecodata::plot_setup(shadedRegion = shadedRegion,
Expand All @@ -26,12 +27,18 @@ plot_gsi <- function(shadedRegion = NULL,
filterEPUs <- c("GB", "GOM")
}

if (varName == "gsi") {
var <- "gulf stream index"
} else {
var <- "western gulf stream index"
}
# optional code to wrangle ecodata object prior to plotting
# e.g., calculate mean, max or other needed values to join below



fix <- ecodata::gsi |>
dplyr::filter(Var == var) |>
dplyr::mutate(Year = floor(Time)) |>
dplyr::group_by(Year) |>
dplyr::summarise(Value = mean(Value)) |>
Expand All @@ -50,7 +57,7 @@ plot_gsi <- function(shadedRegion = NULL,
ymin = -Inf, ymax = Inf) +
ggplot2::geom_point()+
ggplot2::geom_line()+
ggplot2::ggtitle("Gulf Stream Index")+
ggplot2::ggtitle(stringr::str_to_title(var))+
ggplot2::ylab("Anomaly")+
ggplot2::xlab(ggplot2::element_blank())+
ecodata::geom_gls()+
Expand All @@ -75,3 +82,4 @@ plot_gsi <- function(shadedRegion = NULL,


attr(plot_gsi,"report") <- c("MidAtlantic","NewEngland")
attr(plot_gsi,"varName") <- c("gsi","westgsi")
7 changes: 6 additions & 1 deletion R/plot_hms_landings.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ plot_hms_landings <- function(shadedRegion = NULL,

return(p)


}

attr(plot_hms_landings,"varName") <- c("Landings","Revenue")
attr(plot_hms_landings,"report") <- c("MidAtlantic","NewEngland")

# Paste commented original plot code chunk for reference
#Get data for plotting
# ## Apex pred
Expand Down Expand Up @@ -120,4 +126,3 @@ plot_hms_landings <- function(shadedRegion = NULL,
# p1
#

}
2 changes: 1 addition & 1 deletion R/plot_productivity_anomaly.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ plot_productivity_anomaly <- function(shadedRegion = NULL,
p <- plot_stackbarcpts_single(YEAR = bar_dat$Time,
var2bar = bar_dat$Var,
x = bar_dat$Value,
titl = paste0(EPU, "from survey data"),
titl = paste0(EPU, " from survey data"),
xlab = "",
ylab = "Small fish per large fish biomass (anomaly)",
height = 5.5,
Expand Down
12 changes: 9 additions & 3 deletions R/plot_thermal_habitiat_persistence.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' plot thermal habitat persistence
#'
#' plots thermal_habitat_persistence data set.
#' plots thermal_habitat_persistence data set. Current SOE Year only
#'
#' @param shadedRegion Numeric vector. Years denoting the shaded region of the plot (most recent 10)
#' @param report Character string. Which SOE report ("MidAtlantic", "NewEngland")
Expand All @@ -12,7 +12,8 @@
#'

plot_thermal_habitat_persistence <- function(shadedRegion = NULL,
report="MidAtlantic") {
report="MidAtlantic",
year = NULL) {

# generate plot setup list (same for all plot functions)
setup <- ecodata::plot_setup(shadedRegion = shadedRegion,
Expand All @@ -25,10 +26,15 @@ plot_thermal_habitat_persistence <- function(shadedRegion = NULL,
filterEPUs <- c("GB","GOM")
}

if (is.null(year)) {
# current SOE report year
Yr <- setup$shadedRegion[2]
}
# 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_persistence |>
dplyr::mutate(Var = paste0(Var,"\u00B0C"))
dplyr::mutate(Var = paste0(Var,"\u00B0C")) |>
dplyr::filter(Time == Yr)

# neus_map <- ggplot2::map_data('worldHires',region = 'USA')
legendTitle <- unique(fix$Units)
Expand Down
18 changes: 9 additions & 9 deletions R/plot_wind_occupancy.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,31 @@ plot_wind_occupancy <- function(shadedRegion = NULL,
ifelse(wind1$Trend == "neg",
"$\\searrow$",
" "))
wind2<-wind1 %>% dplyr::select(Area, Season, Species, trend)
wind2<-wind1 |> dplyr::select(Area, Season, Species, trend)
names<-c("Area", "Season", "Species", "trend")
bnew<-c("Area.1", "Season.1", "Species.1", "trend.1")
cnew<-c("Area.2", "Season.2", "Species.2", "trend.2")
dnew<-c("Area.3", "Season.3", "Species.3", "trend.3")
enew<-c("Area.4", "Season.4", "Species.4", "trend.4")
a<-wind2 %>% dplyr::filter(Area == "Existing-North")
b<-wind2 %>% dplyr::filter(Area == "Proposed-North") %>%
a<-wind2 |> dplyr::filter(Area == "Existing-North")
b<-wind2 |> dplyr::filter(Area == "Proposed-North") |>
dplyr::rename_at(dplyr::vars(names), ~ bnew)
c<-wind2 %>% dplyr::filter(Area == "Existing-Mid")%>%
c<-wind2 |> dplyr::filter(Area == "Existing-Mid")|>
dplyr::rename_at(dplyr::vars(names), ~ cnew)
d<-wind2 %>% dplyr::filter(Area == "Proposed-Mid")%>%
d<-wind2 |> dplyr::filter(Area == "Proposed-Mid")|>
dplyr::rename_at(dplyr::vars(names), ~ dnew)
e<-wind2 %>% dplyr::filter(Area == "Existing-South")%>%
e<-wind2 |> dplyr::filter(Area == "Existing-South")|>
dplyr::rename_at(dplyr::vars(names), ~ enew)
all<- a %>% cbind(b,c,d,e) %>%
all<- a |> cbind(b,c,d,e) |>
dplyr::select(2:4,7:8,11:12,15:16,19:20)

tab <- kableExtra::kable(all, escape = FALSE,
col.names = c("Season", "Species", "Trend", "Species", "Trend", "Species","Trend", "Species","Trend", "Species", "Trend"),
caption = "Species with highest probability of occupancy species each season and area, with observed trends",
booktabs = T) %>%
booktabs = T) |>
kableExtra::add_header_above(c(" " = 1, "Existing - North" = 2, "Proposed - North" = 2,
"Existing - Mid" = 2, "Proposed - Mid" = 2,
"Existing - South" = 2)) %>%
"Existing - South" = 2)) |>
kableExtra::kable_styling(latex_options = c("hold_position", "scale_down"))

return(tab)
Expand Down
Loading

0 comments on commit e7a5810

Please sign in to comment.