Skip to content

Commit

Permalink
Merge pull request #223 from NOAA-EDAB/plot_fix_jc
Browse files Browse the repository at this point in the history
Plot adjustments: cold pool, bottom temp, bennet, and commercial_div
  • Loading branch information
andybeet authored Jan 31, 2025
2 parents 47f6027 + 7763c63 commit 8c8fe1c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 27 deletions.
12 changes: 6 additions & 6 deletions R/plot_bennet.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ plot_bennet <- function(shadedRegion = NULL,
ymin = -Inf, ymax = Inf)+
ggplot2::geom_bar(data = indicators, ggplot2::aes(x = Time, y = Value, fill = Guild), stat="identity")+
#ggplot2::scale_fill_manual(name = "Indicators", values = Guild) +
ggplot2::geom_line(data = indicators, ggplot2::aes(x = Time, y = component, color = "$"))+
ggplot2::geom_line(data = indicators, ggplot2::aes(x = Time, y = component, color = "$"), linewidth = 0.7)+
ggplot2::scale_x_continuous(breaks = seq(1980, 2020, by = 5), expand = c(0.01, 0.01)) +
ggplot2::facet_grid(EPU~Var, scales = "free")+
ggplot2::scale_colour_grey(name ="Component") +
ggplot2::ggtitle("Bennet Indicator")+
ggplot2::ggtitle(paste0("Bennet Indicator \n",EPU))+
ggplot2::labs(y=paste0("Million USD (", bennet_year, ")")) +

