Skip to content

Check for dropped aesthetics #4866

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

Merged
merged 4 commits into from
Jul 7, 2022

Conversation

clauswilke
Copy link
Member

@clauswilke clauswilke commented Jun 9, 2022

Check for dropped aesthetics and issue a warning if aesthetics are dropped that shouldn't be. Fixes #3250.

As a consequence of this change, stats now need to advertise which aesthetics they are dropping, via the new dropped_aes field. If they don't, unit tests may fail because code now generates warnings that previously ran quietly.

Example of the new feature:

library(tidyverse)

ggplot(mtcars, aes(mpg, fill = am)) + geom_density(alpha = 0.4)
#> Warning: The following aesthetics were dropped during statistical transformation: fill
#> ℹ This can happen when ggplot fails to infer the correct grouping structure in
#>   the data.
#> ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
#>   variable into a factor?

ggplot(mtcars, aes(mpg, fill = am, group = am)) + geom_density(alpha = 0.4)

Created on 2022-06-09 by the reprex package (v2.0.0)

Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good - should we update the docs for the affected stats to say that these aesthetics are dropped? Seems like a nice thing to do

@clauswilke
Copy link
Member Author

Let me think about documenting the dropped aesthetics. In some cases it's just a temporary variable that gets dropped, so documenting that is not so useful. In other cases (e.g. stat_density_2d()) one of the input variables gets dropped, so documenting that makes sense.

@thomasp85
Copy link
Member

yeah - "thankfully" the stats aes documentation is not automatic so it is just a matter of cherry picking where to add it to the docs

@thomasp85
Copy link
Member

@clauswilke is it possible to get the docs updated soon? I plan to start the release process soonish to give the revdep maintainers the summer to fix potential issues

@clauswilke
Copy link
Member Author

@thomasp85 I think I can do it today. I was waiting for you to merge the vctrs PR, but that has happened, correct?

@thomasp85
Copy link
Member

Ah, sorry -- I missed that. Yes, vctrs has been merged in

@clauswilke
Copy link
Member Author

@thomasp85 I think I've addressed everything. I documented the stats where it seemed appropriate. In particular, I didn't document stat_boxplot() because I think it'd be more confusing if I did than if I didn't.

Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

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

Successfully merging this pull request may close these issues.

Unexpected failure of density plot without any error or warning
2 participants