-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Allow functional limits in continuous scales #2334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
3d2e6f7
302e697
c86d643
4cd6c4f
184bd2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,13 +107,17 @@ Scale <- ggproto("Scale", NULL, | |
stop("Not implemented", call. = FALSE) | ||
}, | ||
|
||
# if scale contains a function, apply it to the default (inverted) scale range | ||
# if scale contains a NULL, use the default scale range | ||
# if scale contains a NA, use the default range for that axis, otherwise | ||
# use the user defined limit for that axis | ||
get_limits = function(self) { | ||
if (self$is_empty()) return(c(0, 1)) | ||
|
||
if (!is.null(self$limits)) { | ||
if (is.function(self$limits)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're adding another condition here, can you please reframe the if statement along these lines: if (is.null()) {
} else if (is.function()) {
} else if (is.numeric()) {
} else {
stop("Informative error message", call. = FALSE)
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did rework this conditional to be more intuitive but since |
||
# if limits is a function, it expects to work in data space | ||
self$trans$transform(self$limits(self$trans$inverse(self$range$range))) | ||
} else if (!is.null(self$limits)) { | ||
ifelse(!is.na(self$limits), self$limits, self$range$range) | ||
} else { | ||
self$range$range | ||
|
@@ -526,8 +530,11 @@ ScaleDiscrete <- ggproto("ScaleDiscrete", Scale, | |
#' - A character vector giving labels (must be same length as `breaks`) | ||
#' - A function that takes the breaks as input and returns labels | ||
#' as output | ||
#' @param limits A numeric vector of length two providing limits of the scale. | ||
#' Use `NA` to refer to the existing minimum or maximum. | ||
#' @param limits One of: | ||
#' - A numeric vector of length two providing limits of the scale. | ||
dpseidel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#' Use `NA` to refer to the existing minimum or maximum | ||
#' - A function that accepts the existing (automatic) limits and returns | ||
#' new limits | ||
#' @param rescaler Used by diverging and n colour gradients | ||
#' (i.e. [scale_colour_gradient2()], [scale_colour_gradientn()]). | ||
#' A function used to scale the input values to the range \eqn{[0, 1]}. | ||
|
@@ -565,7 +572,7 @@ continuous_scale <- function(aesthetics, scale_name, palette, name = waiver(), | |
} | ||
|
||
trans <- as.trans(trans) | ||
if (!is.null(limits)) { | ||
if (!is.null(limits) && !is.function(limits)) { | ||
limits <- trans$transform(limits) | ||
} | ||
|
||
|
@@ -598,7 +605,7 @@ continuous_scale <- function(aesthetics, scale_name, palette, name = waiver(), | |
#' | ||
#' @export | ||
#' @inheritParams continuous_scale | ||
#' @param breaks One of: | ||
#' @param breaks One of: | ||
#' - `NULL` for no breaks | ||
#' - `waiver()` for the default breaks computed by the | ||
#' transformation object | ||
|
Uh oh!
There was an error while loading. Please reload this page.