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

Could scale_*_manual have a default values argument of NULL? #5653

Open
davidhodge931 opened this issue Jan 19, 2024 · 5 comments
Open

Could scale_*_manual have a default values argument of NULL? #5653

davidhodge931 opened this issue Jan 19, 2024 · 5 comments

Comments

@davidhodge931
Copy link

The scale_*_manual functions are super useful. Is it possible that the values argument in these could default to NULL? This would allow users familiar with them to use them to change other non-values aspects of the scale through these functions

library(tidyverse)

p <- ggplot(mtcars, aes(mpg, wt)) +
  geom_point(aes(colour = factor(cyl)))

#you can do this currently
p + 
  scale_colour_manual(values = c("red", "blue", "green"),
                      breaks = c(4, 6))

#I would like to be able to do this
p + 
  scale_colour_manual(breaks = c(4, 6))
#> Error in `palette()`:
#> ! Insufficient values in manual scale. 3 needed but only 0 provided.

Created on 2024-01-20 with reprex v2.1.0

@teunbrand
Copy link
Collaborator

What would be the intended outcome of the manual scale without values?

@davidhodge931
Copy link
Author

The outcome is that the manual scale turns up with NULL values, which would do whatever ggplot2 would do by default for the values if scale layer wasn't called

@davidhodge931
Copy link
Author

In the example below, I want the same graph to be produced without me having to specify what the values are

library(tidyverse)
library(palmerpenguins)

ggplot(mtcars, aes(mpg, wt)) +
  geom_point(aes(colour = factor(cyl))) + 
  scale_colour_manual(values = scales::pal_hue()(3), breaks = c(4, 6))

Created on 2024-01-21 with reprex v2.1.0

@davidhodge931 davidhodge931 changed the title Could scale_*manual have a default values argument of NULL? Could scale_*_manual have a default values argument of NULL? Jan 20, 2024
@teunbrand
Copy link
Collaborator

Right, I think this falls under the umbrella of #4269. To briefly recap, it has been on the wishlist for a while to set scale parameters without explicitly declaring the scale itself. This is similar to your example where you want to set the breaks but not other parameters, such as the palette.

There have been several attempts at implementing this, namely two in #4271 and one in #5444.
The reason that these efforts have been fruitless, is because we cannot implement it in a clean way. Or maybe we can, but haven't found the way yet. I think it'd be only possible to do cleanly if the scale system gets a major overhaul.

That said, using scale_colour_discrete() sort of uses the default palette while leaving room to mess with breaks or limits etc.

@davidhodge931
Copy link
Author

Thanks @teunbrand the partial scales thing looks super useful.

With regard to the scale_*_manual layers, can you not just make the values argument NULL, and then tell it to do the standard defaults when it is NULL?

Assume it's not that simple??

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

No branches or pull requests

2 participants