diff --git a/DESCRIPTION b/DESCRIPTION index 1ce0af70d4..3b4b20a5cf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -39,7 +39,7 @@ Imports: isoband, lifecycle (> 1.0.1), rlang (>= 1.1.0), - scales (>= 1.3.0), + scales (>= 1.4.0), stats, vctrs (>= 0.6.0), withr (>= 2.5.0) diff --git a/R/geom-sf.R b/R/geom-sf.R index 448329dd79..177c30f933 100644 --- a/R/geom-sf.R +++ b/R/geom-sf.R @@ -171,7 +171,7 @@ GeomSf <- ggproto("GeomSf", Geom, other_default <- modify_list( GeomPolygon$default_aes, aes( - fill = from_theme(fill %||% col_mix(ink, paper, 0.9)), + fill = from_theme(fill %||% col_mix(ink, paper, 0.899)), colour = from_theme(colour %||% col_mix(ink, paper, 0.35)), linewidth = from_theme(0.4 * borderwidth) ) diff --git a/R/theme-defaults.R b/R/theme-defaults.R index 6f32012cd0..7b5bb286f7 100644 --- a/R/theme-defaults.R +++ b/R/theme-defaults.R @@ -167,7 +167,7 @@ theme_grey <- function(base_size = 11, base_family = "", axis.line = element_blank(), axis.line.x = NULL, axis.line.y = NULL, - axis.text = element_text(size = rel(0.8), colour = col_mix(ink, paper, 0.305)), + axis.text = element_text(size = rel(0.8), colour = col_mix(ink, paper, 0.302)), axis.text.x = element_text(margin = margin(t = 0.8 * half_line / 2), vjust = 1), axis.text.x.top = element_text(margin = margin(b = 0.8 * half_line / 2), vjust = 0), axis.text.y = element_text(margin = margin(r = 0.8 * half_line / 2), hjust = 1), @@ -223,7 +223,7 @@ theme_grey <- function(base_size = 11, base_family = "", legend.box.background = element_blank(), legend.box.spacing = rel(2), - panel.background = element_rect(fill = col_mix(ink, paper, 0.925), colour = NA), + panel.background = element_rect(fill = col_mix(ink, paper, 0.92), colour = NA), panel.border = element_blank(), panel.grid = element_line(colour = paper), panel.grid.minor = element_line(linewidth = rel(0.5)), @@ -232,10 +232,10 @@ theme_grey <- function(base_size = 11, base_family = "", panel.spacing.y = NULL, panel.ontop = FALSE, - strip.background = element_rect(fill = col_mix(ink, paper, 0.854), colour = NA), + strip.background = element_rect(fill = col_mix(ink, paper, 0.85), colour = NA), strip.clip = "on", strip.text = element_text( - colour = col_mix(ink, paper, 0.105), + colour = col_mix(ink, paper, 0.1), size = rel(0.8), margin = margin_auto(0.8 * half_line) ), @@ -303,7 +303,7 @@ theme_bw <- function(base_size = 11, base_family = "", panel.background = element_rect(fill = paper, colour = NA), panel.border = element_rect(colour = col_mix(ink, paper, 0.2)), # make gridlines dark, same contrast with white as in theme_grey - panel.grid = element_line(colour = col_mix(ink, paper, 0.925)), + panel.grid = element_line(colour = col_mix(ink, paper, 0.92)), panel.grid.minor = element_line(linewidth = rel(0.5)), # contour strips to match panel contour strip.background = element_rect( @@ -380,7 +380,7 @@ theme_light <- function(base_size = 11, base_family = "", theme( # white panel with light grey border panel.background = element_rect(fill = paper, colour = NA), - panel.border = element_rect(colour = col_mix(ink, paper, 0.705), linewidth = rel(1)), + panel.border = element_rect(colour = col_mix(ink, paper, 0.702), linewidth = rel(1)), # light grey, thinner gridlines # => make them slightly darker to keep acceptable contrast panel.grid = element_line(colour = col_mix(ink, paper, 0.871)), @@ -388,10 +388,10 @@ theme_light <- function(base_size = 11, base_family = "", panel.grid.minor = element_line(linewidth = rel(0.25)), # match axes ticks thickness to gridlines and colour to panel border - axis.ticks = element_line(colour = col_mix(ink, paper, 0.705), linewidth = rel(0.5)), + axis.ticks = element_line(colour = col_mix(ink, paper, 0.702), linewidth = rel(0.5)), # dark strips with light text (inverse contrast compared to theme_grey) - strip.background = element_rect(fill = col_mix(ink, paper, 0.705), colour = NA), + strip.background = element_rect(fill = col_mix(ink, paper, 0.702), colour = NA), strip.text = element_text( colour = paper, size = rel(0.8), @@ -423,7 +423,7 @@ theme_dark <- function(base_size = 11, base_family = "", ) %+replace% theme( # dark panel - panel.background = element_rect(fill = col_mix(ink, paper, 0.5), colour = NA), + panel.background = element_rect(fill = col_mix(ink, paper, 0.499), colour = NA), # inverse grid lines contrast compared to theme_grey # make them thinner and try to keep the same visual contrast as in theme_light panel.grid = element_line(colour = col_mix(ink, paper, 0.42)), @@ -436,7 +436,7 @@ theme_dark <- function(base_size = 11, base_family = "", # dark strips with light text (inverse contrast compared to theme_grey) strip.background = element_rect(fill = col_mix(ink, paper, 0.15), colour = NA), strip.text = element_text( - colour = col_mix(ink, paper, 0.9), + colour = col_mix(ink, paper, 0.899), size = rel(0.8), margin = margin_auto(0.8 * half_line) ), @@ -649,7 +649,7 @@ theme_test <- function(base_size = 11, base_family = "", axis.line = element_blank(), axis.line.x = NULL, axis.line.y = NULL, - axis.text = element_text(size = rel(0.8), colour = col_mix(ink, paper, 0.305)), + axis.text = element_text(size = rel(0.8), colour = col_mix(ink, paper, 0.302)), axis.text.x = element_text(margin = margin(t = 0.8 * half_line / 2), vjust = 1), axis.text.x.top = element_text(margin = margin(b = 0.8 * half_line / 2), vjust = 0), axis.text.y = element_text(margin = margin(r = 0.8 * half_line / 2), hjust = 1), @@ -715,12 +715,12 @@ theme_test <- function(base_size = 11, base_family = "", panel.ontop = FALSE, strip.background = element_rect( - fill = col_mix(ink, paper, 0.851), + fill = col_mix(ink, paper, 0.85), colour = col_mix(ink, paper, 0.2) ), strip.clip = "on", strip.text = element_text( - colour = col_mix(ink, paper, 0.105), + colour = col_mix(ink, paper, 0.1), size = rel(0.8), margin = margin_auto(0.8 * half_line) ), diff --git a/R/utilities.R b/R/utilities.R index ff623df1a8..8e6f9d46e9 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -852,56 +852,6 @@ warn_dots_used <- function(env = caller_env(), call = caller_env()) { ) } -# TODO: delete shims when {scales} releases >1.3.0.9000 -# and bump {scales} version requirements -# Shim for scales/#424 -col_mix <- function(a, b, amount = 0.5) { - input <- vec_recycle_common(a = a, b = b, amount = amount) - a <- grDevices::col2rgb(input$a, TRUE) - b <- grDevices::col2rgb(input$b, TRUE) - new <- (a * (1 - input$amount) + b * input$amount) - grDevices::rgb( - new["red", ], new["green", ], new["blue", ], - alpha = new["alpha", ], maxColorValue = 255 - ) -} - -# Shim for scales/#427 -as_discrete_pal <- function(x, ...) { - if (is.function(x)) { - return(x) - } - pal_manual(x) -} - -# Shim for scales/#427 -as_continuous_pal <- function(x, ...) { - if (is.function(x)) { - return(x) - } - is_color <- grepl("^#(([[:xdigit:]]{2}){3,4}|([[:xdigit:]]){3,4})$", x) | - x %in% grDevices::colours() - if (all(is_color)) { - colour_ramp(x) - } else { - stats::approxfun(seq(0, 1, length.out = length(x)), x) - } -} - -# Replace shims by actual scales function when available -on_load({ - nse <- getNamespaceExports("scales") - if ("col_mix" %in% nse) { - col_mix <- scales::col_mix - } - if ("as_discrete_pal" %in% nse) { - as_discrete_pal <- scales::as_discrete_pal - } - if ("as_continuous_pal" %in% nse) { - as_continuous_pal <- scales::as_continuous_pal - } -}) - # TODO: Replace me if rlang/#1730 gets implemented # Similar to `rlang::check_installed()` but returns boolean and misses # features such as versions, comparisons and using {pak}. diff --git a/tests/testthat/_snaps/scale-date.md b/tests/testthat/_snaps/scale-date.md index da37c01413..38c9ef3b73 100644 --- a/tests/testthat/_snaps/scale-date.md +++ b/tests/testthat/_snaps/scale-date.md @@ -6,7 +6,7 @@ --- A value was passed to a Datetime scale. - i The value was converted to a object. + i The value was converted to a object. --- diff --git a/tests/testthat/_snaps/theme/theme-with-inverted-colours.svg b/tests/testthat/_snaps/theme/theme-with-inverted-colours.svg index 812529cf9f..760107a5c9 100644 --- a/tests/testthat/_snaps/theme/theme-with-inverted-colours.svg +++ b/tests/testthat/_snaps/theme/theme-with-inverted-colours.svg @@ -26,7 +26,7 @@ - + @@ -289,8 +289,8 @@ - -Strip title + +Strip title @@ -299,15 +299,15 @@ -2 -3 -4 -5 -6 -7 -20 -30 -40 +2 +3 +4 +5 +6 +7 +20 +30 +40 @@ -315,11 +315,11 @@ hwy drv - + - + - + 4 f