diff --git a/R/theme_noaa.R b/R/theme_noaa.R index f502a6e4..6991e44b 100644 --- a/R/theme_noaa.R +++ b/R/theme_noaa.R @@ -17,20 +17,39 @@ #' ) + #' ggplot2::geom_point() + #' theme_noaa() -#' \dontrun{ -#' ggplot2::theme_set(stockplotr::theme_noaa()) -#' } +#' +#' ggplot2::ggplot( +#' data = OrchardSprays, +#' ggplot2::aes( +#' x = rowpos, +#' y = decrease, +#' color = decrease +#' ) +#' ) + +#' ggplot2::geom_point() + +#' theme_noaa(discrete = FALSE) +#'\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."), + cli::cli_warn( + "Your {.pkg ggplot2} version is {.val {utils::packageVersion('ggplot2')}}, + which is older than the version required to use {.fn theme_noaa} (4.0.0). + Please update your {.pkg ggplot2} package.", .frequency = "once", .frequency_id = "ggplot2_version_warning" ) } - - theme <- ggplot2::theme_bw() + + + mako_pal_discrete <- scales::pal_viridis(begin = 0.1, end = 0.85, option = "G") + + mako_pal_continuous <- scales::gradient_n_pal( + scales::pal_viridis(begin = 0.1, end = 0.85, option = "G")(6) + ) + + thm <- ggplot2::theme_bw() + ggplot2::theme( plot.background = ggplot2::element_rect(fill = "transparent"), panel.background = ggplot2::element_rect(fill = "transparent"), @@ -40,23 +59,17 @@ theme_noaa <- function(discrete = TRUE, 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 - ) + thm <- thm + ggplot2::theme( + palette.colour.discrete = mako_pal_discrete, + palette.fill.discrete = mako_pal_discrete + ) } else { - theme <- theme + - ggplot2::theme( - palette.colour.continuous = pal, - palette.fill.continuous = pal - ) + thm <- thm + ggplot2::theme( + palette.colour.continuous = mako_pal_continuous, + palette.fill.continuous = mako_pal_continuous + ) } - - theme + thm } diff --git a/man/theme_noaa.Rd b/man/theme_noaa.Rd index c23e3612..4117fd89 100644 --- a/man/theme_noaa.Rd +++ b/man/theme_noaa.Rd @@ -28,7 +28,18 @@ ggplot2::ggplot( ) + ggplot2::geom_point() + theme_noaa() + +ggplot2::ggplot( + data = OrchardSprays, + ggplot2::aes( + x = rowpos, + y = decrease, + color = decrease + ) +) + + ggplot2::geom_point() + + theme_noaa(discrete = FALSE) \dontrun{ -ggplot2::theme_set(stockplotr::theme_noaa()) + ggplot2::theme_set(stockplotr::theme_noaa()) } }