Skip to content

Commit

Permalink
Purge scale_name
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Jul 4, 2023
1 parent 646f366 commit cad1eaa
Show file tree
Hide file tree
Showing 20 changed files with 92 additions and 91 deletions.
7 changes: 3 additions & 4 deletions R/scale-alpha.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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),
...
)
}
Expand Down
4 changes: 2 additions & 2 deletions R/scale-binned.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
22 changes: 14 additions & 8 deletions R/scale-brewer.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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, ...)
}
4 changes: 2 additions & 2 deletions R/scale-continuous.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions R/scale-date.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))) {
Expand All @@ -337,7 +332,6 @@ datetime_scale <- function(aesthetics, trans, palette,

sc <- continuous_scale(
aesthetics,
name,
palette = palette,
breaks = breaks,
minor_breaks = minor_breaks,
Expand Down
4 changes: 2 additions & 2 deletions R/scale-discrete-.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
36 changes: 24 additions & 12 deletions R/scale-gradient.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@
#'
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, ...)
}

#' @rdname scale_gradient
#' @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, ...)
}

Expand All @@ -97,19 +97,25 @@ 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
#' @export
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) {
Expand All @@ -126,15 +132,21 @@ 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
scale_fill_gradientn <- function(..., colours, values = NULL, space = "Lab", na.value = "grey50",
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, ...
)
}
4 changes: 2 additions & 2 deletions R/scale-grey.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...)
}
8 changes: 4 additions & 4 deletions R/scale-hue.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@
#' }
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, ...)
}

#' @rdname scale_hue
#' @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, ...)
}

Expand Down Expand Up @@ -168,15 +168,15 @@ 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, ...
)
}

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, ...
)
}
Expand Down
18 changes: 9 additions & 9 deletions R/scale-identity.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions R/scale-linetype.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit cad1eaa

Please sign in to comment.