Skip to content

Commit c00f875

Browse files
authored
Use new {scales} syntax (#5544)
* increment scales version * Use `transform_` prefixed version * rename palettes * reoxygenate
1 parent f155d2f commit c00f875

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+203
-203
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Imports:
4040
MASS,
4141
mgcv,
4242
rlang (>= 1.1.0),
43-
scales (>= 1.2.0),
43+
scales (>= 1.3.0),
4444
stats,
4545
tibble,
4646
vctrs (>= 0.5.0),

R/axis-secondary.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
280280
},
281281

282282
# Temporary scale for the purpose of calling break_info()
283-
create_scale = function(self, range, trans = identity_trans()) {
283+
create_scale = function(self, range, trans = transform_identity()) {
284284
scale <- ggproto(NULL, ScaleContinuousPosition,
285285
name = self$name,
286286
breaks = self$breaks,

R/coord-transform.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#' no guarantee that straight lines will continue to be straight.
66
#'
77
#' Transformations only work with continuous values: see
8-
#' [scales::trans_new()] for list of transformations, and instructions
8+
#' [scales::new_transform()] for list of transformations, and instructions
99
#' on how to create your own.
1010
#'
1111
#' @inheritParams coord_cartesian
@@ -60,7 +60,7 @@
6060
#' geom_smooth(method = "lm") +
6161
#' scale_x_log10() +
6262
#' scale_y_log10() +
63-
#' coord_trans(x = scales::exp_trans(10), y = scales::exp_trans(10))
63+
#' coord_trans(x = scales::transform_exp(10), y = scales::transform_exp(10))
6464
#'
6565
#' # cf.
6666
#' ggplot(diamonds, aes(carat, price)) +
@@ -90,8 +90,8 @@ coord_trans <- function(x = "identity", y = "identity", xlim = NULL, ylim = NULL
9090
check_coord_limits(ylim)
9191

9292
# resolve transformers
93-
if (is.character(x)) x <- as.trans(x)
94-
if (is.character(y)) y <- as.trans(y)
93+
if (is.character(x)) x <- as.transform(x)
94+
if (is.character(y)) y <- as.transform(y)
9595

9696
ggproto(NULL, CoordTrans,
9797
trans = list(x = x, y = y),
@@ -190,7 +190,7 @@ transform_value <- function(trans, value, range) {
190190
# TODO: can we merge this with view_scales_from_scale()?
191191
view_scales_from_scale_with_coord_trans <- function(scale, coord_limits, trans, expand = TRUE) {
192192
expansion <- default_expansion(scale, expand = expand)
193-
scale_trans <- scale$trans %||% identity_trans()
193+
scale_trans <- scale$trans %||% transform_identity()
194194
coord_limits <- coord_limits %||% scale_trans$inverse(c(NA, NA))
195195
scale_limits <- scale$get_limits()
196196

R/guide-axis-logticks.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ GuideAxisLogticks <- ggproto(
154154
"{.field {trans_name}} transformation in log-tick positioning."
155155
))
156156
}
157-
trans <- log_trans(base = params$prescale_base)
157+
trans <- transform_log(base = params$prescale_base)
158158
} else {
159159
trans <- scale$scale$trans
160160
}

R/scale-.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
#' that should be used for error messages associated with this scale.
88
#' @param palette A palette function that when called with a numeric vector with
99
#' values between 0 and 1 returns the corresponding output values
10-
#' (e.g., [scales::area_pal()]).
10+
#' (e.g., [scales::pal_area()]).
1111
#' @param name The name of the scale. Used as the axis or legend title. If
1212
#' `waiver()`, the default, the name of the scale is taken from the first
1313
#' mapping used for that aesthetic. If `NULL`, the legend title will be
1414
#' omitted.
1515
#' @param breaks One of:
1616
#' - `NULL` for no breaks
1717
#' - `waiver()` for the default breaks computed by the
18-
#' [transformation object][scales::trans_new()]
18+
#' [transformation object][scales::new_transform()]
1919
#' - A numeric vector of positions
2020
#' - A function that takes the limits as input and returns breaks
2121
#' as output (e.g., a function returned by [scales::extended_breaks()]).
@@ -75,8 +75,8 @@
7575
#' and methods for generating breaks and labels. Transformation objects
7676
#' are defined in the scales package, and are called `<name>_trans`. If
7777
#' transformations require arguments, you can call them from the scales
78-
#' package, e.g. [`scales::boxcox_trans(p = 2)`][scales::boxcox_trans].
79-
#' You can create your own transformation with [scales::trans_new()].
78+
#' package, e.g. [`scales::transform_boxcox(p = 2)`][scales::transform_boxcox].
79+
#' You can create your own transformation with [scales::new_transform()].
8080
#' @param guide A function used to create a guide or its name. See
8181
#' [guides()] for more information.
8282
#' @param expand For position scales, a vector of range expansion constants used to add some
@@ -113,7 +113,7 @@ continuous_scale <- function(aesthetics, scale_name = deprecated(), palette, nam
113113
guide <- "none"
114114
}
115115

116-
trans <- as.trans(trans)
116+
trans <- as.transform(trans)
117117
if (!is.null(limits) && !is.function(limits)) {
118118
limits <- trans$transform(limits)
119119
}
@@ -157,7 +157,7 @@ continuous_scale <- function(aesthetics, scale_name = deprecated(), palette, nam
157157
#' @inheritParams continuous_scale
158158
#' @param palette A palette function that when called with a single integer
159159
#' argument (the number of levels in the scale) returns the values that
160-
#' they should take (e.g., [scales::hue_pal()]).
160+
#' they should take (e.g., [scales::pal_hue()]).
161161
#' @param breaks One of:
162162
#' - `NULL` for no breaks
163163
#' - `waiver()` for the default breaks (the scale limits)
@@ -278,7 +278,7 @@ binned_scale <- function(aesthetics, scale_name = deprecated(), palette, name =
278278
guide <- "none"
279279
}
280280

281-
trans <- as.trans(trans)
281+
trans <- as.transform(trans)
282282
if (!is.null(limits)) {
283283
limits <- trans$transform(limits)
284284
}
@@ -603,7 +603,7 @@ ScaleContinuous <- ggproto("ScaleContinuous", Scale,
603603
oob = censor,
604604
minor_breaks = waiver(),
605605
n.breaks = NULL,
606-
trans = identity_trans(),
606+
trans = transform_identity(),
607607

608608
is_discrete = function() FALSE,
609609

R/scale-alpha.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#' p + scale_alpha("cylinders")
2525
#' p + scale_alpha(range = c(0.4, 0.8))
2626
scale_alpha <- function(..., range = c(0.1, 1)) {
27-
continuous_scale("alpha", palette = rescale_pal(range), ...)
27+
continuous_scale("alpha", palette = pal_rescale(range), ...)
2828
}
2929

3030
#' @rdname scale_alpha
@@ -34,7 +34,7 @@ scale_alpha_continuous <- scale_alpha
3434
#' @rdname scale_alpha
3535
#' @export
3636
scale_alpha_binned <- function(..., range = c(0.1, 1)) {
37-
binned_scale("alpha", palette = rescale_pal(range), ...)
37+
binned_scale("alpha", palette = pal_rescale(range), ...)
3838
}
3939

4040
#' @rdname scale_alpha
@@ -60,12 +60,12 @@ scale_alpha_ordinal <- function(..., range = c(0.1, 1)) {
6060
#' @export
6161
#' @usage NULL
6262
scale_alpha_datetime <- function(..., range = c(0.1, 1)) {
63-
datetime_scale("alpha", "time", palette = rescale_pal(range), ...)
63+
datetime_scale("alpha", "time", palette = pal_rescale(range), ...)
6464
}
6565

6666
#' @rdname scale_alpha
6767
#' @export
6868
#' @usage NULL
6969
scale_alpha_date <- function(..., range = c(0.1, 1)){
70-
datetime_scale("alpha", "date", palette = rescale_pal(range), ...)
70+
datetime_scale("alpha", "date", palette = pal_rescale(range), ...)
7171
}

R/scale-brewer.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#'
99
#' @note
1010
#' The `distiller` scales extend `brewer` scales by smoothly
11-
#' interpolating 7 colours from any palette to a continuous scale.
11+
#' interpolating 7 colours from any palette to a continuous scale.
1212
#' The `distiller` scales have a default direction = -1. To reverse, use direction = 1.
1313
#' The `fermenter` scales provide binned versions of the `brewer` scales.
1414
#'
@@ -27,10 +27,10 @@
2727
#' }
2828
#' Modify the palette through the `palette` argument.
2929
#'
30-
#' @inheritParams scales::brewer_pal
30+
#' @inheritParams scales::pal_brewer
3131
#' @inheritParams scale_colour_hue
3232
#' @inheritParams scale_colour_gradient
33-
#' @inheritParams scales::gradient_n_pal
33+
#' @inheritParams scales::pal_gradient_n
3434
#' @param palette If a string, will use that named palette. If a number, will index into
3535
#' the list of palettes of appropriate `type`. The list of available palettes can found
3636
#' in the Palettes section.
@@ -52,7 +52,7 @@
5252
#' # Change scale label
5353
#' d + scale_colour_brewer("Diamond\nclarity")
5454
#'
55-
#' # Select brewer palette to use, see ?scales::brewer_pal for more details
55+
#' # Select brewer palette to use, see ?scales::pal_brewer for more details
5656
#' d + scale_colour_brewer(palette = "Greens")
5757
#' d + scale_colour_brewer(palette = "Set1")
5858
#'
@@ -84,13 +84,13 @@
8484
#' v + scale_fill_fermenter()
8585
#'
8686
scale_colour_brewer <- function(..., type = "seq", palette = 1, direction = 1, aesthetics = "colour") {
87-
discrete_scale(aesthetics, palette = brewer_pal(type, palette, direction), ...)
87+
discrete_scale(aesthetics, palette = pal_brewer(type, palette, direction), ...)
8888
}
8989

9090
#' @export
9191
#' @rdname scale_brewer
9292
scale_fill_brewer <- function(..., type = "seq", palette = 1, direction = 1, aesthetics = "fill") {
93-
discrete_scale(aesthetics, palette = brewer_pal(type, palette, direction), ...)
93+
discrete_scale(aesthetics, palette = pal_brewer(type, palette, direction), ...)
9494
}
9595

9696
#' @export
@@ -106,7 +106,7 @@ scale_colour_distiller <- function(..., type = "seq", palette = 1, direction = -
106106
}
107107
continuous_scale(
108108
aesthetics,
109-
palette = gradient_n_pal(brewer_pal(type, palette, direction)(7), values, space),
109+
palette = pal_gradient_n(pal_brewer(type, palette, direction)(7), values, space),
110110
na.value = na.value, guide = guide, ...
111111
)
112112
# NB: 6-7 colours per palette gives nice gradients; more results in more saturated colours which do not look as good
@@ -125,7 +125,7 @@ scale_fill_distiller <- function(..., type = "seq", palette = 1, direction = -1,
125125
}
126126
continuous_scale(
127127
aesthetics,
128-
palette = gradient_n_pal(brewer_pal(type, palette, direction)(7), values, space),
128+
palette = pal_gradient_n(pal_brewer(type, palette, direction)(7), values, space),
129129
na.value = na.value, guide = guide, ...
130130
)
131131
}
@@ -141,7 +141,7 @@ scale_colour_fermenter <- function(..., type = "seq", palette = 1, direction = -
141141
"i" = "Consider using {.code type = \"seq\"} or {.code type = \"div\"} instead"
142142
))
143143
}
144-
binned_scale(aesthetics, palette = binned_pal(brewer_pal(type, palette, direction)), na.value = na.value, guide = guide, ...)
144+
binned_scale(aesthetics, palette = pal_binned(pal_brewer(type, palette, direction)), na.value = na.value, guide = guide, ...)
145145
}
146146

147147
#' @export
@@ -154,5 +154,5 @@ scale_fill_fermenter <- function(..., type = "seq", palette = 1, direction = -1,
154154
"i" = "Consider using {.code type = \"seq\"} or {.code type = \"div\"} instead"
155155
))
156156
}
157-
binned_scale(aesthetics, palette = binned_pal(brewer_pal(type, palette, direction)), na.value = na.value, guide = guide, ...)
157+
binned_scale(aesthetics, palette = pal_binned(pal_brewer(type, palette, direction)), na.value = na.value, guide = guide, ...)
158158
}

