Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Imports:
dplyr,
flextable,
fs,
ggplot2,
ggplot2 (>= 4.0.0),
glue,
gt,
httr,
Expand Down
65 changes: 32 additions & 33 deletions R/theme_noaa.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,47 @@
#' ) +
#' ggplot2::geom_point() +
#' theme_noaa()
#'\dontrun{
#' ggplot2::theme_set(stockplotr::theme_noaa())
#'}
theme_noaa <- function(discrete = TRUE,
...) {
theme <- list(
# might not need the ggplot2 dependencies if make this pkg an extension

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."),
.frequency = "once",
.frequency_id = "ggplot2_version_warning"
)
}

theme <- ggplot2::theme_bw() +
ggplot2::theme(
plot.background = ggplot2::element_rect(fill = "transparent"),
panel.background = ggplot2::element_rect(fill = "transparent"),
panel.grid = ggplot2::element_blank(),
panel.border = ggplot2::element_rect(colour = "black", fill = NA, linewidth = 0.5),
complete = TRUE,
text = ggplot2::element_text(size = 14),
plot.margin = ggplot2::margin(0.5, 1, 0.5, 0.5, "cm")
)
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) {
list(
theme,
ggplot2::scale_color_viridis_d(
option = "mako",
begin = 0.1,
end = 0.85
),
ggplot2::scale_fill_viridis_d(
option = "mako",
begin = 0.1,
end = 0.85
)
)
} else {
list(
theme,
ggplot2::scale_color_viridis_c(
option = "mako",
begin = 0.1,
end = 0.85
),
ggplot2::scale_fill_viridis_c(
option = "mako",
begin = 0.1,
end = 0.85
)
)
}
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
)
}

theme
}
2 changes: 1 addition & 1 deletion tests/testthat/test-plot_abundance_at_age.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,5 @@ test_that("plot contains a legend", {
make_rda = FALSE,
figures_dir = getwd()
)
expect_true(is.null(plot$theme$legend.position))
expect_true(!is.null(plot$theme$legend.position))
})
2 changes: 1 addition & 1 deletion tests/testthat/test-plot_biomass_at_age.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,5 @@ test_that("plot contains a legend", {
make_rda = FALSE,
figures_dir = getwd()
)
expect_true(is.null(plot$theme$legend.position))
expect_true(!is.null(plot$theme$legend.position))
})
2 changes: 1 addition & 1 deletion tests/testthat/test-plot_catch_comp.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ test_that("plot contains a legend", {
make_rda = FALSE,
figures_dir = getwd()
)
expect_true(is.null(plot$theme$legend.position))
expect_true(!is.null(plot$theme$legend.position))
})

test_that("year class lines are plotted", {
Expand Down
Loading