From cad1eaab9ef2fffab010d77a33cbe1c5c866a3a0 Mon Sep 17 00:00:00 2001 From: Teun van den Brand <49372158+teunbrand@users.noreply.github.com> Date: Tue, 4 Jul 2023 19:18:37 +0200 Subject: [PATCH] Purge `scale_name` --- R/scale-alpha.R | 7 +++--- R/scale-binned.R | 4 ++-- R/scale-brewer.R | 22 +++++++++++------- R/scale-continuous.R | 4 ++-- R/scale-date.R | 6 ----- R/scale-discrete-.R | 4 ++-- R/scale-gradient.R | 36 ++++++++++++++++++++---------- R/scale-grey.R | 4 ++-- R/scale-hue.R | 8 +++---- R/scale-identity.R | 18 +++++++-------- R/scale-linetype.R | 4 ++-- R/scale-linewidth.R | 7 +++--- R/scale-manual.R | 2 +- R/scale-shape.R | 4 ++-- R/scale-size.R | 13 +++++------ R/scale-steps.R | 16 ++++++------- R/scale-viridis.R | 18 +++++---------- R/zxx.R | 2 -- tests/testthat/test-geom-dotplot.R | 2 +- tests/testthat/test-scales.R | 2 +- 20 files changed, 92 insertions(+), 91 deletions(-) diff --git a/R/scale-alpha.R b/R/scale-alpha.R index 35ed20d581..8be2925c58 100644 --- a/R/scale-alpha.R +++ b/R/scale-alpha.R @@ -24,7 +24,7 @@ #' p + scale_alpha("cylinders") #' p + scale_alpha(range = c(0.4, 0.8)) scale_alpha <- function(..., range = c(0.1, 1)) { - continuous_scale("alpha", "alpha_c", rescale_pal(range), ...) + continuous_scale("alpha", palette = rescale_pal(range), ...) } #' @rdname scale_alpha @@ -34,7 +34,7 @@ scale_alpha_continuous <- scale_alpha #' @rdname scale_alpha #' @export scale_alpha_binned <- function(..., range = c(0.1, 1)) { - binned_scale("alpha", "alpha_b", rescale_pal(range), ...) + binned_scale("alpha", palette = rescale_pal(range), ...) } #' @rdname scale_alpha @@ -51,8 +51,7 @@ scale_alpha_discrete <- function(...) { scale_alpha_ordinal <- function(..., range = c(0.1, 1)) { discrete_scale( "alpha", - "alpha_d", - function(n) seq(range[1], range[2], length.out = n), + palette = function(n) seq(range[1], range[2], length.out = n), ... ) } diff --git a/R/scale-binned.R b/R/scale-binned.R index 003cd59456..1fb5444696 100644 --- a/R/scale-binned.R +++ b/R/scale-binned.R @@ -30,7 +30,7 @@ scale_x_binned <- function(name = waiver(), n.breaks = 10, nice.breaks = TRUE, guide = waiver(), position = "bottom") { binned_scale( ggplot_global$x_aes, - scale_name = "position_b", palette = identity, name = name, breaks = breaks, + palette = identity, name = name, breaks = breaks, labels = labels, limits = limits, expand = expand, oob = oob, na.value = na.value, n.breaks = n.breaks, nice.breaks = nice.breaks, right = right, trans = trans, show.limits = show.limits, guide = guide, position = position, super = ScaleBinnedPosition @@ -47,7 +47,7 @@ scale_y_binned <- function(name = waiver(), n.breaks = 10, nice.breaks = TRUE, guide = waiver(), position = "left") { binned_scale( ggplot_global$y_aes, - scale_name = "position_b", palette = identity, name = name, breaks = breaks, + palette = identity, name = name, breaks = breaks, labels = labels, limits = limits, expand = expand, oob = oob, na.value = na.value, n.breaks = n.breaks, nice.breaks = nice.breaks, right = right, trans = trans, show.limits = show.limits, guide = guide, position = position, super = ScaleBinnedPosition diff --git a/R/scale-brewer.R b/R/scale-brewer.R index 55c7bab954..d56187a693 100644 --- a/R/scale-brewer.R +++ b/R/scale-brewer.R @@ -80,13 +80,13 @@ #' v + scale_fill_fermenter() #' scale_colour_brewer <- function(..., type = "seq", palette = 1, direction = 1, aesthetics = "colour") { - discrete_scale(aesthetics, "brewer", brewer_pal(type, palette, direction), ...) + discrete_scale(aesthetics, palette = brewer_pal(type, palette, direction), ...) } #' @export #' @rdname scale_brewer scale_fill_brewer <- function(..., type = "seq", palette = 1, direction = 1, aesthetics = "fill") { - discrete_scale(aesthetics, "brewer", brewer_pal(type, palette, direction), ...) + discrete_scale(aesthetics, palette = brewer_pal(type, palette, direction), ...) } #' @export @@ -100,8 +100,11 @@ scale_colour_distiller <- function(..., type = "seq", palette = 1, direction = - "i" = "Consider using {.code type = \"seq\"} or {.code type = \"div\"} instead" )) } - continuous_scale(aesthetics, "distiller", - gradient_n_pal(brewer_pal(type, palette, direction)(7), values, space), na.value = na.value, guide = guide, ...) + continuous_scale( + aesthetics, + palette = gradient_n_pal(brewer_pal(type, palette, direction)(7), values, space), + na.value = na.value, guide = guide, ... + ) # NB: 6-7 colours per palette gives nice gradients; more results in more saturated colours which do not look as good # For diverging scales, you need an odd number to make sure the mid-point is in the center } @@ -116,8 +119,11 @@ scale_fill_distiller <- function(..., type = "seq", palette = 1, direction = -1, "i" = "Consider using {.code type = \"seq\"} or {.code type = \"div\"} instead" )) } - continuous_scale(aesthetics, "distiller", - gradient_n_pal(brewer_pal(type, palette, direction)(7), values, space), na.value = na.value, guide = guide, ...) + continuous_scale( + aesthetics, + palette = gradient_n_pal(brewer_pal(type, palette, direction)(7), values, space), + na.value = na.value, guide = guide, ... + ) } #' @export @@ -131,7 +137,7 @@ scale_colour_fermenter <- function(..., type = "seq", palette = 1, direction = - "i" = "Consider using {.code type = \"seq\"} or {.code type = \"div\"} instead" )) } - binned_scale(aesthetics, "fermenter", binned_pal(brewer_pal(type, palette, direction)), na.value = na.value, guide = guide, ...) + binned_scale(aesthetics, palette = binned_pal(brewer_pal(type, palette, direction)), na.value = na.value, guide = guide, ...) } #' @export @@ -144,5 +150,5 @@ scale_fill_fermenter <- function(..., type = "seq", palette = 1, direction = -1, "i" = "Consider using {.code type = \"seq\"} or {.code type = \"div\"} instead" )) } - binned_scale(aesthetics, "fermenter", binned_pal(brewer_pal(type, palette, direction)), na.value = na.value, guide = guide, ...) + binned_scale(aesthetics, palette = binned_pal(brewer_pal(type, palette, direction)), na.value = na.value, guide = guide, ...) } diff --git a/R/scale-continuous.R b/R/scale-continuous.R index 3fc870f067..73b026a678 100644 --- a/R/scale-continuous.R +++ b/R/scale-continuous.R @@ -90,7 +90,7 @@ scale_x_continuous <- function(name = waiver(), breaks = waiver(), } sc <- continuous_scale( ggplot_global$x_aes, - "position_c", identity, name = name, breaks = breaks, n.breaks = n.breaks, + palette = identity, name = name, breaks = breaks, n.breaks = n.breaks, minor_breaks = minor_breaks, labels = labels, limits = limits, expand = expand, oob = oob, na.value = na.value, trans = trans, guide = guide, position = position, call = call, @@ -116,7 +116,7 @@ scale_y_continuous <- function(name = waiver(), breaks = waiver(), } sc <- continuous_scale( ggplot_global$y_aes, - "position_c", identity, name = name, breaks = breaks, n.breaks = n.breaks, + palette = identity, name = name, breaks = breaks, n.breaks = n.breaks, minor_breaks = minor_breaks, labels = labels, limits = limits, expand = expand, oob = oob, na.value = na.value, trans = trans, guide = guide, position = position, call = call, diff --git a/R/scale-date.R b/R/scale-date.R index 20b0fabff7..8c20532599 100644 --- a/R/scale-date.R +++ b/R/scale-date.R @@ -313,11 +313,6 @@ datetime_scale <- function(aesthetics, trans, palette, } } - name <- switch(trans, - date = "date", - time = "datetime" - ) - # x/y position aesthetics should use ScaleContinuousDate or # ScaleContinuousDatetime; others use ScaleContinuous if (all(aesthetics %in% c("x", "xmin", "xmax", "xend", "y", "ymin", "ymax", "yend"))) { @@ -337,7 +332,6 @@ datetime_scale <- function(aesthetics, trans, palette, sc <- continuous_scale( aesthetics, - name, palette = palette, breaks = breaks, minor_breaks = minor_breaks, diff --git a/R/scale-discrete-.R b/R/scale-discrete-.R index 25931f3d7e..339df10122 100644 --- a/R/scale-discrete-.R +++ b/R/scale-discrete-.R @@ -62,7 +62,7 @@ #' scale_x_discrete(labels = abbreviate) #' } scale_x_discrete <- function(..., expand = waiver(), guide = waiver(), position = "bottom") { - sc <- discrete_scale(c("x", "xmin", "xmax", "xend"), "position_d", identity, ..., + sc <- discrete_scale(c("x", "xmin", "xmax", "xend"), palette = identity, ..., expand = expand, guide = guide, position = position, super = ScaleDiscretePosition) sc$range_c <- ContinuousRange$new() @@ -71,7 +71,7 @@ scale_x_discrete <- function(..., expand = waiver(), guide = waiver(), position #' @rdname scale_discrete #' @export scale_y_discrete <- function(..., expand = waiver(), guide = waiver(), position = "left") { - sc <- discrete_scale(c("y", "ymin", "ymax", "yend"), "position_d", identity, ..., + sc <- discrete_scale(c("y", "ymin", "ymax", "yend"), palette = identity, ..., expand = expand, guide = guide, position = position, super = ScaleDiscretePosition) sc$range_c <- ContinuousRange$new() diff --git a/R/scale-gradient.R b/R/scale-gradient.R index a2cce5b8a3..95ee2824b2 100644 --- a/R/scale-gradient.R +++ b/R/scale-gradient.R @@ -77,7 +77,7 @@ #' scale_colour_gradient <- function(..., low = "#132B43", high = "#56B1F7", space = "Lab", na.value = "grey50", guide = "colourbar", aesthetics = "colour") { - continuous_scale(aesthetics, "gradient", seq_gradient_pal(low, high, space), + continuous_scale(aesthetics, palette = seq_gradient_pal(low, high, space), na.value = na.value, guide = guide, ...) } @@ -85,7 +85,7 @@ scale_colour_gradient <- function(..., low = "#132B43", high = "#56B1F7", space #' @export scale_fill_gradient <- function(..., low = "#132B43", high = "#56B1F7", space = "Lab", na.value = "grey50", guide = "colourbar", aesthetics = "fill") { - continuous_scale(aesthetics, "gradient", seq_gradient_pal(low, high, space), + continuous_scale(aesthetics, palette = seq_gradient_pal(low, high, space), na.value = na.value, guide = guide, ...) } @@ -97,9 +97,12 @@ scale_fill_gradient <- function(..., low = "#132B43", high = "#56B1F7", space = scale_colour_gradient2 <- function(..., low = muted("red"), mid = "white", high = muted("blue"), midpoint = 0, space = "Lab", na.value = "grey50", guide = "colourbar", aesthetics = "colour") { - continuous_scale(aesthetics, "gradient2", - div_gradient_pal(low, mid, high, space), na.value = na.value, guide = guide, ..., - rescaler = mid_rescaler(mid = midpoint)) + continuous_scale( + aesthetics, + palette = div_gradient_pal(low, mid, high, space), + na.value = na.value, guide = guide, ..., + rescaler = mid_rescaler(mid = midpoint) + ) } #' @rdname scale_gradient @@ -107,9 +110,12 @@ scale_colour_gradient2 <- function(..., low = muted("red"), mid = "white", high scale_fill_gradient2 <- function(..., low = muted("red"), mid = "white", high = muted("blue"), midpoint = 0, space = "Lab", na.value = "grey50", guide = "colourbar", aesthetics = "fill") { - continuous_scale(aesthetics, "gradient2", - div_gradient_pal(low, mid, high, space), na.value = na.value, guide = guide, ..., - rescaler = mid_rescaler(mid = midpoint)) + continuous_scale( + aesthetics, + palette = div_gradient_pal(low, mid, high, space), + na.value = na.value, guide = guide, ..., + rescaler = mid_rescaler(mid = midpoint) + ) } mid_rescaler <- function(mid) { @@ -126,8 +132,11 @@ scale_colour_gradientn <- function(..., colours, values = NULL, space = "Lab", n guide = "colourbar", aesthetics = "colour", colors) { colours <- if (missing(colours)) colors else colours - continuous_scale(aesthetics, "gradientn", - gradient_n_pal(colours, values, space), na.value = na.value, guide = guide, ...) + continuous_scale( + aesthetics, + palette = gradient_n_pal(colours, values, space), + na.value = na.value, guide = guide, ... + ) } #' @rdname scale_gradient #' @export @@ -135,6 +144,9 @@ scale_fill_gradientn <- function(..., colours, values = NULL, space = "Lab", na. guide = "colourbar", aesthetics = "fill", colors) { colours <- if (missing(colours)) colors else colours - continuous_scale(aesthetics, "gradientn", - gradient_n_pal(colours, values, space), na.value = na.value, guide = guide, ...) + continuous_scale( + aesthetics, + palette = gradient_n_pal(colours, values, space), + na.value = na.value, guide = guide, ... + ) } diff --git a/R/scale-grey.R b/R/scale-grey.R index 4289d3690f..c71dd444ef 100644 --- a/R/scale-grey.R +++ b/R/scale-grey.R @@ -28,13 +28,13 @@ #' geom_point(aes(colour = miss)) + #' scale_colour_grey(na.value = "green") scale_colour_grey <- function(..., start = 0.2, end = 0.8, na.value = "red", aesthetics = "colour") { - discrete_scale(aesthetics, "grey", grey_pal(start, end), + discrete_scale(aesthetics, palette = grey_pal(start, end), na.value = na.value, ...) } #' @rdname scale_grey #' @export scale_fill_grey <- function(..., start = 0.2, end = 0.8, na.value = "red", aesthetics = "fill") { - discrete_scale(aesthetics, "grey", grey_pal(start, end), + discrete_scale(aesthetics, palette = grey_pal(start, end), na.value = na.value, ...) } diff --git a/R/scale-hue.R b/R/scale-hue.R index 87bef03078..0e0d796537 100644 --- a/R/scale-hue.R +++ b/R/scale-hue.R @@ -55,7 +55,7 @@ #' } scale_colour_hue <- function(..., h = c(0, 360) + 15, c = 100, l = 65, h.start = 0, direction = 1, na.value = "grey50", aesthetics = "colour") { - discrete_scale(aesthetics, "hue", hue_pal(h, c, l, h.start, direction), + discrete_scale(aesthetics, palette = hue_pal(h, c, l, h.start, direction), na.value = na.value, ...) } @@ -63,7 +63,7 @@ scale_colour_hue <- function(..., h = c(0, 360) + 15, c = 100, l = 65, h.start = #' @export scale_fill_hue <- function(..., h = c(0, 360) + 15, c = 100, l = 65, h.start = 0, direction = 1, na.value = "grey50", aesthetics = "fill") { - discrete_scale(aesthetics, "hue", hue_pal(h, c, l, h.start, direction), + discrete_scale(aesthetics, palette = hue_pal(h, c, l, h.start, direction), na.value = na.value, ...) } @@ -168,7 +168,7 @@ scale_fill_discrete <- function(..., type = getOption("ggplot2.discrete.fill")) scale_colour_qualitative <- function(..., type = NULL, h = c(0, 360) + 15, c = 100, l = 65, h.start = 0, direction = 1, na.value = "grey50", aesthetics = "colour") { discrete_scale( - aesthetics, "qualitative", qualitative_pal(type, h, c, l, h.start, direction), + aesthetics, palette = qualitative_pal(type, h, c, l, h.start, direction), na.value = na.value, ... ) } @@ -176,7 +176,7 @@ scale_colour_qualitative <- function(..., type = NULL, h = c(0, 360) + 15, c = 1 scale_fill_qualitative <- function(..., type = NULL, h = c(0, 360) + 15, c = 100, l = 65, h.start = 0, direction = 1, na.value = "grey50", aesthetics = "fill") { discrete_scale( - aesthetics, "qualitative", qualitative_pal(type, h, c, l, h.start, direction), + aesthetics, palette = qualitative_pal(type, h, c, l, h.start, direction), na.value = na.value, ... ) } diff --git a/R/scale-identity.R b/R/scale-identity.R index 336083a6a2..9a3ace41a0 100644 --- a/R/scale-identity.R +++ b/R/scale-identity.R @@ -63,7 +63,7 @@ NULL #' @rdname scale_identity #' @export scale_colour_identity <- function(..., guide = "none", aesthetics = "colour") { - sc <- discrete_scale(aesthetics, "identity", identity_pal(), ..., guide = guide, + sc <- discrete_scale(aesthetics, palette = identity_pal(), ..., guide = guide, super = ScaleDiscreteIdentity) sc @@ -72,7 +72,7 @@ scale_colour_identity <- function(..., guide = "none", aesthetics = "colour") { #' @rdname scale_identity #' @export scale_fill_identity <- function(..., guide = "none", aesthetics = "fill") { - sc <- discrete_scale(aesthetics, "identity", identity_pal(), ..., guide = guide, + sc <- discrete_scale(aesthetics, palette = identity_pal(), ..., guide = guide, super = ScaleDiscreteIdentity) sc @@ -83,7 +83,7 @@ scale_fill_identity <- function(..., guide = "none", aesthetics = "fill") { #' Other shape scales: [scale_shape()], [scale_shape_manual()]. #' @export scale_shape_identity <- function(..., guide = "none") { - sc <- continuous_scale("shape", "identity", identity_pal(), ..., guide = guide, + sc <- continuous_scale("shape", palette = identity_pal(), ..., guide = guide, super = ScaleContinuousIdentity) sc @@ -94,7 +94,7 @@ scale_shape_identity <- function(..., guide = "none") { #' Other linetype scales: [scale_linetype()], [scale_linetype_manual()]. #' @export scale_linetype_identity <- function(..., guide = "none") { - sc <- discrete_scale("linetype", "identity", identity_pal(), ..., guide = guide, + sc <- discrete_scale("linetype", palette = identity_pal(), ..., guide = guide, super = ScaleDiscreteIdentity) sc @@ -105,7 +105,7 @@ scale_linetype_identity <- function(..., guide = "none") { #' Other alpha scales: [scale_alpha()], [scale_alpha_manual()]. #' @export scale_linewidth_identity <- function(..., guide = "none") { - sc <- continuous_scale("linewidth", "identity", identity_pal(), ..., + sc <- continuous_scale("linewidth", palette = identity_pal(), ..., guide = guide, super = ScaleContinuousIdentity) sc @@ -114,7 +114,7 @@ scale_linewidth_identity <- function(..., guide = "none") { #' @rdname scale_identity #' @export scale_alpha_identity <- function(..., guide = "none") { - sc <- continuous_scale("alpha", "identity", identity_pal(), ..., guide = guide, + sc <- continuous_scale("alpha", palette = identity_pal(), ..., guide = guide, super = ScaleContinuousIdentity) sc @@ -125,7 +125,7 @@ scale_alpha_identity <- function(..., guide = "none") { #' Other size scales: [scale_size()], [scale_size_manual()]. #' @export scale_size_identity <- function(..., guide = "none") { - sc <- continuous_scale("size", "identity", identity_pal(), ..., guide = guide, + sc <- continuous_scale("size", palette = identity_pal(), ..., guide = guide, super = ScaleContinuousIdentity) sc @@ -134,7 +134,7 @@ scale_size_identity <- function(..., guide = "none") { #' @rdname scale_identity #' @export scale_discrete_identity <- function(aesthetics, ..., guide = "none") { - sc <- discrete_scale(aesthetics, "identity", identity_pal(), ..., guide = guide, + sc <- discrete_scale(aesthetics, palette = identity_pal(), ..., guide = guide, super = ScaleDiscreteIdentity) sc @@ -143,7 +143,7 @@ scale_discrete_identity <- function(aesthetics, ..., guide = "none") { #' @rdname scale_identity #' @export scale_continuous_identity <- function(aesthetics, ..., guide = "none") { - sc <- continuous_scale(aesthetics, "identity", identity_pal(), ..., guide = guide, + sc <- continuous_scale(aesthetics, palette = identity_pal(), ..., guide = guide, super = ScaleContinuousIdentity) sc diff --git a/R/scale-linetype.R b/R/scale-linetype.R index 54d0eb1360..494abc5d55 100644 --- a/R/scale-linetype.R +++ b/R/scale-linetype.R @@ -34,14 +34,14 @@ #' facet_grid(linetype ~ .) + #' theme_void(20) scale_linetype <- function(..., na.value = "blank") { - discrete_scale("linetype", "linetype_d", linetype_pal(), + discrete_scale("linetype", palette = linetype_pal(), na.value = na.value, ...) } #' @rdname scale_linetype #' @export scale_linetype_binned <- function(..., na.value = "blank") { - binned_scale("linetype", "linetype_b", binned_pal(linetype_pal()), ...) + binned_scale("linetype", palette = binned_pal(linetype_pal()), ...) } #' @rdname scale_linetype diff --git a/R/scale-linewidth.R b/R/scale-linewidth.R index 46feae48ed..61f4dc1c0c 100644 --- a/R/scale-linewidth.R +++ b/R/scale-linewidth.R @@ -31,7 +31,7 @@ scale_linewidth_continuous <- function(name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = c(1, 6), trans = "identity", guide = "legend") { - continuous_scale("linewidth", "linewidth_c", rescale_pal(range), name = name, + continuous_scale("linewidth", palette = rescale_pal(range), name = name, breaks = breaks, labels = labels, limits = limits, trans = trans, guide = guide) } @@ -45,7 +45,7 @@ scale_linewidth <- scale_linewidth_continuous scale_linewidth_binned <- function(name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = c(1, 6), n.breaks = NULL, nice.breaks = TRUE, trans = "identity", guide = "bins") { - binned_scale("linewidth", "linewidth_b", rescale_pal(range), name = name, + binned_scale("linewidth", palette = rescale_pal(range), name = name, breaks = breaks, labels = labels, limits = limits, trans = trans, n.breaks = n.breaks, nice.breaks = nice.breaks, guide = guide) } @@ -68,8 +68,7 @@ scale_linewidth_ordinal <- function(..., range = c(2, 6)) { discrete_scale( "linewidth", - "linewidth_d", - function(n) seq(range[1], range[2], length.out = n), + palette = function(n) seq(range[1], range[2], length.out = n), ... ) } diff --git a/R/scale-manual.R b/R/scale-manual.R index fdf59716d2..380d64d64f 100644 --- a/R/scale-manual.R +++ b/R/scale-manual.R @@ -183,6 +183,6 @@ manual_scale <- function(aesthetic, values = NULL, breaks = waiver(), ..., } values } - discrete_scale(aesthetic, "manual", pal, breaks = breaks, limits = limits, + discrete_scale(aesthetic, palette = pal, breaks = breaks, limits = limits, call = call, ...) } diff --git a/R/scale-shape.R b/R/scale-shape.R index 9bbd904b56..cc293174ef 100644 --- a/R/scale-shape.R +++ b/R/scale-shape.R @@ -41,13 +41,13 @@ #' facet_wrap(~shape) + #' theme_void() scale_shape <- function(..., solid = TRUE) { - discrete_scale("shape", "shape_d", shape_pal(solid), ...) + discrete_scale("shape", palette = shape_pal(solid), ...) } #' @rdname scale_shape #' @export scale_shape_binned <- function(..., solid = TRUE) { - binned_scale("shape", "shape_b", binned_pal(shape_pal(solid)), ...) + binned_scale("shape", palette = binned_pal(shape_pal(solid)), ...) } #' @rdname scale_shape diff --git a/R/scale-size.R b/R/scale-size.R index c960cc5557..c75a22fa3e 100644 --- a/R/scale-size.R +++ b/R/scale-size.R @@ -52,7 +52,7 @@ NULL scale_size_continuous <- function(name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = c(1, 6), trans = "identity", guide = "legend") { - continuous_scale("size", "area", area_pal(range), name = name, + continuous_scale("size", palette = area_pal(range), name = name, breaks = breaks, labels = labels, limits = limits, trans = trans, guide = guide) } @@ -66,7 +66,7 @@ scale_size <- scale_size_continuous scale_radius <- function(name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = c(1, 6), trans = "identity", guide = "legend") { - continuous_scale("size", "radius", rescale_pal(range), name = name, + continuous_scale("size", palette = rescale_pal(range), name = name, breaks = breaks, labels = labels, limits = limits, trans = trans, guide = guide) } @@ -76,7 +76,7 @@ scale_radius <- function(name = waiver(), breaks = waiver(), labels = waiver(), scale_size_binned <- function(name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = c(1, 6), n.breaks = NULL, nice.breaks = TRUE, trans = "identity", guide = "bins") { - binned_scale("size", "area_b", area_pal(range), name = name, + binned_scale("size", palette = area_pal(range), name = name, breaks = breaks, labels = labels, limits = limits, trans = trans, n.breaks = n.breaks, nice.breaks = nice.breaks, guide = guide) } @@ -99,8 +99,7 @@ scale_size_ordinal <- function(..., range = c(2, 6)) { discrete_scale( "size", - "size_d", - function(n) { + palette = function(n) { area <- seq(range[1] ^ 2, range[2] ^ 2, length.out = n) sqrt(area) }, @@ -113,7 +112,7 @@ scale_size_ordinal <- function(..., range = c(2, 6)) { #' @export #' @rdname scale_size scale_size_area <- function(..., max_size = 6) { - continuous_scale("size", "area", + continuous_scale("size", palette = abs_area(max_size), rescaler = rescale_max, ...) } @@ -121,7 +120,7 @@ scale_size_area <- function(..., max_size = 6) { #' @export #' @rdname scale_size scale_size_binned_area <- function(..., max_size = 6) { - binned_scale("size", "area_b", + binned_scale("size", palette = abs_area(max_size), rescaler = rescale_max, ...) } diff --git a/R/scale-steps.R b/R/scale-steps.R index 193fa6ddcb..5bbba07cb9 100644 --- a/R/scale-steps.R +++ b/R/scale-steps.R @@ -46,7 +46,7 @@ #' @rdname scale_steps scale_colour_steps <- function(..., low = "#132B43", high = "#56B1F7", space = "Lab", na.value = "grey50", guide = "coloursteps", aesthetics = "colour") { - binned_scale(aesthetics, "steps", seq_gradient_pal(low, high, space), + binned_scale(aesthetics, palette = seq_gradient_pal(low, high, space), na.value = na.value, guide = guide, ...) } #' @rdname scale_steps @@ -54,7 +54,7 @@ scale_colour_steps <- function(..., low = "#132B43", high = "#56B1F7", space = " scale_colour_steps2 <- function(..., low = muted("red"), mid = "white", high = muted("blue"), midpoint = 0, space = "Lab", na.value = "grey50", guide = "coloursteps", aesthetics = "colour") { - binned_scale(aesthetics, "steps2", div_gradient_pal(low, mid, high, space), + binned_scale(aesthetics, palette = div_gradient_pal(low, mid, high, space), na.value = na.value, guide = guide, rescaler = mid_rescaler(mid = midpoint), ...) } #' @rdname scale_steps @@ -62,14 +62,14 @@ scale_colour_steps2 <- function(..., low = muted("red"), mid = "white", high = m scale_colour_stepsn <- function(..., colours, values = NULL, space = "Lab", na.value = "grey50", guide = "coloursteps", aesthetics = "colour", colors) { colours <- if (missing(colours)) colors else colours - binned_scale(aesthetics, "stepsn", - gradient_n_pal(colours, values, space), na.value = na.value, guide = guide, ...) + binned_scale(aesthetics, palette = gradient_n_pal(colours, values, space), + na.value = na.value, guide = guide, ...) } #' @rdname scale_steps #' @export scale_fill_steps <- function(..., low = "#132B43", high = "#56B1F7", space = "Lab", na.value = "grey50", guide = "coloursteps", aesthetics = "fill") { - binned_scale(aesthetics, "steps", seq_gradient_pal(low, high, space), + binned_scale(aesthetics, palette = seq_gradient_pal(low, high, space), na.value = na.value, guide = guide, ...) } #' @rdname scale_steps @@ -77,7 +77,7 @@ scale_fill_steps <- function(..., low = "#132B43", high = "#56B1F7", space = "La scale_fill_steps2 <- function(..., low = muted("red"), mid = "white", high = muted("blue"), midpoint = 0, space = "Lab", na.value = "grey50", guide = "coloursteps", aesthetics = "fill") { - binned_scale(aesthetics, "steps2", div_gradient_pal(low, mid, high, space), + binned_scale(aesthetics, palette = div_gradient_pal(low, mid, high, space), na.value = na.value, guide = guide, rescaler = mid_rescaler(mid = midpoint), ...) } #' @rdname scale_steps @@ -85,6 +85,6 @@ scale_fill_steps2 <- function(..., low = muted("red"), mid = "white", high = mut scale_fill_stepsn <- function(..., colours, values = NULL, space = "Lab", na.value = "grey50", guide = "coloursteps", aesthetics = "fill", colors) { colours <- if (missing(colours)) colors else colours - binned_scale(aesthetics, "stepsn", - gradient_n_pal(colours, values, space), na.value = na.value, guide = guide, ...) + binned_scale(aesthetics, palette = gradient_n_pal(colours, values, space), + na.value = na.value, guide = guide, ...) } diff --git a/R/scale-viridis.R b/R/scale-viridis.R index 6460d435b9..72ecd4a491 100644 --- a/R/scale-viridis.R +++ b/R/scale-viridis.R @@ -62,8 +62,7 @@ scale_colour_viridis_d <- function(..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", aesthetics = "colour") { discrete_scale( aesthetics, - "viridis_d", - viridis_pal(alpha, begin, end, direction, option), + palette = viridis_pal(alpha, begin, end, direction, option), ... ) } @@ -74,8 +73,7 @@ scale_fill_viridis_d <- function(..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", aesthetics = "fill") { discrete_scale( aesthetics, - "viridis_d", - viridis_pal(alpha, begin, end, direction, option), + palette = viridis_pal(alpha, begin, end, direction, option), ... ) } @@ -88,8 +86,7 @@ scale_colour_viridis_c <- function(..., alpha = 1, begin = 0, end = 1, guide = "colourbar", aesthetics = "colour") { continuous_scale( aesthetics, - "viridis_c", - gradient_n_pal( + palette = gradient_n_pal( viridis_pal(alpha, begin, end, direction, option)(6), values, space @@ -108,8 +105,7 @@ scale_fill_viridis_c <- function(..., alpha = 1, begin = 0, end = 1, guide = "colourbar", aesthetics = "fill") { continuous_scale( aesthetics, - "viridis_c", - gradient_n_pal( + palette = gradient_n_pal( viridis_pal(alpha, begin, end, direction, option)(6), values, space @@ -132,8 +128,7 @@ scale_colour_viridis_b <- function(..., alpha = 1, begin = 0, end = 1, binned_scale( aesthetics, - "viridis_b", - pal, + palette = pal, na.value = na.value, guide = guide, ... @@ -152,8 +147,7 @@ scale_fill_viridis_b <- function(..., alpha = 1, begin = 0, end = 1, binned_scale( aesthetics, - "viridis_b", - pal, + palette = pal, na.value = na.value, guide = guide, ... diff --git a/R/zxx.R b/R/zxx.R index 79bfc358c5..369f7c532c 100644 --- a/R/zxx.R +++ b/R/zxx.R @@ -16,7 +16,6 @@ scale_colour_ordinal <- function(..., type = getOption("ggplot2.ordinal.colour", exec( discrete_scale, aesthetics = "colour", - scale_name = "ordinal", palette = ordinal_pal(type), !!!args ) @@ -95,7 +94,6 @@ scale_fill_ordinal <- function(..., type = getOption("ggplot2.ordinal.fill", get exec( discrete_scale, aesthetics = "fill", - scale_name = "ordinal", palette = ordinal_pal(type), !!!args ) diff --git a/tests/testthat/test-geom-dotplot.R b/tests/testthat/test-geom-dotplot.R index 6eda6bb8ed..eedd4ba4e3 100644 --- a/tests/testthat/test-geom-dotplot.R +++ b/tests/testthat/test-geom-dotplot.R @@ -196,7 +196,7 @@ test_that("geom_dotplot draws correctly", { ) ) + geom_dotplot(binwidth = .4, fill = "red", col = "blue") + - continuous_scale("stroke", "scaleName", function(x) scales::rescale(x, to = c(1, 6))) + continuous_scale("stroke", palette = function(x) scales::rescale(x, to = c(1, 6))) ) # Stacking groups diff --git a/tests/testthat/test-scales.R b/tests/testthat/test-scales.R index d95cb22588..562c593b29 100644 --- a/tests/testthat/test-scales.R +++ b/tests/testthat/test-scales.R @@ -288,7 +288,7 @@ test_that("multiple aesthetics can be set with one function call", { test_that("limits with NA are replaced with the min/max of the data for continuous scales", { make_scale <- function(limits = NULL, data = NULL) { - scale <- continuous_scale("aesthetic", scale_name = "test", palette = identity, limits = limits) + scale <- continuous_scale("aesthetic", palette = identity, limits = limits) if (!is.null(data)) { scale$train(data) }