diff --git a/R/plot_abc_acl.R b/R/plot_abc_acl.R index cbe1052e..bf0e0ec5 100644 --- a/R/plot_abc_acl.R +++ b/R/plot_abc_acl.R @@ -13,13 +13,13 @@ #' @export #' -plot_abc_acl <- function(shadedRegion = NULL, - report="MidAtlantic", - plottype = "Stacked") { - +plot_abc_acl <- function( + shadedRegion = NULL, + report = "MidAtlantic", + plottype = "Stacked" +) { # generate plot setup list (same for all plot functions) - setup <- ecodata::plot_setup(shadedRegion = shadedRegion, - report=report) + setup <- ecodata::plot_setup(shadedRegion = shadedRegion, report = report) # which report? this may be bypassed for some figures if (report == "MidAtlantic") { @@ -38,69 +38,105 @@ plot_abc_acl <- function(shadedRegion = NULL, # splitting code by report for now if (report == "MidAtlantic") { - ABCs <- ecodata::abc_acl |> dplyr::filter(EPU == filterEPUs) |> tidyr::separate(col = Var, into = c("Fishery", "Var"), sep = "_") |> dplyr::filter(Var == "Quota") |> - dplyr::mutate(Fishery = gsub("Commercial", "C", Fishery), - Fishery = gsub("Recreational", "R", Fishery)) |> + dplyr::mutate( + Fishery = gsub("Commercial", "C", Fishery), + Fishery = gsub("Recreational", "R", Fishery) + ) |> dplyr::group_by(Fishery, Time) |> - dplyr::summarise(Value = sum(Value), - .groups="drop") + dplyr::summarise(Value = sum(Value), .groups = "drop") CatchABC <- ecodata::abc_acl |> - unique()|> + unique() |> dplyr::filter(EPU == filterEPUs) |> tidyr::separate(col = Var, into = c("Fishery", "Var"), sep = "_") |> - tidyr::pivot_wider(names_from = Var, values_from = Value) |> + tidyr::pivot_wider(names_from = Var, values_from = Value) |> #tidyr::separate(Catch, into = c("Catch", "X"), sep = ",") %>% - dplyr::mutate(Catch = as.numeric(stringr::str_extract(Catch, pattern = "\\d+")), - Quota = as.numeric(stringr::str_extract(Quota, pattern = "\\d+")), - Value = Catch/Quota#, - #Time = as.character(Time) + dplyr::mutate( + Catch = as.numeric(stringr::str_extract(Catch, pattern = "\\d+")), + Quota = as.numeric(stringr::str_extract(Quota, pattern = "\\d+")), + Value = Catch / Quota #, + #Time = as.character(Time) ) |> dplyr::filter(!is.na(Value)) meanCatchABC <- CatchABC |> dplyr::group_by(Time) |> - dplyr::summarise(val = mean(Value), - .groups="drop") |> + dplyr::summarise(val = mean(Value), .groups = "drop") |> dplyr::ungroup() |> dplyr::mutate(Time = as.numeric(Time)) - } if (report == "NewEngland") { - ABCs <- ecodata::abc_acl |> dplyr::filter(EPU == filterEPUs) |> - tidyr::separate(col = Var, into = c("FMP", "Fishery", "Var"), sep = "_") |> + tidyr::separate( + col = Var, + into = c("FMP", "Fishery", "Var"), + sep = "_" + ) |> dplyr::filter(Var == "ABC") |> dplyr::group_by(Fishery, Time) |> - dplyr::summarise(Value = sum(Value), - .groups="drop") + dplyr::summarise(Value = sum(Value), .groups = "drop") |> + subset(!is.na(Value)) |> + dplyr::mutate(Fishery = dplyr::recode(Fishery, + "Acadian redfish - Gulf of Maine / Georges Bank" = "Acadian redfish", + "American plaice - Gulf of Maine / Georges Bank" = "American plaice", + "Atlantic cod - Georges Bank" = "Atlantic cod GB", + "Atlantic cod - Gulf of Maine" = "Atlantic cod GOM", + "Atlantic halibut - Northwestern Atlantic Coast" = "Atlantic halibut", + "Atlantic wolffish - Gulf of Maine / Georges Bank" = "Atlantic wolffish", + "Goosefish - Gulf of Maine / Northern Georges Bank" = "Goosefish GOM/N.GB", + "Goosefish - Southern Georges Bank / Mid-Atlantic" = "Goosefish S.GB/MAB", + "Haddock - Georges Bank" = "Haddock GB", + "Haddock - Gulf of Maine" = "Haddock GOM", + "Ocean pout - Northwestern Atlantic Coast" = "Ocean pout", + "Offshore hake - Northwestern Atlantic Coast" = "Offshore hake", + "Offshore hake - Northwestern Atlantic Coast | Asmt & Status" = "Offshore hake", + "Pollock - Gulf of Maine / Georges Bank" = "Pollock", + "Red hake - Gulf of Maine / Northern Georges Bank" = "Red hake GOM/N.GB", + "Red hake - Southern Georges Bank / Mid-Atlantic" = "Red hake S.GB/MAB", + "Silver hake - Gulf of Maine / Northern Georges Bank" = "Silver hake GOM/N.GB", + "Silver hake - Southern Georges Bank / Mid-Atlantic" = "Silver hake S.GB/MAB", + "Silver hake - Southern Georges Bank / Mid-Atlantic | Asmt & Status" = "Silver hake S.GB/MAB", + "White hake - Gulf of Maine / Georges Bank" = "White hake", + "Windowpane - Gulf of Maine / Georges Bank" = "Windowpane GOM/GB", + "Windowpane - Southern New England / Mid-Atlantic" = "Windowpane SNE/MAB", + "Winter flounder - Georges Bank" = "Winter flounder GB", + "Winter flounder - Gulf of Maine" = "Winter flounder GOM", + "Winter flounder - Southern New England / Mid-Atlantic" = "Winter flounder SNE/MAB", + "Witch flounder - Northwestern Atlantic Coast" = "Witch flounder", + "Yellowtail flounder - Cape Cod / Gulf of Maine" = "Yellowtail flounder CC/GOM", + "Yellowtail flounder - Georges Bank" = "Yellowtail flounder GB", + "Yellowtail flounder - Southern New England / Mid-Atlantic" = "Yellowtail flounder SNE/MAB" + )) CatchABC <- ecodata::abc_acl |> - unique()|> + unique() |> dplyr::filter(EPU == filterEPUs) |> - tidyr::separate(col = Var, into = c("FMP", "Fishery", "Var"), sep = "_") |> - tidyr::pivot_wider(names_from = Var, values_from = Value) |> + tidyr::separate( + col = Var, + into = c("FMP", "Fishery", "Var"), + sep = "_" + ) |> + tidyr::pivot_wider(names_from = Var, values_from = Value) |> #tidyr::separate(Catch, into = c("Catch", "X"), sep = ",") %>% - dplyr::mutate(Catch = as.numeric(stringr::str_extract(Catch, pattern = "\\d+")), - Quota = as.numeric(stringr::str_extract(ABC, pattern = "\\d+")), - Value = Catch/ABC#, - #Time = as.character(Time) - ) |> + dplyr::mutate( + Catch = as.numeric(stringr::str_extract(Catch, pattern = "\\d+")), + Quota = as.numeric(stringr::str_extract(ABC, pattern = "\\d+")), + Value = Catch / ABC #, + #Time = as.character(Time) + ) |> dplyr::filter(!is.na(Value)) meanCatchABC <- CatchABC |> dplyr::group_by(Time) |> - dplyr::summarise(val = mean(Value), - .groups="drop") |> + dplyr::summarise(val = mean(Value), .groups = "drop") |> dplyr::ungroup() |> dplyr::mutate(Time = as.numeric(Time)) - } # code for generating plot object p @@ -109,108 +145,103 @@ plot_abc_acl <- function(shadedRegion = NULL, # xmin = setup$x.shade.min , xmax = setup$x.shade.max # if (plottype == "Stacked") { + # p <- ABCs |> + # ggplot2::ggplot() + + # ggplot2::geom_bar( + # ggplot2::aes(y = Value, x = Time, fill = Fishery), + # stat = "identity", + # position = "stack", + # color = "black" + # ) + + # ggplot2::scale_x_continuous(breaks = scales::pretty_breaks()) + + # ggplot2::ggtitle("ABC or ACL for Managed Species") + + # ggplot2::theme( + # legend.text = ggplot2::element_text(size = 8), + # legend.key.height = ggplot2::unit(2, "mm") + # ) + + # ggplot2::ylab("ABC or ACL, metric tons") + + # ggplot2::xlab(ggplot2::element_blank()) + + # ecodata::theme_ts() + + # ggplot2::guides(fill = ggplot2::guide_legend(ncol = 1)) + + # ecodata::theme_title() + + species <- ABCs |> + dplyr::mutate(Fishery = stringr::str_wrap(Fishery, width = 10)) |> + ggplot2::ggplot() + + ggplot2::geom_bar( + ggplot2::aes(y = Value, x = Time, fill = Fishery), + stat = "identity", + position = "stack" + ) + + ggplot2::facet_wrap(~Fishery, ncol = 4, strip.position = "right") + + ggplot2::scale_x_continuous(breaks = scales::pretty_breaks(n = 3)) + + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(n = 3)) + + ggplot2::ggtitle("ABC or ACL for Managed Species") + + ggplot2::theme( + legend.text = ggplot2::element_text(size = 8), + legend.key.height = ggplot2::unit(2, "mm"), + legend.position = "none" + ) + + ggplot2::ylab("ABC or ACL, metric tons") + + ggplot2::xlab(ggplot2::element_blank()) + + ecodata::theme_ts() + + # ggplot2::guides(fill = ggplot2::guide_legend(ncol = 1)) + + ecodata::theme_title() - p <- ABCs |> - ggplot2::ggplot()+ - ggplot2::geom_bar(ggplot2::aes( y = Value, x = Time, fill = Fishery), stat="identity", position = "stack" )+ - ggplot2::scale_x_continuous(breaks= scales::pretty_breaks()) + - ggplot2::ggtitle("ABC or ACL for Managed Species")+ - ggplot2::theme(legend.text = ggplot2::element_text(size = 8), - legend.key.height = ggplot2::unit(2, "mm"))+ - ggplot2::ylab("ABC or ACL, metric tons")+ - ggplot2::xlab(ggplot2::element_blank())+ - ecodata::theme_ts()+ - ggplot2::guides(fill=ggplot2::guide_legend(ncol=1))+ + total <- ABCs |> + dplyr::group_by(Time) |> + dplyr::summarise(Total = sum(Value)) |> + ggplot2::ggplot(ggplot2::aes(x = Time, y = Total)) + + ggplot2::geom_bar( + stat = "identity", + fill = "lightblue" + ) + + ggplot2::ggtitle("Combined ABC or ACL for Managed Species") + + ggplot2::ylab("ABC or ACL, metric tons") + + ggplot2::xlab(ggplot2::element_blank()) + + ggplot2::scale_x_continuous(breaks = scales::pretty_breaks()) + + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(n = 3)) + + ecodata::theme_ts() + ecodata::theme_title() - return(p) + p <- ggpubr::ggarrange( + total, + species, + ncol = 1, + nrow = 2, + heights = c(1, 3) + ) + return(p) } if (plottype == "Catch") { - p <- CatchABC |> - ggplot2::ggplot()+ + ggplot2::ggplot() + #geom_boxplot()+ - ggplot2::geom_point(ggplot2::aes(x = Time, y = Value))+ - ggplot2::geom_point(data = meanCatchABC, ggplot2::aes(x = Time, y = val), color = "red")+ - ggplot2::geom_line(data = meanCatchABC, ggplot2::aes(x = Time, y = val), color = "red")+ - ggplot2::geom_hline(yintercept = 1, linetype='dashed', col = 'gray')+ - ggplot2::scale_x_continuous(breaks= scales::pretty_breaks()) + - ggplot2::ggtitle("Catch per ABC or ACL")+ - ggplot2::ylab(expression("Catch / ABC or ACL"))+ - ggplot2::theme(legend.title = ggplot2::element_blank())+ - ggplot2::xlab(ggplot2::element_blank())+ - ecodata::theme_ts()+ + ggplot2::geom_point(ggplot2::aes(x = Time, y = Value)) + + ggplot2::geom_point( + data = meanCatchABC, + ggplot2::aes(x = Time, y = val), + color = "red" + ) + + ggplot2::geom_line( + data = meanCatchABC, + ggplot2::aes(x = Time, y = val), + color = "red" + ) + + ggplot2::geom_hline(yintercept = 1, linetype = 'dashed', col = 'gray') + + ggplot2::scale_x_continuous(breaks = scales::pretty_breaks()) + + ggplot2::ggtitle("Catch per ABC or ACL") + + ggplot2::ylab(expression("Catch / ABC or ACL")) + + ggplot2::theme(legend.title = ggplot2::element_blank()) + + ggplot2::xlab(ggplot2::element_blank()) + + ecodata::theme_ts() + ecodata::theme_title() return(p) } - } -attr(plot_abc_acl,"report") <- c("MidAtlantic","NewEngland") -attr(plot_abc_acl,"plottype") <- c("Stacked","Catch") - - -# Paste commented original plot code chunk for reference -# -# Stacked -# mean<- ecodata::abc_acl %>% -# ecodata::abc_acl |> -# dplyr::filter(EPU == "MAB") |> -# tidyr::separate(col = Var, into = c("Fishery", "Var"), sep = "_") |> -# dplyr::filter(Var == "Quota") |> -# dplyr::mutate(Fishery = gsub("Commercial", "C", Fishery), -# Fishery = gsub("Recreational", "R", Fishery)) |> -# dplyr::group_by(Fishery, Time) |> -# dplyr::summarise(Value = sum(Value)) |> -# ggplot2::ggplot()+ -# ggplot2::geom_bar(ggplot2::aes( y = Value, x = Time, fill = Fishery), stat="identity", position = "stack" )+ -# ggplot2::ggtitle("ABC or ACL for MAFMC Managed Species")+ -# ggplot2::theme(legend.text = ggplot2::element_text(size = 8), -# legend.key.height = ggplot2::unit(2, "mm"))+ -# ggplot2::ylab("ABC or ACL")+ -# ggplot2::xlab(ggplot2::element_blank())+ -# ecodata::theme_ts()+ -# ggplot2::guides(fill=ggplot2::guide_legend(ncol=2))+ -# ecodata::theme_title() -# -# Catch -# mean<- ecodata::abc_acl %>% -# dplyr::filter(EPU == "MAB") %>% -# tidyr::separate(col = Var, into = c("FMP", "Var"), sep = "_") %>% -# tidyr::pivot_wider(names_from = Var, values_from = Value) %>% -# #tidyr::separate(Catch, into = c("Catch", "X"), sep = ",") %>% -# dplyr::mutate(Catch = as.numeric(stringr::str_extract(Catch, pattern = "\\d+")), -# Quota = as.numeric(stringr::str_extract(Quota, pattern = "\\d+")), -# Value = Catch/Quota, -# Time = as.character(Time)) %>% -# filter(!Value == "NA") %>% -# dplyr::group_by(Time) %>% -# dplyr::summarise(val = mean(Value)) %>% -# dplyr::ungroup() %>% -# dplyr::mutate(Time = as.numeric(Time)) -# -# ecodata::abc_acl %>% -# dplyr::filter(EPU == "MAB") %>% -# tidyr::separate(col = Var, into = c("FMP", "Var"), sep = "_") %>% -# tidyr::pivot_wider(names_from = Var, values_from = Value) %>% -# #tidyr::separate(Catch, into = c("Catch", "X"), sep = ",") %>% -# dplyr::mutate(Catch = as.numeric(stringr::str_extract(Catch, pattern = "\\d+")), -# Quota = as.numeric(stringr::str_extract(Quota, pattern = "\\d+")), -# Value = Catch/Quota, -# Time = as.numeric(Time))%>% -# filter(!Value == "NA") %>% -# ggplot2::ggplot()+ -# #geom_boxplot()+ -# geom_point(aes(x = Time, y = Value))+ -# geom_point(data = mean, aes(x = Time, y = val), color = "red")+ -# geom_line(data = mean, aes(x = Time, y = val), color = "red")+ -# geom_hline(yintercept = 1, linetype='dashed', col = 'gray')+ -# ggplot2::ggtitle("MAFMC Catch per ABC or ACL")+ -# ggplot2::ylab(expression("Catch / ABC or ACL"))+ -# ggplot2::theme(legend.title = element_blank())+ -# ggplot2::xlab(element_blank())+ -# ecodata::theme_ts()+ -# ecodata::theme_title() +attr(plot_abc_acl, "report") <- c("MidAtlantic", "NewEngland") +attr(plot_abc_acl, "plottype") <- c("Stacked", "Catch") diff --git a/R/plot_aggregate_biomass.R b/R/plot_aggregate_biomass.R index 8d28742b..3b562109 100644 --- a/R/plot_aggregate_biomass.R +++ b/R/plot_aggregate_biomass.R @@ -349,9 +349,16 @@ plot_aggregate_biomass <- function(shadedRegion = NULL, color = "#ca0020",na.rm = T) } - - p <- cowplot::plot_grid(p1, p2, p3, p4, nrow=4,scale = 0.9) + - cowplot::draw_label(expression("Biomass (kg tow"^-1*")"), x= 0, y=0.5, vjust= 1.5, angle=90) + p <- ggpubr::ggarrange( + p1, + p2, + p3, + p4, + nrow = 4, + scale = 0.9) + + # p <- cowplot::plot_grid(p1, p2, p3, p4, nrow=4,scale = 0.9) + + # cowplot::draw_label(expression("Biomass (kg tow"^-1*")"), x= 0, y=0.5, vjust= 1.5, angle=90) #ggplot2::ylab(expression("Biomass (kg tow"^-1*")")) return(p) diff --git a/R/plot_annual_chl_pp.R b/R/plot_annual_chl_pp.R index cea105ab..80e76f9f 100644 --- a/R/plot_annual_chl_pp.R +++ b/R/plot_annual_chl_pp.R @@ -83,6 +83,17 @@ plot_annual_chl_pp <- function(shadedRegion = NULL, ecodata::theme_facet() + ecodata::theme_title() + if (report == "MidAtlantic") { + p <- p + + ggplot2::coord_cartesian(ylim = c(2e+07, 4e+07), xlim = c(1998, 2023)) + + ggplot2::ggtitle("MAB Primary Production") + + ggplot2::ylab("Carbon (mt)") + } + else { + p <- p + + ggplot2::theme(axis.title.x = ggplot2::element_blank()) + } + return(p) } diff --git a/R/plot_bennet.R b/R/plot_bennet.R index 1ebabbfa..44c2b5d0 100644 --- a/R/plot_bennet.R +++ b/R/plot_bennet.R @@ -88,6 +88,17 @@ plot_bennet <- function(shadedRegion = NULL, ecodata::theme_title()+ ecodata::theme_facet() + if (report == "MidAtlantic") { + p <- p + + ggplot2::theme(legend.position = "bottom") + + ggplot2::facet_wrap(~Var, + nrow = 2) + } else { + p <- p + + ggplot2::theme(legend.position = "bottom", + legend.title = ggplot2::element_blank(), + strip.text.y = ggplot2::element_blank()) + } } else if (varName == "total") { @@ -123,9 +134,35 @@ plot_bennet <- function(shadedRegion = NULL, # limits = y.lim, expand = c(0.01, 0.01)) + ecodata::theme_ts() + ggplot2::xlab(ggplot2::element_blank())+ - ggplot2::theme(title = ggplot2::element_text(size = 10))+ ecodata::theme_title() + if (report == "MidAtlantic") { + p <- p + + ggplot2::theme(text = ggplot2::element_text(size = 14)) + + ggplot2::theme( + legend.position = "bottom") + } + + if (EPU == "GB") { + p <- p + + ggplot2::ggtitle("GB revenue components") + + ggplot2::theme( + legend.position = "none", + legend.title = ggplot2::element_blank()) + + ggplot2::ylab("Million USD (2023)") + + ggplot2::theme(text = ggplot2::element_text(size = 12)) + } + + if (EPU == "GOM") { + p <- p + + ggplot2::ggtitle("GOM revenue components") + + ggplot2::theme( + legend.position = "bottom", + legend.title = ggplot2::element_blank()) + + ggplot2::ylab("Million USD (2023)") + + ggplot2::theme(text = ggplot2::element_text(size = 12)) + } + } else if (varName == "total_guild") { diff --git a/R/plot_benthos_index.R b/R/plot_benthos_index.R index c015aa03..9b17c50c 100644 --- a/R/plot_benthos_index.R +++ b/R/plot_benthos_index.R @@ -69,8 +69,8 @@ plot_benthos_index <- function(shadedRegion = NULL, xmin = setup$x.shade.min , xmax = setup$x.shade.max, ymin = -Inf, ymax = Inf) + ggplot2::geom_ribbon(ggplot2::aes(ymin = Lower, ymax = Upper, fill = Season), alpha = 0.5)+ - ggplot2::geom_point()+ - ggplot2::geom_line()+ + ggplot2::geom_point(ggplot2::aes(color = .data$Season)) + + ggplot2::geom_line(ggplot2::aes(color = .data$Season)) + ggplot2::ggtitle("")+ ggplot2::ylab(paste("Relative",varName,"Biomass"))+ ggplot2::xlab(ggplot2::element_blank())+ @@ -87,6 +87,11 @@ plot_benthos_index <- function(shadedRegion = NULL, legend.title = ggplot2::element_blank()) } + + if (varName == "Megabenthos") { + p <- p + + ggplot2::theme(legend.position = "none") + } } if (plottype == "cog"){ @@ -111,18 +116,19 @@ plot_benthos_index <- function(shadedRegion = NULL, xmin = setup$x.shade.min , xmax = setup$x.shade.max, ymin = -Inf, ymax = Inf) + ggplot2::geom_ribbon(ggplot2::aes(ymin = Lower, ymax = Upper, fill = Season), alpha = 0.3)+ # - ggplot2::geom_point()+ - ggplot2::geom_line()+ - ggplot2::ggtitle("")+ - ggplot2::ylab(paste(varName," Center of Gravity, km"))+ ggplot2::xlab(ggplot2::element_blank())+ - ggplot2::facet_wrap(~Direction, scales = "free_y")+ #Season ecodata::geom_gls()+ ecodata::geom_lm(n=n)+ ecodata::theme_ts()+ ecodata::theme_facet()+ - ecodata::theme_title() - + ecodata::theme_title() + + ggplot2::coord_cartesian(xlim = c(1980, 2023)) + + ggplot2::ggtitle("Northeast U.S. Macrobenthos Distribution") + + ggplot2::ylab("Center of Gravity, km") + + ggplot2::geom_point(ggplot2::aes(color = .data$Season)) + + ggplot2::geom_line(ggplot2::aes(color = .data$Season)) + + ggplot2::theme(legend.position = 'bottom') + + ggplot2::facet_grid(cols = ggplot2::vars(Season), rows = ggplot2::vars(Direction), scales = "free_y") } return(p) diff --git a/R/plot_cetacean_dist.R b/R/plot_cetacean_dist.R index 0e1e61d7..c8caf1e5 100644 --- a/R/plot_cetacean_dist.R +++ b/R/plot_cetacean_dist.R @@ -66,7 +66,6 @@ plot_cetacean_dist <- function(shadedRegion = NULL, #ggplot2::scale_color_manual(values = c("blue", "black", "red"))+ ggplot2::coord_sf(xlim = setup$xlims, ylim = setup$ylims) + ecodata::theme_map() + - ggplot2::ggtitle("Cetacean Species Distribution") + ggplot2::xlab("") + ggplot2::ylab("") + ggplot2::scale_x_continuous(breaks=c(-76,-72, -68) )+ @@ -77,8 +76,9 @@ plot_cetacean_dist <- function(shadedRegion = NULL, strip.text = ggplot2::element_text(hjust=0), axis.text = ggplot2::element_text(size = 8), legend.title = ggplot2::element_blank())+#, - #ggplot2::legend.position = c(0.6, 0.15)) + - ggplot2::facet_wrap(~season) + ggplot2::ggtitle("Whale and Dolphin Distribution Shifts") + + ggplot2::facet_wrap(~season, nrow = 1) + + ggplot2::theme(legend.position = "bottom") # hms_map # # optional code for New England specific (2 panel) formatting diff --git a/R/plot_chl_pp.R b/R/plot_chl_pp.R index efb4b2cf..208609e0 100644 --- a/R/plot_chl_pp.R +++ b/R/plot_chl_pp.R @@ -125,7 +125,7 @@ plot_chl_pp <- function(shadedRegion = NULL, ggplot2::geom_point() + ggplot2::geom_line() + ecodata::geom_lm(n = n) + - ggplot2::scale_x_discrete(name = "", breaks = seq(min(out$Year),max(out$Year),10)) + + ggplot2::scale_x_discrete(name = "", breaks = scales::pretty_breaks(n = 1)) + ggplot2::facet_wrap(EPU~Month~., ncol = 12) + ggplot2::ggtitle(paste0("Monthly median ",varabbr)) + ggplot2::ylab(varunits) + @@ -135,9 +135,13 @@ plot_chl_pp <- function(shadedRegion = NULL, alpha = setup$hline.alpha, linetype = setup$hline.lty)+ ecodata::theme_facet() + - ggplot2::theme(axis.text.x = ggplot2::element_text(angle=45, hjust = 1), + ggplot2::theme(text = ggplot2::element_text(size = 16), + axis.text.x = ggplot2::element_text(size = 8, angle=45, hjust = 1), panel.spacing = ggplot2::unit(1, "lines"), + panel.border = ggplot2::element_rect(color = "gray80"), plot.margin = ggplot2::unit(c(0.1, 0, 0, 0), "cm"))+ + ggplot2::facet_grid(rows = ggplot2::vars(EPU), cols = ggplot2::vars(Month)) + + ggplot2::geom_point(color = "white") + ggplot2::geom_line() + ecodata::theme_title() } diff --git a/R/plot_comdat.R b/R/plot_comdat.R index f00ba47d..73c58733 100644 --- a/R/plot_comdat.R +++ b/R/plot_comdat.R @@ -216,6 +216,7 @@ plot_comdat <- function(shadedRegion = NULL, dplyr::filter(EPU %in% filterEPUs) ylabdat <- expression("Revenue (10"^6*" USD)") + } # code for generating plot object p @@ -246,7 +247,6 @@ plot_comdat <- function(shadedRegion = NULL, ggplot2::scale_color_manual(values = series.col2, aesthetics = "color")+ ggplot2::facet_wrap(~EPU, scales = "free")+ #ggplot2::guides(color = "none") + - ggplot2::ylab(ylabdat) + ggplot2::xlab(ggplot2::element_blank())+ ggplot2::theme(legend.position = "bottom", legend.title = ggplot2::element_blank())+ @@ -258,9 +258,22 @@ plot_comdat <- function(shadedRegion = NULL, ecodata::theme_ts() + ggplot2::ggtitle(setup$region)+ ecodata::theme_title() + - ecodata::theme_facet() + ecodata::theme_facet() + + ggplot2::ylab(ylabdat) + + if (report == "MidAtlantic") { + p <- p + + ggplot2::theme(strip.text.x = ggplot2::element_blank(), + legend.position = "bottom", + legend.title = ggplot2::element_blank()) + } else { + p <- p + + ggplot2::facet_wrap(~EPU, + nrow = 2) + } } + if(plottype == "guild") { facet_names <- list("Apex" = expression("Apex"), @@ -314,7 +327,9 @@ plot_comdat <- function(shadedRegion = NULL, legend.position = "bottom", legend.title = ggplot2::element_blank())+ ggplot2::ggtitle(setup$region)+ - ecodata::theme_title() + ecodata::theme_title() + + ggplot2::geom_point(size = 0.05) + + ggplot2::geom_line(size = 0.05) } diff --git a/R/plot_commercial_div.R b/R/plot_commercial_div.R index 598ba5b8..05bf7b95 100644 --- a/R/plot_commercial_div.R +++ b/R/plot_commercial_div.R @@ -89,13 +89,15 @@ plot_commercial_div <- function(shadedRegion = NULL, size = setup$hline.size, alpha = setup$hline.alpha, linetype = setup$hline.lty) + + ggplot2::theme(plot.margin = ggplot2::unit(c(0.25, 0.5, 0.25, 0.5), "cm")) + ecodata::theme_ts()+ ecodata::theme_title() # optional code for New England specific (2 panel) formatting if (report == "NewEngland") { p <- p + ggplot2::theme(legend.position = "bottom", - legend.title = ggplot2::element_blank()) + legend.title = ggplot2::element_blank()) + + ggplot2::ylab('Effective Shannon Index') } diff --git a/R/plot_community_climate_vulnerability.R b/R/plot_community_climate_vulnerability.R index 6321d389..168fb2b7 100644 --- a/R/plot_community_climate_vulnerability.R +++ b/R/plot_community_climate_vulnerability.R @@ -7,7 +7,7 @@ #' @param varName Character string. Which variable: ocean acidification sensitivity, #' temperature sensitivity, stock biomass sensitivity, total sensitivity, total vulnerability #' ("oaSum","tempSum","stckSum","sensSum","vulnSum") -#' @param plottype Character string. Which plot: proportion of communities (default) +#' @param plottype Character string. Which plot: proportion of communities (default) #' or regional sensitivity by revenue or landings ("propcomm", "regionrev", "regionland") #' @param n Numeric scalar. Number of years used (from most recent year) to estimate short term trend . Default = 0 (No trend calculated) #' @@ -51,9 +51,9 @@ plot_community_climate_vulnerability <- function(shadedRegion = NULL, "Total Climate Sensitivity", "Total Climate Vulnerability") names(varTitle) <- c("oaSum","tempSum","stckSum", "sensSum","vulnSum") - + if(plottype=="propcomm"){ #proportion of communities - + props <- ecodata::community_climate_vulnerability |> dplyr::filter(!stringr::str_detect(Var, "Regional-")) |> tidyr::separate(Var, into = c("Town", "StateVar"), sep = ",") |> #using two steps because some towns have - in the name @@ -72,18 +72,18 @@ plot_community_climate_vulnerability <- function(shadedRegion = NULL, dplyr::group_by(Time, EPU, risk) |> dplyr::mutate(catn = dplyr::n(), propcat = catn/commn) - + propsonly <- props |> dplyr::select(Time, EPU, risk, propcat) |> dplyr::distinct() - + # 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 <- ggplot2::ggplot() + + + p <- ggplot2::ggplot() + 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) + @@ -104,16 +104,17 @@ plot_community_climate_vulnerability <- function(shadedRegion = NULL, #ggplot2::ggtitle("Mid-Atlantic") + #ggplot2::theme(legend.position = "blank") ggplot2::ylab("Proportion communities") + + ggplot2::theme(legend.position = 'bottom')+ ecodata::geom_lm(n=n) + ecodata::theme_ts()+ ecodata::theme_facet()+ ecodata::theme_title() - - + + return(p) - + }else{ #regional plots - + if(plottype == "regionrev"){ units <- "value" type <- "Revenue" @@ -121,7 +122,7 @@ plot_community_climate_vulnerability <- function(shadedRegion = NULL, units <- "pounds" type <- "Landings" } - + regional <- ecodata::community_climate_vulnerability |> dplyr::filter(stringr::str_detect(Var, "Regional-")) |> dplyr::mutate(Varin = stringr::str_extract(Var, '\\b\\w+$'), #keep everything before - @@ -130,7 +131,7 @@ plot_community_climate_vulnerability <- function(shadedRegion = NULL, dplyr::filter(Var %in% varName, EPU %in% filterEPUs, Units %in% units) - + p <- ggplot2::ggplot() + #Highlight last ten years ggplot2::annotate("rect", fill = setup$shade.fill, alpha = setup$shade.alpha, @@ -141,7 +142,7 @@ plot_community_climate_vulnerability <- function(shadedRegion = NULL, alpha = .3) + ggplot2::scale_fill_manual(values=risk, breaks=c('Low', 'Moderate', 'High', 'Very High'), - name=varTitle[varName]) + + name=varTitle[varName]) + # ecodata::geom_gls(data = regional, ggplot2::aes(x = Time, y = Value, # group = Var), # alpha = setup$trend.alpha, size = setup$trend.size) + @@ -155,19 +156,21 @@ plot_community_climate_vulnerability <- function(shadedRegion = NULL, ggplot2::theme_bw() + #ggplot2::ggtitle("Mid-Atlantic") + #ggplot2::theme(legend.position = "blank") - ggplot2::ylab(paste("Regional", type, varTitle[varName])) + + ggplot2::ylab(paste("Total Climate Vulnerability \n Regional", type)) + ecodata::theme_ts()+ ecodata::theme_facet()+ - ecodata::theme_title() - - + ecodata::theme_title()+ + # ggplot2::ylab("Total Climate Vulnerability \n (Regional Landings)") + + ggplot2::theme(legend.position = 'bottom') + + return(p) - - - + + + } - - + + } attr(plot_community_climate_vulnerability,"report") <- c("MidAtlantic","NewEngland") diff --git a/R/plot_condition.R b/R/plot_condition.R index bb8fe2b7..4a2f82f5 100644 --- a/R/plot_condition.R +++ b/R/plot_condition.R @@ -83,11 +83,14 @@ plot_condition <- function(shadedRegion = NULL, ggplot2::scale_fill_manual(values=vir) + ggplot2::guides(fill = ggplot2::guide_legend(reverse = TRUE)) + ggplot2::scale_x_continuous(breaks=round(seq(min(fix$Time), max(fix$Time), by = numberOfConditions))) + - ggplot2::theme(legend.position = "right", legend.box = "vertical", legend.title = ggplot2::element_text(size = 8), - legend.text = ggplot2::element_text(size = 6), + ggplot2::theme( + legend.title = ggplot2::element_text(size = 10), + legend.text = ggplot2::element_text(size = 10), axis.title = ggplot2::element_blank(), - axis.text.x = ggplot2::element_text(size = 6), - axis.text.y = ggplot2::element_text(size = 6), + axis.text.x = ggplot2::element_text(size = 12), + axis.text.y = ggplot2::element_text(size = 8), + plot.title = ggplot2::element_text(size = 14), + legend.position = "bottom", panel.grid.major = ggplot2::element_blank(), panel.grid.minor = ggplot2::element_blank()) + ggplot2::ggtitle(paste0("Relative condition for species sampled in ",EPU)) + @@ -96,6 +99,21 @@ plot_condition <- function(shadedRegion = NULL, ecodata::theme_ts()+ ecodata::theme_title() + if (report == "NewEngland") { + p <- p + + ggplot2::theme( + legend.text = ggplot2::element_text(size = 8), + legend.title = ggplot2::element_text(size = 8), + axis.text.x = ggplot2::element_text(size = 8), + axis.text.y = ggplot2::element_text(size = 6), + plot.title = ggplot2::element_text(size = 12) + ) + } + else { + p <- p + + ggplot2::guides(fill= ggplot2::guide_legend(nrow=2,byrow=TRUE)) + } + return(p) } diff --git a/R/plot_energy_density.R b/R/plot_energy_density.R index c3e6523b..2b7a425c 100644 --- a/R/plot_energy_density.R +++ b/R/plot_energy_density.R @@ -59,7 +59,8 @@ plot_energy_density <- function(shadedRegion = NULL, ggplot2::ylab("Mean Energy Density (kJ/g)")+ ggplot2::theme(axis.title.x= ggplot2::element_blank(), axis.text.x = ggplot2::element_text(angle = 45, hjust = 1), - legend.title = ggplot2::element_blank())+ + legend.title = ggplot2::element_blank(), + legend.position = "bottom")+ #ggplot2::scale_x_continuous(breaks=c(2017,2018, 2019, 2020, 2021, 2022))+ ggplot2::ggtitle("Forage Fish Energy Density")+ ecodata::theme_facet()+ diff --git a/R/plot_engagement.R b/R/plot_engagement.R index 717b17c7..6b0f2069 100644 --- a/R/plot_engagement.R +++ b/R/plot_engagement.R @@ -120,16 +120,17 @@ plot_engagement <- function(shadedRegion = NULL, ggplot2::xlab(expression(paste("Engagement Index", italic(" (factor score)"))))+ ggplot2::guides(color=ggplot2::guide_legend(title="Engagement Score Rank"))+ ggrepel::geom_label_repel(ggplot2::aes(label = ifelse(Town %in% c(unlist(topTowns)),as.character(Town),'')), - size=2, - force=2.5, + size=2.5, + force=2.75, box.padding = 0.5, point.padding = 0, - segment.color = 'grey50', + segment.color = 'grey80', min.segment.length = 0.01, max.overlaps=Inf, label.size = NA, fill = ggplot2::alpha(c("white"),0.1))+ ggplot2::ggtitle(paste(setup$region, "Engagement in Top", varName, "Fishing Communities"))+ + ggplot2::theme(plot.title = ggplot2::element_text(vjust = 0))+ #ecodata::theme_ts()+ ecodata::theme_title() diff --git a/R/plot_exp_n.R b/R/plot_exp_n.R index f3e44e73..c8efa228 100644 --- a/R/plot_exp_n.R +++ b/R/plot_exp_n.R @@ -73,34 +73,24 @@ plot_exp_n <- function(shadedRegion = NULL, alpha = 0.5) + ggplot2::geom_line(size = setup$lwd-0.5) + ggplot2::geom_point(size = setup$pcex-0.5) + - #ecodata::geom_lm(aes(x = Time, y = Value, group = Var))+ - #ecodata::geom_lm()+ - # scale_color_manual(values = series.col, aesthetics = "color")+ - #ggplot2::guides(color = FALSE) + - #ggplot2::geom_hline(aes(yintercept = hline, - # group = Var), - # size = hline.size, - # alpha = hline.alpha, - # linetype = hline.lty)+ ggplot2::facet_wrap(EPU~.,scales = "free_y", ncol = 2) + ggplot2::ggtitle(paste("Expected Number of Species -", season))+ ecodata::geom_gls() + ecodata::geom_lm(n=n) + #Axis and theme - ggplot2::scale_x_continuous(breaks = seq(start_year, 2015, by = 10), expand = c(0.01, 0.01)) + - ggplot2::ylab("n species per 1000 ind") + + ggplot2::scale_x_continuous(breaks = seq(1968, 2018, by = 10), expand = c(0.01, 0.01)) + + ggplot2::ylab("Number of species / 1000 Individuals") + ggplot2::xlab(ggplot2::element_blank())+ ecodata::theme_facet()+ ggplot2::theme(strip.text= ggplot2::element_text(hjust=0), - legend.title = ggplot2::element_blank())+ + legend.title = ggplot2::element_blank(), + axis.title.y = ggplot2::element_text(size = 8), + legend.position = 'bottom') + ecodata::theme_title() - # optional code for New England specific (2 panel) formatting if (report == "NewEngland") { p <- p + - ggplot2::theme(legend.position = "bottom", - legend.title = ggplot2::element_blank()) - + ggplot2::facet_wrap(~EPU, nrow = 2) } return(p) diff --git a/R/plot_finfish_traits.R b/R/plot_finfish_traits.R index 1cc98eb9..e3117bea 100644 --- a/R/plot_finfish_traits.R +++ b/R/plot_finfish_traits.R @@ -4,9 +4,9 @@ #' #' @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:Trophic Level, Offspring Size, -#' Age at Maturity, Length at Maturity, Fecundity, Maximum Theoretical Length, Growth Rate, -#' Maximum Observed Length, and three Pricipal Components Axes Pace of Life (PC1), PC2, andPC3 +#' @param varName Character string. Which variable:Trophic Level, Offspring Size, +#' Age at Maturity, Length at Maturity, Fecundity, Maximum Theoretical Length, Growth Rate, +#' Maximum Observed Length, and three Pricipal Components Axes Pace of Life (PC1), PC2, andPC3 #' ("trophic_level","offspring_size","age_maturity","length_maturity","fecundity","l_inf","k", #' "max_obs_length","PC1","PC2","PC3") #' @param n Numeric scalar. Number of years used (from most recent year) to estimate short term trend . Default = 0 (No trend calculated) @@ -35,19 +35,19 @@ plot_finfish_traits <- function(shadedRegion = NULL, # optional code to wrangle ecodata object prior to plotting # e.g., calculate mean, max or other needed values to join below - + varTitle <- c("Trophic Level", "Offspring Size", "Age at Maturity", "Length at Maturity", "Fecundity", "Maximum Theoretical Length", "Growth Rate", "Maximum Observed Length", "Pace of Life", "PC2", "PC3") names(varTitle) <- c("trophic_level","offspring_size","age_maturity","length_maturity", "fecundity","l_inf","k","max_obs_length", "PC1","PC2","PC3") - + fix<- ecodata::finfish_traits |> tidyr::separate(Var, into = c("Season", "Var"), sep = "-") |> dplyr::group_by(Season, Var, EPU) |> dplyr::summarise(hline = mean(Value)) - + varUnit <- ecodata::finfish_traits |> tidyr::separate(Var, into = c("Season", "Var"), sep = "-") |> dplyr::filter(Var %in% c(varName)) |> @@ -85,21 +85,19 @@ plot_finfish_traits <- function(shadedRegion = NULL, linewidth = setup$hline.size, alpha = setup$hline.alpha, linetype = setup$hline.lty)+ + ggplot2::theme(legend.position = "bottom") + ecodata::theme_ts()+ ecodata::theme_facet()+ ecodata::theme_title() # optional code for New England specific (2 panel) formatting - if (report == "NewEngland") { + if (report == "NewEngland") { p <- p + - ggplot2::theme(legend.position = "bottom", - legend.title = ggplot2::element_blank()) - + ggplot2::ylab('Fecundity (number of \noffspring per mature female)')+ + ggplot2::facet_wrap(~EPU, nrow = 2) } - return(p) - } attr(plot_finfish_traits,"report") <- c("MidAtlantic","NewEngland") diff --git a/R/plot_forage_index.R b/R/plot_forage_index.R index aaef4c8e..46a7a6e2 100644 --- a/R/plot_forage_index.R +++ b/R/plot_forage_index.R @@ -75,7 +75,8 @@ plot_forage_index <- function(shadedRegion = NULL, if (report == "NewEngland") { p <- p + ggplot2::theme(legend.position = "bottom", - legend.title = ggplot2::element_blank()) + legend.title = ggplot2::element_blank()) + + ggplot2::facet_wrap(~EPU, nrow = 2) } } @@ -102,17 +103,20 @@ plot_forage_index <- function(shadedRegion = NULL, xmin = setup$x.shade.min , xmax = setup$x.shade.max, ymin = -Inf, ymax = Inf) + ggplot2::geom_ribbon(ggplot2::aes(ymin = Lower, ymax = Upper, fill = Season), alpha = 0.3)+ # - ggplot2::geom_point()+ - ggplot2::geom_line()+ - ggplot2::ggtitle("")+ - ggplot2::ylab(expression("Forage Center of Gravity, km"))+ - ggplot2::xlab(ggplot2::element_blank())+ - ggplot2::facet_wrap(~Direction, scales = "free_y")+ #Season + ggplot2::xlab(ggplot2::element_blank()) + ecodata::geom_gls()+ ecodata::geom_lm(n=n)+ ecodata::theme_ts()+ ecodata::theme_facet()+ - ecodata::theme_title() + ecodata::theme_title()+ + ggplot2::coord_cartesian(xlim = c(1982, 2023)) + + ggplot2::ggtitle("Northeast U.S. Forage Fish Distribution") + + ggplot2::ylab("Center of Gravity, km") + + ggplot2::geom_point(ggplot2::aes(color = .data$Season)) + + ggplot2::geom_line(ggplot2::aes(color = .data$Season)) + + ggplot2::facet_wrap(~Var, nrow = 2) + + ggplot2::theme(legend.position = "bottom") + + ggplot2::facet_grid(cols = ggplot2::vars(Season), rows = ggplot2::vars(Direction), scales = "free_y") } diff --git a/R/plot_gom_salmon.R b/R/plot_gom_salmon.R index 9aec252c..c223dca7 100644 --- a/R/plot_gom_salmon.R +++ b/R/plot_gom_salmon.R @@ -51,15 +51,16 @@ plot_gom_salmon <- function(shadedRegion = NULL, strip.position = "left", labeller = ggplot2::as_labeller(c(Total = yaxisLabel$Units[yaxisLabel$Var=="Total"], PSAR = yaxisLabel$Units[yaxisLabel$Var=="PSAR"]) ) )+ ggplot2::ggtitle("Atlantic Salmon")+ - #ggplot2::ylab()+ ggplot2::xlab(ggplot2::element_blank())+ ggplot2::ylab(ggplot2::element_blank())+ + ggplot2::ylab('Returning proportion') + ecodata::geom_gls()+ ecodata::geom_lm(n=n) + ecodata::theme_ts()+ ecodata::theme_title()+ ggplot2::theme(strip.placement = "outside", - strip.background = ggplot2::element_blank()) + strip.background = ggplot2::element_blank())+ + ggplot2::facet_wrap(~Var, nrow = 2, scales = "free_y") return(p) diff --git a/R/plot_lps_sharks.r b/R/plot_lps_sharks.r index 6db2c714..b5574964 100644 --- a/R/plot_lps_sharks.r +++ b/R/plot_lps_sharks.r @@ -54,7 +54,7 @@ plot_lps_sharks <- function(shadedRegion = NULL, ggplot2::geom_point()+ ggplot2::geom_line()+ ecodata::geom_lm(n = n) + - ggplot2::ggtitle(paste(report, "Recreational Pelagic Shark Landings"))+ + ggplot2::ggtitle(paste(report, "Large Pelagics Survey Rec. Shark Landings"))+ ggplot2::ylab(expression("Number of Fish (1000s)"))+ ggplot2::xlab(ggplot2::element_blank()) + ggplot2::geom_hline(ggplot2::aes(yintercept = ltm$hline), @@ -65,7 +65,8 @@ plot_lps_sharks <- function(shadedRegion = NULL, # ecodata::geom_gls()+ ecodata::theme_ts()+ ecodata::theme_facet()+ - ecodata::theme_title() + ecodata::theme_title()+ + ggplot2::theme(legend.background = ggplot2::element_rect(fill = "white")) # optional code for New England specific (2 panel) formatting # if (report == "NewEngland") { diff --git a/R/plot_mass_inshore_survey.R b/R/plot_mass_inshore_survey.R index d26c9fdd..2ac4f527 100644 --- a/R/plot_mass_inshore_survey.R +++ b/R/plot_mass_inshore_survey.R @@ -105,8 +105,6 @@ plot_mass_inshore_survey <- 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_point()+ - ggplot2::geom_line()+ ggplot2::geom_point(data = df2,ggplot2::aes(x=Time,y=max),alpha = 0)+ ggplot2::geom_hline(ggplot2::aes(yintercept = hline, group = Var), @@ -117,6 +115,8 @@ plot_mass_inshore_survey <- function(shadedRegion = NULL, ggplot2::aes(x = Time, ymin = pmax(lower,0), ymax = upper), alpha = 0.5, fill = "gray")+ + ggplot2::geom_point()+ + ggplot2::geom_line()+ ggplot2::ggtitle("Massachusetts inshore BTS")+ ggplot2::ylab(expression("Biomass (kg tow"^-1*")"))+ ggplot2::xlab(ggplot2::element_blank())+ diff --git a/R/plot_narw.R b/R/plot_narw.R index 729809de..6c2fda52 100644 --- a/R/plot_narw.R +++ b/R/plot_narw.R @@ -16,7 +16,7 @@ plot_narw <- function(shadedRegion = NULL, report="MidAtlantic", varName = "adult", - n = 0) { + n = 10) { # generate plot setup list (same for all plot functions) setup <- ecodata::plot_setup(shadedRegion = shadedRegion, @@ -30,10 +30,10 @@ plot_narw <- function(shadedRegion = NULL, } if (varName == "calf") { - vtitle <- "NARW calf abundance" + vtitle <- "North Atlantic right whale calf abundance" vylab <- "Number of individuals" } else { - vtitle <- "NARW abundance" + vtitle <- "North Atlantic right whale abundance" vylab <- "Number of individuals" } diff --git a/R/plot_productivity_anomaly.R b/R/plot_productivity_anomaly.R index 5b96fabd..a9f84f6a 100644 --- a/R/plot_productivity_anomaly.R +++ b/R/plot_productivity_anomaly.R @@ -86,12 +86,14 @@ plot_productivity_anomaly <- function(shadedRegion = NULL, ggplot2::ggtitle(paste0(filterEPUs," Recruitment Anomaly from Stock Assessments")) + #ggplot2::guides(fill = guide_legend(ncol = leg_ncol)) + ecodata::theme_ts()+ + ggplot2::guides(fill = ggplot2::guide_legend(ncol = 2)) + ggplot2::theme(axis.title = ggplot2::element_text(size = 10), - axis.text = ggplot2::element_text(size = 10), - plot.title = ggplot2::element_text(size = 12), - #legend.text = element_text(size = leg_font_size), + axis.title.y = ggplot2::element_text(vjust = 0, size = 10), + axis.text = ggplot2::element_text(size = 11), + plot.title = ggplot2::element_text(size = 11), legend.title = ggplot2::element_blank(), - legend.text=ggplot2::element_text(size=6)) + legend.text = ggplot2::element_text(size=8), + legend.position = "bottom") } @@ -117,7 +119,20 @@ plot_productivity_anomaly <- function(shadedRegion = NULL, leg_font_size = leg_font_size, label = "", y.text = 10, - aggregate = TRUE) + aggregate = TRUE) + + ggplot2::guides( + fill = ggplot2::guide_legend( + ncol = dplyr::case_when( + region == "NewEngland" ~ 3, + region == "MidAtlantic" ~ 2, + TRUE ~ 2))) + + ggplot2::theme( + legend.position = "bottom", + legend.title = ggplot2::element_blank(), + legend.text = ggplot2::element_text(size = 8), + plot.title = ggplot2::element_text(size = 11), + axis.text = ggplot2::element_text(size = 11), + axis.title.y = ggplot2::element_text(vjust = 0, size = 10)) diff --git a/R/plot_rec_hms.r b/R/plot_rec_hms.r index f01c1832..a6877ea0 100644 --- a/R/plot_rec_hms.r +++ b/R/plot_rec_hms.r @@ -51,15 +51,20 @@ plot_rec_hms <- function(shadedRegion = NULL, ggplot2::geom_point()+ ggplot2::geom_line()+ ecodata::geom_lm(n = n) + - ggplot2::ggtitle(paste(report,"Recreational Shark Landings"))+ + ggplot2::ggtitle(paste(report,"Marine Recreational Information Program (MRIP) Rec. Shark Landings"))+ ggplot2::ylab(expression("Number of Fish (1000s)"))+ ggplot2::xlab(ggplot2::element_blank()) + + ggplot2::scale_color_discrete( + limits = c("LargeCoastal", "Prohibited", "SmallCoastal"), + labels = c("Large Coastal", "Prohibited", "Small Coastal") + ) + # ecodata::geom_gls()+ ecodata::theme_ts()+ ecodata::theme_facet()+ ecodata::theme_title() + # optional code for New England specific (2 panel) formatting # if (report == "NewEngland") { # p <- p + diff --git a/R/plot_recdat.R b/R/plot_recdat.R index 49928819..1af67bf3 100644 --- a/R/plot_recdat.R +++ b/R/plot_recdat.R @@ -90,7 +90,8 @@ plot_recdat <- function(shadedRegion = NULL, if (report == "NewEngland") { p <- p + ggplot2::theme(legend.position = "bottom", - legend.title = ggplot2::element_blank()) + legend.title = ggplot2::element_blank()) + + ggplot2::ylab('Effective Shannon Index') } diff --git a/R/plot_seabird_ne.R b/R/plot_seabird_ne.R index 94de99c8..bb689a3f 100644 --- a/R/plot_seabird_ne.R +++ b/R/plot_seabird_ne.R @@ -69,6 +69,7 @@ plot_seabird_ne <- function(shadedRegion = NULL, ggplot2::ggtitle("Common tern productivity")+ ggplot2::ylab(expression("Fledged chicks per nest"))+ ggplot2::xlab(ggplot2::element_blank())+ + ggplot2::coord_cartesian(xlim = c(1992, 2023))+ ecodata::geom_gls()+ ecodata::geom_lm(n=n)+ ecodata::theme_ts()+ diff --git a/R/plot_seal_pups.R b/R/plot_seal_pups.R index 4ef3f3a7..dde0a0a8 100644 --- a/R/plot_seal_pups.R +++ b/R/plot_seal_pups.R @@ -12,7 +12,7 @@ #' plot_seal_pups <- function(shadedRegion = NULL, - report="MidAtlantic") { + report="NewEngland") { # generate plot setup list (same for all plot functions) setup <- ecodata::plot_setup(shadedRegion = shadedRegion, @@ -52,7 +52,8 @@ plot_seal_pups <- function(shadedRegion = NULL, #ecodata::geom_gls()+ ecodata::theme_ts()+ ecodata::theme_facet()+ - ecodata::theme_title() + ecodata::theme_title()+ + ggplot2::theme(legend.position = 'bottom') # # optional code for New England specific (2 panel) formatting # if (report == "NewEngland") { diff --git a/R/plot_spawn_timing.R b/R/plot_spawn_timing.R index 3a856001..899e9f6f 100644 --- a/R/plot_spawn_timing.R +++ b/R/plot_spawn_timing.R @@ -74,7 +74,7 @@ plot_spawn_timing <- function(shadedRegion = NULL, ecodata::theme_title() if(varName %in% c("Resting", "Ripe", "Spent", "Developing")){ - p <- p + ggplot2::ggtitle(paste(stringr::str_to_sentence(filt$Season), varName, "Spawning Stage")) + p <- p + ggplot2::ggtitle("Spring Resting Maturity Stage") } if(varName %in% c("MF", "meanTEMP", "meanJDAY")){ diff --git a/R/plot_species_dist.R b/R/plot_species_dist.R index cda82fc2..abad3e3b 100644 --- a/R/plot_species_dist.R +++ b/R/plot_species_dist.R @@ -75,6 +75,7 @@ plot_species_dist <- function(shadedRegion = NULL, alpha = setup$hline.alpha, linetype = setup$hline.lty, na.rm=T) + + ggplot2::coord_cartesian(xlim = c(1969, 2021)) + ecodata::geom_gls(na.rm=T) + ecodata::geom_lm(n=n,na.rm=T)+ ecodata::theme_ts()+ diff --git a/R/plot_stock_status.R b/R/plot_stock_status.R index 4b42e46a..c10e5340 100644 --- a/R/plot_stock_status.R +++ b/R/plot_stock_status.R @@ -81,6 +81,15 @@ plot_stock_status <- function(shadedRegion = NULL, ecodata::theme_ts()+ ecodata::theme_title() + if (report == "MidAtlantic") { + p <- p + + ggplot2::coord_cartesian(xlim = c(0, 2), ylim = c(0, 2)) + + ggplot2::theme(legend.position = 'bottom') + } else { + p <- p + + ggplot2::theme(legend.position = "bottom") + } + # # optional code for New England specific (2 panel) formatting # if (report == "NewEngland") { # p <- p + diff --git a/R/plot_thermal_habitat_gridded.R b/R/plot_thermal_habitat_gridded.R index 68bfe12d..8e3a82c3 100644 --- a/R/plot_thermal_habitat_gridded.R +++ b/R/plot_thermal_habitat_gridded.R @@ -49,7 +49,7 @@ plot_thermal_habitat_gridded <- function(shadedRegion = NULL, p <- fix |> ggplot2::ggplot()+ - ggplot2::geom_tile(ggplot2::aes(x=Longitude,y = Latitude, color = Value, width = 1/12, height = 1/12), + ggplot2::geom_tile(ggplot2::aes(x=Longitude,y = Latitude, fill = Value, width = 1/12, height = 1/12), linewidth = setup$line.size) + ggplot2::geom_sf(data=ecodata::coast, size = setup$map.lwd) + ggplot2::facet_grid(Depth~Var)+ @@ -65,6 +65,11 @@ plot_thermal_habitat_gridded <- function(shadedRegion = NULL, ggplot2::ggtitle(paste(Yr)) + ggplot2::theme(legend.position = "bottom") + if (report == "NewEngland") { + p <- p + + ggplot2::theme(plot.margin = grid::unit(c(0, 0, 0, 0), "cm")) + } + return(p) diff --git a/R/plot_trans_dates.R b/R/plot_trans_dates.R index b359bddc..bdd282af 100644 --- a/R/plot_trans_dates.R +++ b/R/plot_trans_dates.R @@ -72,17 +72,21 @@ plot_trans_dates <- function(shadedRegion = NULL, ggplot2::geom_line()+ ecodata::geom_gls() + ecodata::geom_lm(n=n)+ - # ggplot2::theme(strip.text=ggplot2::element_text(hjust=0), - # plot.title = ggplot2::element_text(size = 12))+ + ggplot2::theme( + strip.background = ggplot2::element_blank(), + strip.text.x = ggplot2::element_blank()) + ecodata::theme_title()+ ggplot2::ylab("Number of Days")+ - ggplot2::ggtitle(paste0(report,": Number of days between spring and fall transition dates")) + + ggplot2::ggtitle(paste0("Time between spring and fall transition in ", report)) + #ggplot2::xlab(ggplot2::element_blank())+ ecodata::theme_ts()+ ggplot2::facet_wrap(.~EPU)+ ecodata::theme_facet() - + if (report == "NewEngland") { + p <- p + + ggplot2::facet_wrap(~EPU, nrow = 2) + } diff --git a/R/plot_wind_dev_speed.R b/R/plot_wind_dev_speed.R index a32a4905..db5b6bce 100644 --- a/R/plot_wind_dev_speed.R +++ b/R/plot_wind_dev_speed.R @@ -47,7 +47,8 @@ plot_wind_dev_speed <- function(shadedRegion = NULL, #theme(axis.text.x = element_text(angle = 45, hjust = 1))+ ggplot2::scale_x_continuous(breaks=c(2020,2022, 2024,2026, 2028, 2030))+ ecodata::theme_title()+ - ggplot2::scale_colour_discrete(name="Year Reported") + ggplot2::scale_colour_discrete(name="Year Reported") + + ggplot2::theme(legend.position = 'bottom') # ggplot2::theme(legend.position = c(0.8, 0.2)) diff --git a/R/plot_wind_port.R b/R/plot_wind_port.R index b413a886..38c017e1 100644 --- a/R/plot_wind_port.R +++ b/R/plot_wind_port.R @@ -1,18 +1,36 @@ -#' plot revenue by port from wind energy +#' @details +#' The \code{lease_status} column is converted to a \strong{factor} with levels ordered +#' as: "All leases", "Non-active leases", and "Active leases". #' -#' plot wind_port data +#' If \code{port_list} is \code{NULL}, data is filtered by the \code{region} column +#' matching the \code{report} value (e.g., \code{"MidAtlantic"}). If \code{port_list} +#' is provided, data is filtered to include only those port states. #' -#' @param shadedRegion Numeric vector. Years denoting the shaded region of the plot (most recent 10) -#' @param report Character string. Which SOE report ("MidAtlantic", "NewEngland") +#' The ports (\code{PORT_STATE}) are ordered on the plot based on the +#' \strong{descending \code{avg_val}} for the \strong{"All leases"} status. #' -#' @return ggplot object +#' The plot uses a \strong{dodged column geometry} (\code{geom_col}) and is +#' \strong{coordinate-flipped} (\code{coord_flip}). The title and \code{facet_wrap} +#' layout depend on whether a \code{port_list} was provided. #' +#' @examples +#' # Assuming 'all_data' is a dataframe with the required columns +#' # (Run these examples after loading required packages like ggplot2 and dplyr) #' -#' @export +#' # Example 1: Plotting for the default Mid-Atlantic region +#' # plot_wind_port() +#' +#' # Example 2: Plotting for the New England region (by setting a different report value) +#' # plot_wind_port(report = "NewEngland") +#' +#' # Example 3: Plotting for a specific list of ports +#' # plot_wind_port(port_list = c("New Bedford, MA", "Montauk, NY")) #' plot_wind_port <- function(shadedRegion = NULL, - report="MidAtlantic") { + report="MidAtlantic", + data = all_data, + port_list = NULL) { # generate plot setup list (same for all plot functions) setup <- ecodata::plot_setup(shadedRegion = shadedRegion, @@ -21,74 +39,67 @@ plot_wind_port <- function(shadedRegion = NULL, # which report? this may be bypassed for some figures if (report == "MidAtlantic") { filterEPUs <- c("MAB") + region <- "Mid Atlantic" } else { filterEPUs <- c("NE") + region <- "New England" + } + + data$lease_status <- factor(data$lease_status, + levels = c("All leases", + "Non-active leases", + "Active leases")) + + # filter to ports of interest + if(is.null(port_list)) { + data <- data |> + dplyr::filter(.data$region == report) + } else { + data <- data |> + dplyr::filter(PORT_STATE %in% port_list) } - # optional code to wrangle ecodata object prior to plotting - # e.g., calculate mean, max or other needed values to join below - fix <- ecodata::wind_port |> - dplyr::filter(EPU %in% filterEPUs) - fix <- tidyr::pivot_wider(fix,names_from = Var, values_from = Value) |> - dplyr::mutate(ordering = MaxVal, - City = paste0(City, ",", State), - perc_dif = c(perc_MAX - perc_MIN), - TOT_MAX = c(100 - perc_dif - perc_MIN)) - fix <- tidyr::pivot_longer(fix,cols = c(perc_MIN, perc_dif, TOT_MAX), names_to="Var", values_to = "Value") |> - dplyr::arrange(ordering) |> - dplyr::mutate(City = factor(City, levels = unique(City))) |> - dplyr::filter(!Var %in% c("EJ","Gentrification","MaxVal")) |> - dplyr::mutate(Var = dplyr::recode(Var,"perc_MIN"= "WEA Revenue" , - "perc_dif" ="WEA Revenue Range", - "TOT_MAX" = "Non-WEA Revenue"), - Var = factor(Var, levels = c("Non-WEA Revenue", - "WEA Revenue Range", - "WEA Revenue"))) + # order ports + port_order <- data |> + dplyr::filter(lease_status == "All leases") |> + dplyr::arrange(-avg_val) - # add EJ port symbols - df.symbol <- ecodata::wind_port |> - dplyr::filter(EPU %in% filterEPUs, - !Var %in% c("MaxVal", "TOT_MAX", - "perc_MIN", "perc_MAX")) |> - tidyr::pivot_wider( names_from = Var, values_from = Value) |> - dplyr::mutate(City = paste0(City,",",State)) |> - dplyr::select(City, EJ, Gentrification) |> - tidyr::pivot_longer(cols = c(EJ, Gentrification), names_to = "Variable") |> - dplyr::filter(!value == "NA") |> - dplyr::mutate(symbol = dplyr::recode(Variable, EJ = -7, Gentrification = -3), - Variable = dplyr::recode(Variable,"EJ"= "Mid-High to High Social-demographics Concerns" , - "Gentrification" ="Mid-High to High Gentrification Concerns")) + data$PORT_STATE <- factor(stringr::str_wrap(data$PORT_STATE, 20), + levels = stringr::str_wrap(port_order$PORT_STATE, 20)) + title <- ifelse(is.null(port_list), + paste(region, "Port Revenue from Wind Lease Areas"), + "Port Revenue from WEA, Majority NEFMC Species") - # 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 <- fix |> - ggplot2::ggplot()+ - ggplot2::geom_bar(ggplot2::aes(x = Value,y = City, fill=Var),stat="identity")+ - ggplot2::scale_fill_brewer()+ - ggplot2::theme(legend.position = "bottom", + plt <- data |> + # dplyr::filter(.data$region == report) |> + ggplot2::ggplot(ggplot2::aes(x = PORT_STATE, y = perc_AVG, fill = lease_status)) + + ggplot2::geom_col(position = ggplot2::position_dodge(width = 1, preserve = "single")) + + ggplot2::geom_errorbar(ggplot2::aes(ymin = perc_MIN, ymax = perc_MAX), + width = 0.5, + position = ggplot2::position_dodge(width = 1, preserve = "single"), + color = "gray20") + + ggplot2::scale_fill_manual(values = c("Active leases" = "#DB6015", + "Non-active leases" = "#002364", + "All leases" = "#4B8320")) + + # ggplot2::scale_x_discrete(drop = FALSE) + + ggplot2::theme_bw() + + ggplot2::coord_flip() + + ggplot2::facet_wrap(~PORT_STATE, + ncol = ifelse(is.null(port_list), 1, 1), + scales = "free_y") + + ggplot2::theme(strip.background = ggplot2::element_blank(), + strip.text = ggplot2::element_blank(), + axis.title.y = ggplot2::element_blank(), legend.title = ggplot2::element_blank(), - legend.box="vertical", legend.margin=ggplot2::margin())+ - ggplot2::geom_point(data = df.symbol, ggplot2::aes(x = symbol,y = City, shape = Variable)) + - ggplot2::scale_shape_manual(values = c(17, 16)) + - ggplot2::ggtitle(paste0(report,": Port Revenue from Leased Areas"))+ - ggplot2::xlab(expression("Port Revenue (%)"))+ - ggplot2::ylab(ggplot2::element_blank())+ - ecodata::theme_ts() + legend.position = "top", + panel.spacing = ggplot2::unit(2, "pt")) + + ggplot2::ylab("Percent revenue") + + ggplot2::ggtitle(title) - # optional code for New England specific (2 panel) formatting - # if (report == "NewEngland") { - # p <- p + - # ggplot2::theme(legend.position = "bottom", - # legend.title = ggplot2::element_blank()) - # - # } - - return(p) + return(plt) } + attr(plot_wind_port,"report") <- c("MidAtlantic","NewEngland") diff --git a/R/plot_wind_revenue.R b/R/plot_wind_revenue.R index 72ebca4b..d0a0cde8 100644 --- a/R/plot_wind_revenue.R +++ b/R/plot_wind_revenue.R @@ -96,6 +96,7 @@ plot_wind_revenue <- function(shadedRegion = NULL, ggplot2::ylab(wind_label)+ ggplot2::xlab(ggplot2::element_blank())+ ecodata::geom_lm(n=n)+ + ggplot2::theme(legend.position = "bottom")+ #ecodata::geom_gls()+ ecodata::theme_ts()+ diff --git a/R/plot_zoo_diversity.R b/R/plot_zoo_diversity.R index 2acb0c6a..65803ba2 100644 --- a/R/plot_zoo_diversity.R +++ b/R/plot_zoo_diversity.R @@ -56,16 +56,9 @@ plot_zoo_diversity <- function(shadedRegion = NULL, ymin = -Inf, ymax = Inf) + ggplot2::geom_point()+ ggplot2::geom_line()+ - - ggplot2::ylab("Zooplankton Diversity (Shannon)")+ - ggplot2::xlab(ggplot2::element_blank()) - - #if(report == "MidAtlantic"){ - # p <- p + ggplot2::ggtitle("MAB Zooplankton Diversity") - #} else { - p <- p + ggplot2::facet_wrap(~EPU,scales = "free_y")#,labeller = to_string) - #} - + ggplot2::ggtitle("Zooplankton Diversity")+ + ggplot2::xlab(ggplot2::element_blank())+ + ggplot2::ylab("Zooplankton Diversity Shannon") p <- p + ggplot2::geom_hline(ggplot2::aes(yintercept = mn), linewidth = setup$hline.size, @@ -77,6 +70,14 @@ plot_zoo_diversity <- function(shadedRegion = NULL, ecodata::theme_facet()+ ecodata::theme_title() + if (region == "MidAtlantic") { + p <- p + + ggplot2::ylab("Shannon Index") + } + else { + p <- p + + ggplot2::facet_wrap(~EPU, nrow = 2) + } # # optional code for New England specific (2 panel) formatting # if (report == "NewEngland") { # p <- p + diff --git a/R/plot_zooplankton_index.R b/R/plot_zooplankton_index.R index 88b5c9e8..f1102702 100644 --- a/R/plot_zooplankton_index.R +++ b/R/plot_zooplankton_index.R @@ -68,10 +68,11 @@ plot_zooplankton_index <- function(shadedRegion = NULL, xmin = setup$x.shade.min , xmax = setup$x.shade.max, ymin = -Inf, ymax = Inf) + ggplot2::geom_ribbon(ggplot2::aes(ymin = Lower, ymax = Upper, fill = Season), alpha = 0.5)+ - ggplot2::geom_point()+ - ggplot2::geom_line()+ + ggplot2::theme(strip.text.x = ggplot2::element_blank()) + + ggplot2::geom_point(ggplot2::aes(color = .data$Season)) + + ggplot2::geom_line(ggplot2::aes(color = .data$Season)) + ggplot2::ggtitle("")+ - ggplot2::ylab(paste("Relative",varName,"Biomass"))+ + ggplot2::ylab("Relative Biomass") + ggplot2::xlab(ggplot2::element_blank())+ ggplot2::facet_wrap(.~EPU)+ ecodata::geom_gls()+ @@ -80,6 +81,22 @@ plot_zooplankton_index <- function(shadedRegion = NULL, ecodata::theme_facet()+ ecodata::theme_title() + if (varName == "Lgcopeall") { + p <- p + + ggplot2::labs(title = "Large Copepods") + } + + if (varName == "Smallcopeall") { + p <- p + + ggplot2::labs(title = "Small Copepods") + } + + if (varName == "Euph") { + p <- p + + ggplot2::labs(title = "Euphausiids") + + ggplot2::theme(legend.background = ggplot2::element_rect(fill = "white")) + } + if (report == "NewEngland") { p <- p + ggplot2::theme(legend.position = "bottom", @@ -120,7 +137,8 @@ plot_zooplankton_index <- function(shadedRegion = NULL, ecodata::geom_lm(n=n)+ ecodata::theme_ts()+ ecodata::theme_facet()+ - ecodata::theme_title() + ecodata::theme_title() + + ggplot2::theme(legend.position = 'bottom') } diff --git a/ecodata.Rproj b/ecodata.Rproj index 526ad2d0..81cc8f73 100644 --- a/ecodata.Rproj +++ b/ecodata.Rproj @@ -1,4 +1,5 @@ Version: 1.0 +ProjectId: 88c7df74-f45c-4db2-8c86-f42fe89744ab RestoreWorkspace: Default SaveWorkspace: Default