ggplot2::xlab(ggplot2::element_blank())+
Expand Down Expand Up @@ -114,9 +114,9 @@ plot_bennet <- function(shadedRegion = NULL,
ymin = -Inf, ymax = Inf)+
ggplot2::geom_bar(data = indicators, ggplot2::aes(x = Time, y = Value, fill = Var), stat="identity")+
ggplot2::scale_fill_manual(name = "Indicators", values = ind_fill) +
ggplot2::geom_line(data = revchange, ggplot2::aes(x = Time, y = Value, color = "$"))+
ggplot2::geom_line(data = revchange, ggplot2::aes(x = Time, y = Value, color = "$"), linewidth = 0.7)+
ggplot2::scale_colour_grey(name ="Revenue Change") +
ggplot2::ggtitle("Bennet Indicator")+
ggplot2::ggtitle(paste0("Bennet Indicator \n",EPU))+
ggplot2::labs(y=paste0("Million USD (", bennet_year, ")")) +
ggplot2::scale_x_continuous(breaks = seq(1980, 2020, by = 5), expand = c(0.01, 0.01)) +
#::scale_y_continuous(breaks = seq(y.lim[1], y.lim[2], by = 100),
Expand Down Expand Up @@ -157,9 +157,9 @@ plot_bennet <- function(shadedRegion = NULL,
ymin = -Inf, ymax = Inf)+
ggplot2::geom_bar(data = indicators, ggplot2::aes(x = Time, y = Value, fill = Var), stat="identity")+
ggplot2::scale_fill_manual(name = "Indicators", values = ind_fill) +
ggplot2::geom_line(data = revchange, ggplot2::aes(x = Time, y = Value, color = "$"))+
ggplot2::geom_line(data = revchange, ggplot2::aes(x = Time, y = Value, color = "$"), linewidth = 0.7)+
ggplot2::scale_colour_grey(name ="Revenue Change") +
ggplot2::ggtitle("Bennet Indicator")+
ggplot2::ggtitle(paste0("Bennet Indicator \n",EPU))+
ggplot2::labs(y=paste0("Million USD (", bennet_year, ")")) +
ggplot2::scale_x_continuous(breaks = seq(1980, 2015, by = 10), expand = c(0.01, 0.01)) +
#ggplot2::scale_y_continuous(breaks = seq(y.lim[1], y.lim[2], by = 100),
Expand Down
5 changes: 4 additions & 1 deletion R/plot_bottom_temp_model_anom.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#' @param varName Character string. Which variable ("seasonal", "annual")
#' @param EPU Character string. Which EPU for New England report ("GB", "GOM") Mid will always be MAB
#' @param n Numeric scalar. Number of years used (from most recent year) to estimate short term trend . Default = 0 (No trend calculated)
#' @param source character vector. Which source data should be plotted (e.g. 'GLORYS','MOM6')
#'
#' @return ggplot object
#'
Expand All @@ -16,6 +17,7 @@ plot_bottom_temp_model_anom <- function(shadedRegion=NULL,
report="MidAtlantic",
varName="seasonal",
EPU="MAB",
source = 'GLORYS',
n = 0) {

setup <- ecodata::plot_setup(shadedRegion = shadedRegion,
Expand All @@ -32,7 +34,7 @@ plot_bottom_temp_model_anom <- function(shadedRegion=NULL,


fix <- ecodata::bottom_temp_model_anom |>
dplyr::filter((Source == "GLORYS" & Time >= 1993) | (Source == "ROMS") | (Source == 'MOM6') ) |>
dplyr::filter(Source %in% source) |>
dplyr::filter(EPU %in% filterEPUs) |>
dplyr::mutate(Time = as.numeric(Time),
Var = stringr::str_to_title(stringr::str_extract(Var,"Winter|Spring|Summer|Fall|Annual"))) |>
Expand Down Expand Up @@ -109,3 +111,4 @@ plot_bottom_temp_model_anom <- function(shadedRegion=NULL,
attr(plot_bottom_temp_model_anom,"EPU") <- c("MAB","GB","GOM")
attr(plot_bottom_temp_model_anom,"report") <- c("MidAtlantic","NewEngland")
attr(plot_bottom_temp_model_anom, "varName") <- c("seasonal", "annual")
attr(plot_bottom_temp_model_anom, "source") <- c("GLORYS", "MOM6")
40 changes: 24 additions & 16 deletions R/plot_cold_pool.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@
#'
#' @param shadedRegion Numeric vector. Years denoting the shaded region of the plot (most recent 10)
#' @param report Character string. Which SOE report ("MidAtlantic" only, default)
#' @param varName Character string. Which plot (NULL, "cold_pool", "persistence","extent")
#' @param varName Character string. Which variable to plot (NULL, "cold_pool", "persistence","extent"). NULL plots all three.
#' @param n Numeric scalar. Number of years used (from most recent year) to estimate short term trend . Default = 0 (No trend calculated)
#'
#' @return ggplot object
#'
#'
#' @export
#'
#'

# removed temporarily from params documentation, add back later:
# @param source character vector. Which source data should be plotted (e.g. 'GLORYS','MOM6')


plot_cold_pool <- function(shadedRegion = NULL,
report="MidAtlantic",
varName = NULL,
#source = 'GLORYS',
n = 0) {

# generate plot setup list (same for all plot functions)
Expand All @@ -39,6 +45,7 @@ plot_cold_pool <- function(shadedRegion = NULL,

cpdup <- ecodata::cold_pool |>
dplyr::group_by(Time, Var, EPU) |>
#dplyr::filter(Source %in% source) |>
dplyr::mutate(duplicated = dplyr::n()>1) |>
dplyr::ungroup()

Expand Down Expand Up @@ -67,16 +74,16 @@ plot_cold_pool <- function(shadedRegion = NULL,
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_line(ggplot2::aes(x = Time, y = Value), size = setup$lwd) +
ggplot2::geom_point(ggplot2::aes(x = Time, y = Value, shape = Source), size = setup$pcex) +
ggplot2::geom_line(ggplot2::aes(x = Time, y = Value), size = setup$lwd) + #, color = Source
ggplot2::geom_point(ggplot2::aes(x = Time, y = Value, shape = Source), size = setup$pcex) + #color = Source
ggplot2::scale_shape_manual(values = c(16, 1))+
ggplot2::theme(legend.position = "none")+
# ggplot2::geom_ribbon(aes(x = Time, ymin = Lower, ymax = Upper), fill = "gray")+
ggplot2::geom_hline(ggplot2::aes(yintercept = 0))+
ecodata::geom_gls(ggplot2::aes(x = Time, y = Value))+
ecodata::geom_lm(n=n, ggplot2::aes(x = Time, y = Value))+
#ecodata::geom_lm(aes(x = Time, y = Value, group = Var))+
ggplot2::ylab(bquote("Cold Pool Index, " ~ (x^{-1}))) +
ggplot2::ylab(bquote("Cold Pool Index, (\u00B0C)" ~ (x^{-1}))) +
#ggplot2::scale_y_reverse()+
ggplot2::xlab("")+
ecodata::theme_ts()+
Expand All @@ -85,7 +92,8 @@ plot_cold_pool <- function(shadedRegion = NULL,
ggplot2::annotate("text", x = 1990, y = -2.5, label = "Warmer",size = 4, colour = "red")



#Cold Pool Extent units originall number of cells. Assuming 111km/deg to convert to area
#One cell is 9.25^2 or 85.5 km2

ei<- cpts |>
dplyr::filter(stringr::str_detect(Var, pattern = "extent")) |>
Expand All @@ -99,24 +107,24 @@ plot_cold_pool <- function(shadedRegion = NULL,
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_line(ggplot2::aes(x = Time, y = Value), size = setup$lwd) +
ggplot2::geom_point(ggplot2::aes(x = Time, y = Value, shape = Source), size = setup$pcex) +
ggplot2::geom_line(ggplot2::aes(x = Time, y = Value*85.5), size = setup$lwd) + #, color = Source
ggplot2::geom_point(ggplot2::aes(x = Time, y = Value*85.5, shape = Source), size = setup$pcex) + #color = Source
ggplot2::scale_shape_manual(values = c(16, 1))+
ggplot2::theme(legend.position = "none")+
ggplot2::geom_hline(ggplot2::aes(yintercept = 0))+
ecodata::geom_gls(ggplot2::aes(x = Time, y = Value))+
ecodata::geom_lm(n=n, ggplot2::aes(x = Time, y = Value))+
ecodata::geom_gls(ggplot2::aes(x = Time, y = Value*85.5))+
ecodata::geom_lm(n=n, ggplot2::aes(x = Time, y = Value*85.5))+
#ecodata::geom_lm(aes(x = Time, y = Value, group = Var))+
ggplot2::ylab("Spatial Extent Index") +
ggplot2::ylab(bquote("Spatial Extent Index, " ~ (km^{2}))) +
ggplot2::xlab("")+
ecodata::theme_ts()+
ecodata::theme_title()+
# ggplot2::annotate("segment", x = 2025, xend = 2025, y = 0.05, yend = 50,
# colour = "blue", size = 0.70, arrow = arrow())+
# ggplot2::annotate("segment", x = 2025, xend = 2025, y = -0.05, yend = -250,
# colour = "red", size = 0.70, arrow = arrow())+
ggplot2::annotate("text", x = 1990, y = 125, label = "Larger",size = 4, colour = "blue")+
ggplot2::annotate("text", x = 1990, y = -350, label = "Smaller",size = 4, colour = "red")
ggplot2::annotate("text", x = 1990, y = Inf,vjust = 1.5, label = "Larger",size = 4, colour = "blue")+
ggplot2::annotate("text", x = 1990, y = -Inf,vjust = -1.5, label = "Smaller",size = 4, colour = "red")


pi<- cpts |>
Expand All @@ -131,15 +139,15 @@ plot_cold_pool <- function(shadedRegion = NULL,
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_line(ggplot2::aes(x = Time, y = Value), size = setup$lwd) +
ggplot2::geom_point(ggplot2::aes(x = Time, y = Value, shape = Source), size = setup$pcex) +
ggplot2::geom_line(ggplot2::aes(x = Time, y = Value), size = setup$lwd) + #, color = Source
ggplot2::geom_point(ggplot2::aes(x = Time, y = Value, shape = Source), size = setup$pcex) + #color = Source
ggplot2::scale_shape_manual(values = c(16, 1))+
ggplot2::theme(legend.position = "none")+
ggplot2::geom_hline(ggplot2::aes(yintercept = 0))+
ecodata::geom_gls(ggplot2::aes(x = Time, y = Value))+
ecodata::geom_lm(n=n, ggplot2::aes(x = Time, y = Value))+
#ecodata::geom_lm(aes(x = Time, y = Value, group = Var))+
ggplot2::ylab("Persistence Index") +
ggplot2::ylab("Persistence Index (months)") +
ggplot2::xlab("")+
ecodata::theme_ts()+
ecodata::theme_title()+
Expand Down Expand Up @@ -169,7 +177,7 @@ plot_cold_pool <- function(shadedRegion = NULL,

attr(plot_cold_pool,"report") <- c("MidAtlantic","NewEngland")
attr(plot_cold_pool,"varName") <- c("cold_pool", "persistence","extent")

#attr(plot_cold_pool, "source") <- c("GLORYS", "MOM6")


# Paste commented original plot code chunk for reference
Expand Down
6 changes: 3 additions & 3 deletions R/plot_commercial_div.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ plot_commercial_div <- function(shadedRegion = NULL,
expression("Effective Shannon"))

if(varName=="Fleet count"){
ylim_fc <- c(min(comm_div[comm_div$Var == "Fleet count",]$Value, na.rm = TRUE) - 10,
max(comm_div[comm_div$Var == "Fleet count",]$Value, na.rm = TRUE) + 10 )
ylim_fc <- c(min(comm_div[comm_div$Var == "Fleet count" & comm_div$EPU == setup$region_abbr ,]$Value, na.rm = TRUE) *0.95,
max(comm_div[comm_div$Var == "Fleet count"& comm_div$EPU == setup$region_abbr,]$Value, na.rm = TRUE) *1.05 )
}else if(varName=="Fleet diversity in revenue"){
ylim_fc <- c(0, max(comm_div[comm_div$Var == "Fleet diversity in revenue",]$Value) + 3 )
ylim_fc <- c(0, max(comm_div[comm_div$Var == "Fleet diversity in revenue" & comm_div$EPU == setup$region_abbr,]$Value) *1.1 )
}else{
ylim_fc <- c(NA, NA)
}
Expand Down
3 changes: 3 additions & 0 deletions man/plot_bottom_temp_model_anom.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/plot_cold_pool.Rd

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

0 comments on commit 8c8fe1c

Please sign in to comment.