Skip to content

report a bug in ScaleBinned$get_breaks() #3574

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
microly opened this issue Oct 18, 2019 · 2 comments
Closed

report a bug in ScaleBinned$get_breaks() #3574

microly opened this issue Oct 18, 2019 · 2 comments

Comments

@microly
Copy link
Contributor

microly commented Oct 18, 2019

hi, @thomasp85
Firstly, thank you for your hard works to improve ggplot2!

I think there is a small bug in ScaleBinned$get_breaks(), which is in:

ggplot2/R/scale-.r

Lines 991 to 993 in 115c396

} else if (is.function(self$breaks)) {
breaks <- self$breaks(limits, self$n_bins)
} else {

As I known, end users has no way to set the value of ScaleBinned$n_bins, which has a NULL value by default.
So, when the breaks is a function provided by users, the function's second parameter will always set to be NULL.
As a consequence, users cannot get meaningful breaks by set breaks as a function in the scales, such as scale_colour_stepsn.

This is a simple example:

df <- data.frame(
    x = runif(100),
    y = runif(100),
    z = rnorm(100)
)

brk <- function(limits, n_bins) {
    if (is.null(n_bins))
        stop("n_bins is always set to be NULL, users cannot implement useful function for breaks.")
    else cat("users can set the value of n_bins, and get meaningful breaks using the values of limits and n_bins.")
}

library(ggplot2)

ggplot(df, aes(x, y)) +
    geom_point(aes(colour = z)) +
    scale_colour_stepsn(colours = terrain.colors(10), breaks = brk)

# Error in f(...) : 
# n_bins is always set to be NULL, users cannot implement useful function for breaks. 

I will opening a pull request for this bug, please consider it, thanks!

@lock
Copy link

lock bot commented May 20, 2020

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

1 similar comment
@lock
Copy link

lock bot commented May 20, 2020

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants