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

Checking limits argument in scale_<x|y>_continuous #6092

Closed
llrs opened this issue Sep 8, 2024 · 1 comment · Fixed by #6114
Closed

Checking limits argument in scale_<x|y>_continuous #6092

llrs opened this issue Sep 8, 2024 · 1 comment · Fixed by #6114
Labels
messages requests for improvements to error, warning, or feedback messages scales 🐍

Comments

@llrs
Copy link
Contributor

llrs commented Sep 8, 2024

I added limits = c(1, 2, 3) to a scale_* and I didn't realize it (I though I used breaks). But was surprised by the resulting plot: it only uses the two first values and discards the rest (Totally logic and consistent).

But the documentation says:

A numeric vector of length two providing limits of the scale. Use NA to refer to the existing minimum or maximum

I would like to receive an error if the vector used in limits for scales is larger than 2. This would help to fail with an informative error. I got a warning of Removed <x> rows containing missing values or values outside the scale range:

library("ggplot2")
ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  scale_x_continuous(limits = c(1, 5, 10))
## Warning message:
## Removed 36 rows containing missing values or values outside the scale range (`geom_point()`). 

Expected:

library("ggplot2")
ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  scale_x_continuous(limits = c(1, 5, 10))
## Error in scale_x_continuous: 
## Provided limits for three dimensions when only two are used.  

This might happen to other limits from other scale_* functions or in other arguments

@teunbrand teunbrand added scales 🐍 messages requests for improvements to error, warning, or feedback messages labels Sep 9, 2024
@llrs
Copy link
Contributor Author

llrs commented Oct 31, 2024

Thanks! This will make easier to spot mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
messages requests for improvements to error, warning, or feedback messages scales 🐍
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants