diff --git a/DESCRIPTION b/DESCRIPTION index f59a3fe..304e3d7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -55,7 +55,6 @@ Collate: 'change.R' 'color.R' 'compare.R' - 'ggplot2.R' 'info.R' 'khroma-deprecated.R' 'khroma-internal.R' @@ -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' diff --git a/NEWS.md b/NEWS.md index ec56d95..b5264c2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/ggplot2.R b/R/scale_colour_picker.R similarity index 85% rename from R/ggplot2.R rename to R/scale_colour_picker.R index 317c92f..6ade3bc 100644 --- a/R/ggplot2.R +++ b/R/scale_colour_picker.R @@ -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 @@ -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. @@ -85,15 +85,14 @@ 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(...) @@ -101,11 +100,12 @@ scale_discrete <- function(aesthetics, scale_name, guide = "legend", 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 @@ -113,7 +113,7 @@ scale_continuous <- function(aesthetics, scale_name, guide = "colourbar", 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") @@ -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) } } diff --git a/man/scale_picker.Rd b/man/scale_picker.Rd index 7f0f209..c79dadb 100644 --- a/man/scale_picker.Rd +++ b/man/scale_picker.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ggplot2.R +% Please edit documentation in R/scale_colour_picker.R \name{scale_picker} \alias{scale_picker} \alias{scale_colour_picker} @@ -45,4 +45,4 @@ ggplot2::ggplot(mpg, ggplot2::aes(displ, hwy, colour = class)) + \author{ N. Frerebeau } -\concept{color scales} +\concept{ggplot2 scales}