R/scale-continuous.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464
#' p1 + scale_y_reverse()
6565
#'
6666
#' # Or you can supply a transformation in the `trans` argument:
67-
#' p1 + scale_y_continuous(trans = scales::reciprocal_trans())
67+
#' p1 + scale_y_continuous(trans = scales::transform_reciprocal())
6868
#'
69-
#' # You can also create your own. See ?scales::trans_new
69+
#' # You can also create your own. See ?scales::new_transform
7070
#'
7171
#' @name scale_continuous
7272
#' @aliases NULL
@@ -169,30 +169,30 @@ ScaleContinuousPosition <- ggproto("ScaleContinuousPosition", ScaleContinuous,
169169
#' @rdname scale_continuous
170170
#' @export
171171
scale_x_log10 <- function(...) {
172-
scale_x_continuous(..., trans = log10_trans())
172+
scale_x_continuous(..., trans = transform_log10())
173173
}
174174
#' @rdname scale_continuous
175175
#' @export
176176
scale_y_log10 <- function(...) {
177-
scale_y_continuous(..., trans = log10_trans())
177+
scale_y_continuous(..., trans = transform_log10())
178178
}
179179
#' @rdname scale_continuous
180180
#' @export
181181
scale_x_reverse <- function(...) {
182-
scale_x_continuous(..., trans = reverse_trans())
182+
scale_x_continuous(..., trans = transform_reverse())
183183
}
184184
#' @rdname scale_continuous
185185
#' @export
186186
scale_y_reverse <- function(...) {
187-
scale_y_continuous(..., trans = reverse_trans())
187+
scale_y_continuous(..., trans = transform_reverse())
188188
}
189189
#' @rdname scale_continuous
190190
#' @export
191191
scale_x_sqrt <- function(...) {
192-
scale_x_continuous(..., trans = sqrt_trans())
192+
scale_x_continuous(..., trans = transform_sqrt())
193193
}
194194
#' @rdname scale_continuous
195195
#' @export
196196
scale_y_sqrt <- function(...) {
197-
scale_y_continuous(..., trans = sqrt_trans())
197+
scale_y_continuous(..., trans = transform_sqrt())
198198
}

R/scale-date.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ scale_x_time <- function(name = waiver(),
242242
na.value = na.value,
243243
guide = guide,
244244
position = position,
245-
trans = scales::hms_trans(),
245+
trans = scales::transform_hms(),
246246
sec.axis = sec.axis
247247
)
248248
}
@@ -273,7 +273,7 @@ scale_y_time <- function(name = waiver(),
273273
na.value = na.value,
274274
guide = guide,
275275
position = position,
276-
trans = scales::hms_trans(),
276+
trans = scales::transform_hms(),
277277
sec.axis = sec.axis
278278
)
279279
}
@@ -326,8 +326,8 @@ datetime_scale <- function(aesthetics, trans, palette,
326326
}
327327

