Skip to content

Change minor_breaks interface #3591

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
19 changes: 16 additions & 3 deletions R/scale-.r
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
#' - `waiver()` for the default breaks (one minor break between
#' each major break)
#' - A numeric vector of positions
#' - A function that given the limits returns a vector of minor breaks.
#' - A function passed the limits and major breaks, which should return a
#' vector of minor breaks.
#' @param labels One of:
#' - `NULL` for no labels
#' - `waiver()` for the default labels computed by the
Expand Down Expand Up @@ -613,8 +614,20 @@ ScaleContinuous <- ggproto("ScaleContinuous", Scale,
breaks <- self$trans$minor_breaks(b, limits, n)
}
} else if (is.function(self$minor_breaks)) {
# Find breaks in data space, and convert to numeric
breaks <- self$minor_breaks(self$trans$inverse(limits))
# Need to reach inside of ggproto method to get actual function
# This is fine because it's not a method, it's a function supplied by the
# user that is assigned into the ggproto object on creation
breaks_fun <- environment(self$minor_breaks)$f

# Limits are on transformed scale, so we need to back transform
# so breaks function can work in original data space
if (length(formals(breaks_fun)) == 1) {
# Old API just gets limits
breaks <- breaks_fun(self$trans$inverse(limits))
} else {
# New API gets limits and breaks
breaks <- breaks_fun(self$trans$inverse(limits), self$trans$inverse(b))
}
breaks <- self$trans$transform(breaks)
} else {
breaks <- self$trans$transform(self$minor_breaks)
Expand Down
3 changes: 2 additions & 1 deletion man/continuous_scale.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/scale_continuous.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/scale_gradient.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/scale_size.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.