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: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* Improved palette fallback mechanism in scales (@teunbrand, #6669).
* Allow `stat` in `geom_hline`, `geom_vline`, and `geom_abline`. (@sierrajohnson, #6559)
* `stat_boxplot()` treats `width` as an optional aesthetic (@Yunuuuu, #6575)
* Fixed regression where the first (unnamed) argument to colour/fill scales was
not passed as the `name` argument (@teunbrand, #6623)

# ggplot2 4.0.0

Expand Down
24 changes: 15 additions & 9 deletions R/scale-colour.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
#' * a single string naming a palette.
#' * a palette function that when called with a numeric vector with values
#' between 0 and 1 returns the corresponding output values.
#' @inheritDotParams continuous_scale -scale_name -trans -minor_breaks -expand
#' @inheritDotParams binned_scale -scale_name -trans -expand
#' @inheritDotParams continuous_scale -scale_name -trans -minor_breaks -expand -fallback.palette
#' @inheritDotParams binned_scale -scale_name -trans -expand -fallback.palette
#' @param type `r lifecycle::badge("superseded")` The preferred mechanism for
#' setting the default palette is by using the theme. For example:
#' `theme(palette.colour.discrete = "viridis")`.
Expand Down Expand Up @@ -91,7 +91,8 @@ scale_colour_continuous <- function(..., palette = NULL, aesthetics = "colour",
}
palette <- if (!is.null(palette)) as_continuous_pal(palette)
continuous_scale(
aesthetics, palette = palette, guide = guide, na.value = na.value,
aesthetics = aesthetics, palette = palette, guide = guide,
na.value = na.value, scale_name = deprecated(),
fallback.palette = pal_seq_gradient("#132B43", "#56B1F7"),
...
)
Expand All @@ -114,7 +115,8 @@ scale_fill_continuous <- function(..., palette = NULL, aesthetics = "fill", guid
}
palette <- if (!is.null(palette)) as_continuous_pal(palette)
continuous_scale(
aesthetics, palette = palette, guide = guide, na.value = na.value,
aesthetics = aesthetics, palette = palette, guide = guide,
na.value = na.value, scale_name = deprecated(),
fallback.palette = pal_seq_gradient("#132B43", "#56B1F7"),
...
)
Expand All @@ -137,7 +139,8 @@ scale_colour_binned <- function(..., palette = NULL, aesthetics = "colour", guid
}
palette <- if (!is.null(palette)) pal_binned(as_discrete_pal(palette))
binned_scale(
aesthetics, palette = palette, guide = guide, na.value = na.value,
aesthetics = aesthetics, palette = palette, guide = guide,
na.value = na.value, scale_name = deprecated(),
fallback.palette = pal_seq_gradient("#132B43", "#56B1F7"),
...
)
Expand All @@ -159,7 +162,8 @@ scale_fill_binned <- function(..., palette = NULL, aesthetics = "fill", guide =
}
palette <- if (!is.null(palette)) pal_binned(as_discrete_pal(palette))
binned_scale(
aesthetics, palette = palette, guide = guide, na.value = na.value,
aesthetics = aesthetics, palette = palette, guide = guide,
na.value = na.value, scale_name = deprecated(),
fallback.palette = pal_seq_gradient("#132B43", "#56B1F7"),
...
)
Expand All @@ -175,7 +179,7 @@ scale_fill_binned <- function(..., palette = NULL, aesthetics = "fill", guide =
#' * a single string naming a palette.
#' * a palette function that when called with a single integer argument (the
#' number of levels in the scale) returns the values that they should take.
#' @inheritDotParams discrete_scale -scale_name -expand -position -minor_breaks
#' @inheritDotParams discrete_scale -scale_name -expand -position -minor_breaks -fallback.palette
#' @inheritParams discrete_scale
#' @param type `r lifecycle::badge("superseded")` The preferred mechanism for
#' setting the default palette is by using the theme. For example:
Expand Down Expand Up @@ -218,7 +222,8 @@ scale_colour_discrete <- function(..., palette = NULL, aesthetics = "colour", na
}
palette <- if (!is.null(palette)) as_discrete_pal(palette)
discrete_scale(
aesthetics, palette = palette, na.value = na.value,
aesthetics = aesthetics, palette = palette, na.value = na.value,
scale_name = deprecated(),
fallback.palette = pal_hue(),
...
)
Expand All @@ -240,7 +245,8 @@ scale_fill_discrete <- function(..., palette = NULL, aesthetics = "fill", na.val
}
palette <- if (!is.null(palette)) as_discrete_pal(palette)
discrete_scale(
aesthetics, palette = palette, na.value = na.value,
aesthetics = aesthetics, palette = palette, na.value = na.value,
scale_name = deprecated(),
fallback.palette = pal_hue(),
...
)
Expand Down
19 changes: 19 additions & 0 deletions tests/testthat/test-scale-colour.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,22 @@ test_that("palette arguments can take alternative input", {
expect_equal(alpha(test, 1), hex)

})

test_that("`name` is directed correctly (#6623)", {
# The desired behaviour is that the first argument passed to scales is the
# 'name' argument.

scales <- list(
scale_colour_continuous,
scale_colour_discrete,
scale_colour_binned,
scale_fill_continuous,
scale_fill_discrete,
scale_fill_binned
)

for (scale in scales) {
p <- scale("foobar")
expect_equal(p$name, "foobar")
}
})