Skip to content

Commit

Permalink
Merge pull request #131 from NOAA-EDAB/dev
Browse files Browse the repository at this point in the history
Update master with all data and plot corrections in dev as of Feb 8
  • Loading branch information
andybeet authored Feb 8, 2024
2 parents 5cb4845 + 6f9dd73 commit c04d7ab
Show file tree
Hide file tree
Showing 21 changed files with 171 additions and 53 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ Suggests:
zoo,
rlang
VignetteBuilder: knitr
RoxygenNote: 7.3.0
RoxygenNote: 7.3.1
Depends:
R (>= 2.10)
5 changes: 2 additions & 3 deletions R/ecodata.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
#'To learn more about using \code{ecodata}, start with the vignette: \code{browseVignettes(package="ecodata")} or click the index link below
#'
#'
#' @docType package
#' @name ecodata
NULL
"_PACKAGE"

10 changes: 8 additions & 2 deletions R/plot_bottom_temp_seasonal_gridded.r
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plot_bottom_temp_seasonal_gridded <- function(shadedRegion = NULL,
xmin = -77
xmax = -66
ymin = 35.5
ymax = 43
ymax = 45
xlims <- c(xmin, xmax)
ylims <- c(ymin, ymax)

Expand Down Expand Up @@ -58,7 +58,13 @@ plot_bottom_temp_seasonal_gridded <- function(shadedRegion = NULL,
ggplot2::coord_sf(xlim = xlims, ylim = ylims) +
ggplot2::facet_wrap(Var~.)+
ecodata::theme_map() +
#ggplot2::scale_fill_viridis_c(option = 'A',name = 'Bottom \n Temp')+
#ggplot2::scale_fill_gradient2(name = 'Bottom \n Temp',
#low = scales::muted("blue"),
#mid = "white",
#high = scales::muted("red"),
#limits = c(5,25),
#labels = c("5", "10", "15", "20", "25")) +
ggplot2::scale_fill_viridis_c(option = 'B',name = 'Bottom \n Temp')+
ggplot2::ggtitle('Seasonal Mean Bottom Temperature')+
ggplot2::xlab("Longitude") +
ggplot2::ylab("Latitude") +
Expand Down
4 changes: 2 additions & 2 deletions R/plot_habitat_diversity.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ plot_habitat_diversity <- function(shadedRegion = NULL,
#ggplot2::geom_ribbon(ggplot2::aes(ymin = Lower, ymax = Upper), alpha = 0.5)+
ggplot2::geom_point()+
ggplot2::geom_line()+
ggplot2::geom_point(data = fix, aes(x = Time, y = mean), size = setup$line.size)+
ggplot2::geom_line(data = fix, aes(x = Time, y = mean), linewidth = setup$line.size)+
ggplot2::geom_point(data = fix, ggplot2::aes(x = Time, y = mean), size = setup$line.size)+
ggplot2::geom_line(data = fix, ggplot2::aes(x = Time, y = mean), linewidth = setup$line.size)+
ggplot2::ggtitle(paste(report,"Species Shannon Diversity from Habitat Assessment"))+
ggplot2::ylab("Shannon Diversity")+
ggplot2::xlab(ggplot2::element_blank())+
Expand Down
10 changes: 5 additions & 5 deletions R/plot_hms_stock_status.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ plot_hms_stock_status <- function(shadedRegion = NULL,
#(B.Bmsy == 0.5) ~"a",
#(B.Bmsy <1) ~"a",
#(B.Bmsy == 1) ~"a",
(F.Fmsy == 1) ~ "a",
(F.Fmsy >1) ~ "a",
#(F.Fmsy == 1) ~ "a",
#(F.Fmsy >1) ~ "a",
#(F.Fmsy < 1 & B.Bmsy > 0.5 & B.Bmsy < 1) ~ "b",
(F.Fmsy < 1 & B.Bmsy < 1) ~ "b",
(F.Fmsy < 1 & B.Bmsy > 1) ~ "c"))
(F.Fmsy > 1 | B.Bmsy < 1) ~ "b",
(F.Fmsy < 1 & B.Bmsy > 1) ~ "a"))

