-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Don't switch scale type when using defaults #4456
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
Conversation
FYI: The ubuntu/ R3.3 run failed at the setting-up-R stage. I'm not going to restart all CI runs just for that. |
I think we should use this occasion to also add checks that the defaulted functions have the correct type and aesthetics, i.e. if the default is a function, expect the return value and see if it is a continuous scale for |
Just to be clear: Do you mean adding something like the following?
|
Yes, exactly... I feel this would be a good catch |
In fact, it would have helped me the other day when I was trying to figure out how to use this argument and was trying to provide a palette function. :-) Will do today or tomorrow. |
Ok, done I think. |
} | ||
if (isTRUE(scale$is_discrete())) { | ||
abort(glue("The `type` argument of `{name}()` must return a continuous scale for the {aesthetic} aesthetic, but the provided scale is discrete.")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we use this for the default discrete scale as well, in which case scale$is_discrete()
should match some input argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related issue for discrete scales: #4149
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll look into that issue and see if I can fix it also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for pilling onto what was effectively a documentation change🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thomasp85 Do you want an error or a warning when the scale doesn't contain the right aesthetic? @yutannihilation suggested a warning here, I have currently implemented an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this is done differently for continuous and discrete scales. Continuous scales don't look at the defaults of other aesthetics. Maybe we should merge the current PR as is and defer a broader cleanup of this issue to the next major release, when we wanted to somewhat change how scales work anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Sounds good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can merge this, but I'm very tempted to also fix the discrete scales for this release. The current behaviour is a mistake I think...
At least it should be avoided when the defaults are functions and only when a palette is provided
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But to be frank that would probably be more confusing than simply not inheriting across aesthetics at all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's the point for me: I think this requires a little more careful thinking, and I'm not sure I want to rush this. I can make arguments for either way. It's certainly confusing to have different default color palettes for colour
and fill
, but then it's also confusing to have a scale_colour_*()
applied to fill
or to trigger a "incorrect scale" error if you change the default colour scale to a different function and then want to use the fill
aesthetic.
Addresses this comment: #4450 (comment)
Reprex:
Created on 2021-04-28 by the reprex package (v1.0.0)