Skip to content

n.breaks only supported when breaks = waiver() #5972

Closed
@teunbrand

Description

@teunbrand

This is a minor gripe, but in scale_*_continuous(n.breaks = 20), the n.breaks only kicks in when breaks = waiver() (the default).
The ask here is to also have n.breaks apply when giving a custom function(x, n) {...} so that one can flexibly combine breaks functions with the desired number of breaks.

Many scales::breaks_*() function factories have n as an argument in the constructor, so it isn't a direct problem for this function family.
However, it'd be swell if this would work for user-defined functions too.

As an example, I'd like the following two plots to be identical:

library(ggplot2)

p <- ggplot(mpg, aes(displ, hwy)) +
  geom_point()

p + scale_y_continuous(
    breaks = scales::breaks_extended(), # resulting function has `n` as argument
    n.breaks = 20
  )

p + scale_y_continuous(
    breaks = scales::breaks_extended(20),
  )

Created on 2024-07-03 with reprex v2.1.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions