diff --git a/R/plot_biomass_at_age.R b/R/plot_biomass_at_age.R index a2417982..041dfac7 100644 --- a/R/plot_biomass_at_age.R +++ b/R/plot_biomass_at_age.R @@ -98,7 +98,7 @@ plot_biomass_at_age <- function( create_rda( object = plot, # get name of function and remove "plot_" from it - topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), + topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), fig_or_table = "figure", dat, unit_label = "mt" diff --git a/R/plot_catch_comp.R b/R/plot_catch_comp.R index 4fc178ae..13b3f6fe 100644 --- a/R/plot_catch_comp.R +++ b/R/plot_catch_comp.R @@ -114,7 +114,7 @@ plot_catch_comp <- function( create_rda( object = plot, # get name of function and remove "plot_" from it - topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), + topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), fig_or_table = "figure", dat, unit_label = "mt" diff --git a/R/plot_indices.R b/R/plot_indices.R index 2f2040d4..e0ff78e7 100644 --- a/R/plot_indices.R +++ b/R/plot_indices.R @@ -117,7 +117,7 @@ plot_indices <- function( create_rda( object = plt, # get name of function and remove "plot_" from it - topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), + topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), fig_or_table = "figure", dat = dat, dir = figures_dir, diff --git a/R/plot_landings.R b/R/plot_landings.R index 04dec696..becf7cd0 100644 --- a/R/plot_landings.R +++ b/R/plot_landings.R @@ -102,7 +102,7 @@ plot_landings <- function( create_rda( object = plt, # get name of function and remove "plot_" from it - topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), + topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), fig_or_table = "figure", dat = dat, dir = figures_dir, diff --git a/R/plot_natural_mortality.R b/R/plot_natural_mortality.R index 25d5bf5d..9e496123 100644 --- a/R/plot_natural_mortality.R +++ b/R/plot_natural_mortality.R @@ -105,7 +105,7 @@ plot_natural_mortality <- function( create_rda( object = final, # get name of function and remove "plot_" from it - topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), + topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), fig_or_table = "figure", dat = dat, dir = figures_dir diff --git a/R/plot_recruitment.R b/R/plot_recruitment.R index a6de07de..5728113c 100644 --- a/R/plot_recruitment.R +++ b/R/plot_recruitment.R @@ -147,7 +147,7 @@ plot_recruitment <- function( create_rda( object = final, # get name of function and remove "plot_" from it - topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), + topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), fig_or_table = "figure", dat = dat, dir = figures_dir # , diff --git a/R/plot_recruitment_deviations.R b/R/plot_recruitment_deviations.R index acaf86ac..1d50d0d4 100644 --- a/R/plot_recruitment_deviations.R +++ b/R/plot_recruitment_deviations.R @@ -103,7 +103,7 @@ plot_recruitment_deviations <- function( create_rda( object = final, # get name of function and remove "plot_" from it - topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), + topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), fig_or_table = "figure", dat = selected_dat, dir = figures_dir, diff --git a/R/plot_stock_recruitment.R b/R/plot_stock_recruitment.R index 8a9ea0b7..577d3164 100644 --- a/R/plot_stock_recruitment.R +++ b/R/plot_stock_recruitment.R @@ -130,7 +130,7 @@ plot_stock_recruitment <- function( create_rda( object = final, # get name of function and remove "plot_" from it - topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), + topic_label = gsub("plot_", "", as.character(sys.call()[[1]])), fig_or_table = "figure", dat = dat, dir = figures_dir # , diff --git a/R/table_bnc.R b/R/table_bnc.R index 0881d1a7..41d60021 100644 --- a/R/table_bnc.R +++ b/R/table_bnc.R @@ -179,13 +179,13 @@ # fig_or_table = fig_or_table, # dir = tables_dir # ) -# +# # export_rda( # object = final, # caps_alttext = caps_alttext, # figures_tables_dir = tables_dir, # # get name of function and remove "table_" from it -# topic_label = gsub("table_", "", as.character(sys.call()[[1]])), +# topic_label = gsub("table_", "", as.character(sys.call()[[1]])), # fig_or_table = fig_or_table # ) # } diff --git a/R/table_indices.R b/R/table_indices.R index fe2d58c7..1d86553d 100644 --- a/R/table_indices.R +++ b/R/table_indices.R @@ -155,14 +155,14 @@ # ) - # export_rda( - # object = final, - # caps_alttext = caps_alttext, - # figures_tables_dir = tables_dir, - # # get name of function and remove "table_" from it - # topic_label = gsub("table_", "", as.character(sys.call()[[1]])), - # fig_or_table = fig_or_table - # ) +# export_rda( +# object = final, +# caps_alttext = caps_alttext, +# figures_tables_dir = tables_dir, +# # get name of function and remove "table_" from it +# topic_label = gsub("table_", "", as.character(sys.call()[[1]])), +# fig_or_table = fig_or_table +# ) # } # final # } diff --git a/R/theme_noaa.R b/R/theme_noaa.R index 6d9a2f00..f502a6e4 100644 --- a/R/theme_noaa.R +++ b/R/theme_noaa.R @@ -17,12 +17,11 @@ #' ) + #' ggplot2::geom_point() + #' theme_noaa() -#'\dontrun{ -#' ggplot2::theme_set(stockplotr::theme_noaa()) -#'} +#' \dontrun{ +#' ggplot2::theme_set(stockplotr::theme_noaa()) +#' } theme_noaa <- function(discrete = TRUE, ...) { - if (utils::packageVersion("ggplot2") < "4.0.0") { rlang::warn( message = paste0("Your `ggplot2` version is ", utils::packageVersion("ggplot2"), ", which is older than the version required to use `theme_noaa()` (4.0.0). Please update your `ggplot2` package."), @@ -30,7 +29,7 @@ theme_noaa <- function(discrete = TRUE, .frequency_id = "ggplot2_version_warning" ) } - + theme <- ggplot2::theme_bw() + ggplot2::theme( plot.background = ggplot2::element_rect(fill = "transparent"), @@ -40,24 +39,24 @@ theme_noaa <- function(discrete = TRUE, text = ggplot2::element_text(size = 14), plot.margin = ggplot2::margin(0.5, 1, 0.5, 0.5, "cm"), ... - ) + ) # create main palette pal <- function(n) viridisLite::mako(n, begin = 0.1, end = 0.85) - + if (discrete) { theme <- theme + ggplot2::theme( - palette.colour.discrete = pal, - palette.fill.discrete = pal - ) - } else { - theme <- theme + - ggplot2::theme( - palette.colour.continuous = pal, - palette.fill.continuous = pal - ) - } - + palette.colour.discrete = pal, + palette.fill.discrete = pal + ) + } else { + theme <- theme + + ggplot2::theme( + palette.colour.continuous = pal, + palette.fill.continuous = pal + ) + } + theme } diff --git a/R/utils_rda.R b/R/utils_rda.R index dadddb23..6d513427 100644 --- a/R/utils_rda.R +++ b/R/utils_rda.R @@ -195,10 +195,10 @@ add_more_key_quants <- function( # write analogous code for each in this section, and remove placeholders from # the end of write_captions (once we get clarity about how to extract Btarg, # ssbtarg, and R0) - # - - #TODO: When adding code extracting values for landings and/or indices figures/tables, be aware that both figure/table share the same label ("landings" and "indices"). If there's reason, add in extra conditional to check if value is from a figure or table - + # + + # TODO: When adding code extracting values for landings and/or indices figures/tables, be aware that both figure/table share the same label ("landings" and "indices"). If there's reason, add in extra conditional to check if value is from a figure or table + ## biomass if (topic_cap_alt$label == "biomass") { if (is.null(dat)) { diff --git a/man/theme_noaa.Rd b/man/theme_noaa.Rd index 2b77149e..c23e3612 100644 --- a/man/theme_noaa.Rd +++ b/man/theme_noaa.Rd @@ -28,4 +28,7 @@ ggplot2::ggplot( ) + ggplot2::geom_point() + theme_noaa() +\dontrun{ +ggplot2::theme_set(stockplotr::theme_noaa()) +} } diff --git a/tests/testthat/test-save_all_plots.R b/tests/testthat/test-save_all_plots.R index 0de5c96e..909b5198 100644 --- a/tests/testthat/test-save_all_plots.R +++ b/tests/testthat/test-save_all_plots.R @@ -40,16 +40,16 @@ test_that("save_all_plots works when all figures/tables are plotted", { sort(fig_base_temp_files) ) - # # expect that the tables are all created with expected names - # tab_base_temp_files <- c( - # # "bnc_table.rda", - # # "indices.abundance_table.rda", - # "landings_table.rda" - # ) - # expect_equal( - # list.files(fs::path(getwd(), "tables")), - # tab_base_temp_files - # ) + # # expect that the tables are all created with expected names + # tab_base_temp_files <- c( + # # "bnc_table.rda", + # # "indices.abundance_table.rda", + # "landings_table.rda" + # ) + # expect_equal( + # list.files(fs::path(getwd(), "tables")), + # tab_base_temp_files + # ) # erase temporary testing files file.remove(fs::path(getwd(), "captions_alt_text.csv"))