Skip to content

Allow setting one of the limits of scale #684

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/limits.r
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ylim <- function(...) {
limits <- function(lims, var) UseMethod("limits")
limits.numeric <- function(lims, var) {
stopifnot(length(lims) == 2)
if (lims[1] > lims[2]) {
if (!any(is.na(lims)) && lims[1] > lims[2]) {
trans <- "reverse"
} else {
trans <- "identity"
Expand Down
9 changes: 8 additions & 1 deletion R/scale-.r
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,15 @@ scale_limits <- function(scale) {


#' @S3method scale_limits default
# 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
scale_limits.default <- function(scale) {
scale$limits %||% scale$range$range
if(!is.null(scale$limits)) {
ifelse(!is.na(scale$limits), scale$limits, scale$range$range)
} else {
scale$range$range
}
}

# @kohske
Expand Down