unknown <- stock_status |>
dplyr::filter(is.na(F.Fmsy) | is.na(B.Bmsy)) |>
Expand Down Expand Up @@ -85,7 +85,7 @@ plot_hms_stock_status <- function(shadedRegion = NULL,
ggplot2::geom_text(data = unknownp, ggplot2::aes(x = x, y = y, label = text), #Custom legend for unknown stock status
size = c(4.75,rep(4,3))) +
ggplot2::annotate(geom="text", x=0.43, y=5, label="ATL SBN (F/Fmsy = 22.5)",
color="#1B9E77")+
color="#D95F02")+
ggplot2::scale_color_brewer(palette = "Dark2", #Change legend labels for clarity
breaks = stock_status$score) +
ggplot2::xlab(expression(~B/B[msy])) +
Expand Down
5 changes: 4 additions & 1 deletion R/plot_species_dist.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ plot_species_dist <- function(shadedRegion = NULL,
if (report == "MidAtlantic") {
filterEPUs <- c("MAB")
} else {
stop("This is a shelfwide indicator only used in the MidAtlantic report")
returnMessage <- "This is a shelfwide indicator only used in the MidAtlantic report"
filterEPUs <- c("GB", "GOM")
}

Expand Down Expand Up @@ -85,6 +85,9 @@ plot_species_dist <- function(shadedRegion = NULL,
#
# }

if (report == "NewEngland"){
p <- returnMessage
}
return(p)

}
Expand Down
15 changes: 11 additions & 4 deletions R/plot_species_groupings.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,28 @@ plot_species_groupings <- function(shadedRegion = NULL,
dplyr::distinct() |>
dplyr::group_by(dplyr::across(varName), Fed.Managed) |>
dplyr::summarize_all(dplyr::funs(paste(na.omit(.), collapse = ", "))) |>
dplyr::ungroup() |>
tidyr::spread(Fed.Managed, COMNAME) |>
dplyr::arrange(factor(get(varName), levels = c("Apex Predator", "Piscivore", "Planktivore", "Benthivore", "Benthos")))
fix<-fix[c(1,3,2,4,5)] |>
dplyr::mutate_all(tolower)
dplyr::arrange(factor(get(varName), levels = c("Apex Predator", "Piscivore", "Planktivore", "Benthivore", "Benthos"))) |>
dplyr::mutate(dplyr::across(dplyr::everything(), tolower)) |>
dplyr::rename(Guild = !!varName,
Joint = JOINT) |>
dplyr::relocate(Guild,MAFMC,Joint)

# fix<-fix[c(1,3,2,4,5)] |>
# dplyr::mutate_all(tolower)

# 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 <- flextable::flextable(fix) |>
flextable::set_caption('Feeding guilds and management bodies.') |>
flextable::fontsize(size=8, part = "all") |>
flextable::set_header_labels(SOE.20 = "Guild",
flextable::set_header_labels(SOE.24 = "Guild",
MAFMC = "MAFMC",
JOINT = "Joint",
NEFMC = "NEFMC",
Expand Down
18 changes: 12 additions & 6 deletions R/plot_wind_revenue.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,26 @@ plot_wind_revenue <- function(shadedRegion = NULL,
# e.g., calculate mean, max or other needed values to join below
fix <- tidyr::separate(ecodata::wind_revenue,col=Var, into = c("Species", "Var"),sep = "-sum_") |>
dplyr::filter(Var == varName) |>
dplyr::mutate(Value = Value/1000000,
Time = as.integer(Time)) |>
dplyr::mutate(Value = Value/1000000) |>
dplyr::mutate(Species = dplyr::recode(Species,"MONK"="MONKFISH"))

# Code to determine units displayed on y axis
if (varName == "landing") {
wind_label <- "Landings (million lbs)"
} else {
wind_label <- "Revenue (millions $2022)"
}

if (report == "MidAtlantic") {
fix <- fix |>
dplyr::filter(EPU %in% filterEPUs,
Species %in% c("LONGFIN SQUID","MONKFISH","SUMMER FLOUNDER",
"OCEAN QUAHOG", "SURF CLAM" )) |>
"OCEAN QUAHOG", "SURFCLAM" )) |>
dplyr::mutate(Species = stringr::str_to_sentence(Species))
} else if (report == "NewEngland") {
fix <- fix |>
dplyr::filter(EPU %in% filterEPUs,
Species %in% c("ATLANTIC HERRING","MONKFISH","SEA SCALLOP",
Species %in% c("ATLANTIC HERRING","MONKFISH","ATLANTIC SEA SCALLOP",
"SILVER HAKE", "SKATES" )) |>
dplyr::mutate(Species = stringr::str_to_sentence(Species))
}
Expand All @@ -67,7 +73,7 @@ plot_wind_revenue <- function(shadedRegion = NULL,
ggplot2::geom_point()+
ggplot2::geom_line()+
ggplot2::ggtitle(paste0(report,": Fishery Revenue in Wind Lease Areas"))+
ggplot2::ylab(expression("Dollars (millions)"))+
ggplot2::ylab(wind_label)+
ggplot2::xlab(ggplot2::element_blank())+
ggplot2::facet_wrap(.~Species,scales = "free_y") +
#ecodata::geom_gls()+
Expand All @@ -83,7 +89,7 @@ plot_wind_revenue <- function(shadedRegion = NULL,
ggplot2::geom_point()+
ggplot2::geom_line()+
ggplot2::ggtitle(paste0(report,": Fishery Revenue in Wind Lease Areas"))+
ggplot2::ylab(expression("Dollars (millions)"))+
ggplot2::ylab(wind_label)+
ggplot2::xlab(ggplot2::element_blank())+

#ecodata::geom_gls()+
Expand Down
14 changes: 8 additions & 6 deletions R/plot_zoo_abundance_anom.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#'
#' @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 ("copepod","euphasid")
#' @param varName Character string. Which variable to plot ("copepod","euphausid")
#' @return ggplot object
#'
#'
Expand All @@ -29,12 +29,12 @@ plot_zoo_abundance_anom <- function(shadedRegion = NULL,
if (varName == "copepod") {
varName <- "large-bodied|small-bodied"
vtitle <- "Small and large-bodied copepod abundance anomaly"
} else if (varName == "euphasid") {
} else if (varName == "euphausid") {
varName <- "Euphausiacea|Cnidaria"
vtitle <- "Zooplankton abundance anomaly"

} else {
stop("Please select either 'copepod' or 'euphasid'")
stop("Please select either 'copepod' or 'euphausid'")
}

# optional code to wrangle ecodata object prior to plotting
Expand Down Expand Up @@ -67,10 +67,12 @@ plot_zoo_abundance_anom <- function(shadedRegion = NULL,
linewidth = setup$hline.size,
alpha = setup$hline.alpha,
linetype = setup$hline.lty)+
ggplot2::facet_wrap(~EPU,ncol = 1)+
ggplot2::facet_wrap(~EPU~Var)+
ecodata::geom_gls() +
ecodata::theme_ts()+
ecodata::theme_facet()+
ggplot2::theme(legend.title = ggplot2::element_blank()) +
ggplot2::theme(legend.title = ggplot2::element_blank(),
legend.position = "none") +
ecodata::theme_title()

# optional code for New England specific (2 panel) formatting
Expand All @@ -85,5 +87,5 @@ plot_zoo_abundance_anom <- function(shadedRegion = NULL,

}

attr(plot_zoo_abundance_anom,"varName") <- c("copepod","euphasid")
attr(plot_zoo_abundance_anom,"varName") <- c("copepod","euphausid")
attr(plot_zoo_abundance_anom,"report") <- c("MidAtlantic","NewEngland")
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
GARFO and ASMFC Managed Species,Maximum Percent Total Annual Regional Species Landings,Maximum Percent Total Annual Regional Species Revenue
Redfish,0.537737474,0.531995934
Pollock,0.403607303,0.427294448
White hake,0.33995244,0.3354793
American plaice,0.280356165,0.262408696
Witch flounder,0.225986683,0.25206003
Haddock,0.227643039,0.239032168
Atlantic halibut,0.235914109,0.228287263
Monkfish ,0.199184927,0.196783891
Skate species,0.29,0.3
Atlantic surfclam,0.168852126,0.175173059
Yellowtail flounder,0.152951316,0.149214693
Offshore hake,0.046486926,0.14593979
Atlantic cod,0.149582482,0.145768893
Atlantic menhaden**,0.134323765,0.141880564
American shad*,0.027404255,0.135030286
Red hake,0.078440074,0.112420702
Atlantic sea scallop,0.090517481,0.100980112
Black sea bass,0.097270244,0.099990201
American eel**,0.097294616,0.093826996
Silver hake,0.068394326,0.086802419
Longfin squid,0.080603421,0.082009373
Scup,0.085717641,0.080968966
Atlantic mackerel,0.084275349,0.077206562
Butterfish,0.049862166,0.060246321
Golden Tilefish,0.060738847,0.057944899
Chub mackerel,0.061197443,0.055954247
Winter flounder,0.053520349,0.054544782
Summer flounder,0.04919601,0.054018854
American lobster**,0.060314547,0.054010744
Jonah crab**,0.053231914,0.053091491
Tautog**,0.04324992,0.050759331
Atlantic herring,0.04220826,0.049413471
Bluefish,0.042752088,0.043543898
Windowpane flounder,0.025095714,0.039795363
Spiny dogfish,0.038110711,0.035157093
Ocean quahog,0.031717511,0.032185999
Horseshoe crab**,0.034464121,0.031248412
Cobia*,0.032581567,0.029428304
Atlantic croaker**,0.017050712,0.017970042
Illex squid,0.018699965,0.016932307
Striped bass,0.022556611,0.015895645
Black drum*,0.008870124,0.009620579
Weakfish*,0.008332349,0.007344359
Spot**,0.003224814,0.003402403
Hickory shad*,0.005227273,0.001179856
,,
,,
,,
,,
,,
,,
,,
,,
,,
42 changes: 27 additions & 15 deletions data-raw/get_wea_landings_rev.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,45 @@ raw.dir <- here::here("data-raw")

## Doug Christel
#wind_xlsx<-"CHRISTEL_2022 State of the Ecosystem Report_Max WEA Species Landings and Revenue.xlsx"
wind_xlsx<-"SOE 2023 update_Offshore Wind Fishery Data_Christel (3).xlsx"
wind_rev_xlsx<-"Fishery Impacts from OSW Development_2023 SOE Report_Christel_UPDATED.xlsx"
get_wea_landings_rev <- function(save_clean = F){
# import data
wea_landings_rev<-readxl::read_excel(file.path(raw.dir,wind_xlsx), sheet = "Highest % Rev Table") %>%
wea_landings_rev<-readxl::read_excel(file.path(raw.dir,wind_rev_xlsx),
sheet = "Cumulative Max Rev and Land") %>%
# janitor::row_to_names(.,1) %>%
# select("Max % Regional Revenue and Landings of fisheries managed by the Atlantic States Marine Fisheries Commission and the New England and Mid-Atlantic Fishery Management Council within Existing Lease Areas and the Draft Primary and Secondary Central Atlantic Call Areas")

janitor::row_to_names(.,3) %>%
dplyr::select( "NEFMC, MAFMC, and ASMFC Managed Species",
"Maximum Percent Total Annual Regional Species Landings",
"Maximum Percent Total Annual Regional Species Revenue") %>%
dplyr::rename("perc_landings_max" = "Maximum Percent Total Annual Regional Species Landings",
"perc_revenue_max" = "Maximum Percent Total Annual Regional Species Revenue" ) %>%
dplyr::select( "NEFMC and MAFMC Managed Species",
"Maximum Percent Total Annual Regional Species Landings...9",
"Maximum Percent Total Annual Regional Species Revenue...8") %>%
dplyr::rename("NEFMC, MAFMC, and ASMFC Managed Species" = "NEFMC and MAFMC Managed Species",
"perc_landings_max" = "Maximum Percent Total Annual Regional Species Landings...9",
"perc_revenue_max" = "Maximum Percent Total Annual Regional Species Revenue...8") %>%
tidyr::drop_na() %>%
dplyr::mutate(perc_landings_max = as.numeric(perc_landings_max)*100,
perc_revenue_max = as.numeric(perc_revenue_max)*100,
Units = c("Percent"))
Units = c("Percent")) %>%
dplyr::mutate(across(where(is.numeric), ~round(., 0))) %>%
dplyr::mutate(Council = "NEFSC")

# Add council data to dataset
mafmc <- list("Atlantic mackerel", "Black sea bass", "Bluefish", "Blueline tilefish", "Butterfish",
"Atlantic chub mackerel", "Golden tilefish", "Illex squid", "Longfin squid",
"Ocean quahog", "Scup", "Summer flounder", "Atlantic surfclam")

for (i in 1:length(mafmc)){
wea_landings_rev <- wea_landings_rev %>%
dplyr::mutate(Council = replace(Council, wea_landings_rev$`NEFMC, MAFMC, and ASMFC Managed Species` == mafmc[i], "MAFMC"))
}

wea_landings_rev <- wea_landings_rev %>%
dplyr::mutate(Council = replace(Council, wea_landings_rev$`NEFMC, MAFMC, and ASMFC Managed Species` == "Monkfish", "MAFMC/NEFMC")) %>%
dplyr::mutate(Council = replace(Council, wea_landings_rev$`NEFMC, MAFMC, and ASMFC Managed Species` == "Spiny dogfish", "MAFMC/NEFMC"))

# metadata ----
attr(wea_landings_rev, "tech-doc_url") <- "https://noaa-edab.github.io/tech-doc/fisheries-revenue-in-wind-development-areas.html"
attr(wea_landings_rev, "data_files") <- list(
wind_xlsx = wind_xlsx)
wind_rev_xlsx = wind_rev_xlsx)
attr(wea_landings_rev, "data_steward") <- c(
"Doug Christel <[email protected]>")
attr(wea_landings_rev, "plot_script") <- list(
Expand All @@ -45,8 +62,3 @@ get_wea_landings_rev <- function(save_clean = F){
}
}
get_wea_landings_rev(save_clean = T)





Loading

0 comments on commit c04d7ab

Please sign in to comment.