Skip to content

Commit ded2b47

Browse files
committed
user-facing function
1 parent f3a6fde commit ded2b47

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

R/plot-construction.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ ggplot_add.Scale <- function(object, plot, object_name) {
120120
plot$scales$add(object)
121121
plot
122122
}
123+
124+
#' @export
125+
ggplot_add.scale_params <- function(object, plot, object_name) {
126+
plot$scales$add_params(object$aesthetics, object$params)
127+
plot
128+
}
129+
123130
#' @export
124131
ggplot_add.labels <- function(object, plot, object_name) {
125132
update_labels(plot, object)

R/scale-.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,28 @@ binned_scale <- function(aesthetics, scale_name = deprecated(), palette, name =
214214
inject(super$new(!!!args, call = call %||% current_call()))
215215
}
216216

217+
218+
#' Setting scale parameters
219+
#'
220+
#' @param aesthetics The name of the aesthetics for which to update the scale.
221+
#' @param ... Named arguments to one of the scale constructors,
222+
#' [`continuous_scale()`], [`discrete_scale()`] or [`binned_scale()`].
223+
#'
224+
#' @return A `scale_params` object that can be added to a plot.
225+
#' @export
226+
#'
227+
#' @examples
228+
#' ggplot(mpg, aes(displ, hwy)) +
229+
#' geom_point() +
230+
#' scale_params("x", limits = c(0, 10)) +
231+
#' scale_params("y", transform = "sqrt")
232+
scale_params <- function(aesthetics, ...) {
233+
structure(
234+
list(aesthetics = aesthetics, params = list2(...)),
235+
class = "scale_params"
236+
)
237+
}
238+
217239
#' @section Scales:
218240
#'
219241
#' All `scale_*` functions like [scale_x_continuous()] return a `Scale*`

0 commit comments

Comments
 (0)