Skip to content

Check for dropped aesthetics - #4866

Merged
clauswilke merged 4 commits into
tidyverse:mainfrom
wilkelab:issue-3250-dropped-columns
Jul 7, 2022
Merged

clauswilke merged 4 commits into
tidyverse:mainfrom
wilkelab:issue-3250-dropped-columns

Conversation

@clauswilke

@clauswilke clauswilke commented Jun 9, 2022 •

Copy link
Copy Markdown
Member

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)

@thomasp85 thomasp85 left a comment

Copy link
Copy Markdown
Member

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

Comment thread R/stat-density-2d.r Resolved
Comment thread R/stat-.r Resolved
@clauswilke

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

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

@clauswilke

Copy link
Copy Markdown
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.

@thomasp85 thomasp85 left a comment

Copy link
Copy Markdown
Member

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