328328
trans <- switch(trans,
329-
date = date_trans(),
330-
time = time_trans(timezone)
329+
date = transform_date(),
330+
time = transform_time(timezone)
331331
)
332332

333333
sc <- continuous_scale(
@@ -357,7 +357,7 @@ ScaleContinuousDatetime <- ggproto("ScaleContinuousDatetime", ScaleContinuous,
357357
tz <- attr(x, "tzone")
358358
if (is.null(self$timezone) && !is.null(tz)) {
359359
self$timezone <- tz
360-
self$trans <- time_trans(self$timezone)
360+
self$trans <- transform_time(self$timezone)
361361
}
362362
ggproto_parent(ScaleContinuous, self)$transform(x)
363363
},

R/scale-expansion.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ expand_limits_discrete <- function(limits, expand = expansion(0, 0), coord_limit
168168
}
169169

170170
expand_limits_continuous_trans <- function(limits, expand = expansion(0, 0),
171-
coord_limits = c(NA, NA), trans = identity_trans()) {
171+
coord_limits = c(NA, NA), trans = transform_identity()) {
172172

173173
# let non-NA coord_limits override the scale limits
174174
limits <- ifelse(is.na(coord_limits), limits, coord_limits)
@@ -198,7 +198,7 @@ expand_limits_continuous_trans <- function(limits, expand = expansion(0, 0),
198198
}
199199

200200
expand_limits_discrete_trans <- function(limits, expand = expansion(0, 0),
201-
coord_limits = c(NA, NA), trans = identity_trans(),
201+
coord_limits = c(NA, NA), trans = transform_identity(),
202202
range_continuous = NULL) {
203203
if (is.discrete(limits)) {
204204
n_discrete_limits <- length(limits)

0 commit comments

Comments
 (0)