Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit

Permalink
Remove deprecated argument as of ggplot2 3.5.0 (fixes #15)
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrerebeau committed Jun 26, 2024
1 parent ea535db commit 2197a76
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ Collate:
'change.R'
'color.R'
'compare.R'
'ggplot2.R'
'info.R'
'khroma-deprecated.R'
'khroma-internal.R'
Expand All @@ -70,5 +69,6 @@ Collate:
'scale_colour_crameri.R'
'scale_colour_okabeito.R'
'scale_colour_other.R'
'scale_colour_picker.R'
'scale_colour_science.R'
'scale_colour_tol.R'
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* `plot*()` functions invisibly return the first argument (vector of colors).
* Deprecate `convert()` (#14).
* Deprecate `ramp()`.
* Remove deprecated argument in `ggplot2::discrete_scale()` and `ggplot2::continuous_scale()` (#15).

# khroma 1.12.0
## New functions
Expand Down
23 changes: 12 additions & 11 deletions R/ggplot2.R → R/scale_colour_picker.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ NULL
#' [continuous][ggplot2::continuous_scale] scale.
#' @example inst/examples/ex-pick.R
#' @author N. Frerebeau
#' @family color scales
#' @family ggplot2 scales
#' @name scale_picker
#' @rdname scale_picker
NULL
Expand Down Expand Up @@ -58,7 +58,7 @@ scale_edge_fill_picker <- function(..., palette = "YlOrBr") {
#' Builds a discrete or continuous scale for \pkg{ggplot2} according to the
#' color scheme used.
#' @param aesthetics The names of the aesthetics that this scale works with.
#' @param scale_name A [`character`] string giving the name of the palette to be
#' @param scheme A [`character`] string giving the name of the scheme to be
#' used (see [color()]).
#' @param guide A [`function`] used to create a guide or its name.
#' See [ggplot2::guides()] for more information.
Expand All @@ -85,35 +85,35 @@ scale_edge_fill_picker <- function(..., palette = "YlOrBr") {
#' @noRd
NULL

scale_discrete <- function(aesthetics, scale_name, guide = "legend",
scale_discrete <- function(aesthetics, scheme, guide = "legend",
reverse = FALSE, use_names = FALSE,
lang = "en", ...) {
# Check if ggplot2 is installed
check_package("ggplot2")

# Get color scheme
palette <- color(scale_name, reverse = reverse, names = use_names,
lang = lang)
palette <- color(scheme, reverse = reverse, names = use_names, lang = lang)

# Build scale
scale_args <- list(...)
scale_args$guide <- guide
scale_args$na.value <- scale_args$na.value %||% attr(palette, "missing")

do.call(
ggplot2::discrete_scale, c(aesthetics, scale_name, palette, scale_args)
ggplot2::discrete_scale,
c(aesthetics = aesthetics, palette = palette, scale_args)
)
}

scale_continuous <- function(aesthetics, scale_name, guide = "colourbar",
scale_continuous <- function(aesthetics, scheme, guide = "colourbar",
reverse = FALSE, range = c(0, 1), midpoint = 0,
lang = "en", ...) {
# Validation
check_package("ggplot2") # Check if ggplot2 is installed
if (guide == "edge_colourbar") check_package("ggraph")

# Get color scheme
palette <- color(scale_name, reverse = reverse, names = FALSE, lang = lang)
palette <- color(scheme, reverse = reverse, names = FALSE, lang = lang)
max <- attr(palette, "max")
type <- attr(palette, "type")

Expand All @@ -128,12 +128,13 @@ scale_continuous <- function(aesthetics, scale_name, guide = "colourbar",

palette <- scales::gradient_n_pal(palette(max, range = range))
do.call(
ggplot2::continuous_scale, c(aesthetics, scale_name, palette, scale_args)
ggplot2::continuous_scale,
c(aesthetics = aesthetics, palette = palette, scale_args)
)
}

rescale_mid <- function(mid) {
function(x) {
scale_midpoint(x, midpoint = mid)
function(x, to = c(0, 1), from = range(x, na.rm = TRUE)) {
scale_midpoint(x, to = to, from = from, midpoint = mid)
}
}
4 changes: 2 additions & 2 deletions man/scale_picker.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2197a76

Please sign in to comment.