Skip to content
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

Axis breaks above max data value #6120

Open
Olivia-Box-Power opened this issue Sep 25, 2024 · 1 comment
Open

Axis breaks above max data value #6120

Olivia-Box-Power opened this issue Sep 25, 2024 · 1 comment

Comments

@Olivia-Box-Power
Copy link

Often when producing a chart I'd like the top y axis break to be above the maximum data value. E.g. on the following chart I'd like there to be a break at 100.

library(ggplot2)

df <- data.frame(class = c("A", "B", "c"), value = c(80, 50, 95))

ggplot(df, aes(class, value)) +
  geom_col()

Created on 2024-09-25 with reprex v2.1.1

I can set the breaks manually using scale_y_continuous if I know what the data values are. However, often I don't know the range of values in advance.

This stack overflow post provides a solution to this problem, using the pretty function to set the breaks and limits in scale_y_continuous. I was wondering though if it would be possible to have an option in scale_x/y_continuous to say that the max axis break should be above the max value?

Apologies if this has been requested previously.

@teunbrand
Copy link
Collaborator

I endorse Stefan's answer to this problem: use a function to set whatever rule you'd like for your limits. The function recieves the natural limits of the data and should return the limits you want to use.

Providing a function gives all sorts of flexibilities so that many rules about limits, breaks or labels don't need separate arguments in the scale functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants