Skip to content

Conversation

@yutannihilation
Copy link
Member

@yutannihilation yutannihilation commented Jul 23, 2022

Fix #4776

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.

We are now doing unit tests for all errors so can I get you to add tests for this

@yutannihilation
Copy link
Member Author

Sure

@yutannihilation
Copy link
Member Author

It seems this existing code will be broken by this change. I'm still thinking, but this might mean the same case can be found with stat_bin() and stat_count()...?

library(ggplot2)

do_plot <- function() {
  ggplot(mtcars, aes(mpg, factor(cyl))) +
    stat_density(aes(fill = after_stat(density)), geom = "raster", position = "identity")
}

do_plot()

devtools::load_all("~/GitHub/ggplot2/")
#> ℹ Loading ggplot2
do_plot()
#> Error in `stat_density(aes(fill = after_stat(density)), geom = "raster", position =
#> "identity")`:
#> ! Problem while computing stat.
#> ℹ Error occurred in the 1st layer.
#> Caused by error in `setup_params()` at ggplot2/R/ggproto.r:182:16:
#> ! `stat_density()` must only have an x or y aesthetic.

Created on 2022-07-27 by the reprex package (v2.0.1)

@clauswilke
Copy link
Member

@yutannihilation The example you found that breaks is an important use case I think. Fundamentally this highlights the core problem, which is that we don't explicitly distinguish between aesthetics given to the stat and to the geom. We may have to accept the confusing error message.

@yutannihilation
Copy link
Member Author

Thanks. Yes, I'm almost giving up this pull request. Rather, my current concern is if stat_bin() and stat_count() might be also wrong. The below example won't work even if I remove "must only have an x or y" check, but I don't figure out if this should work like the example of stat_density() above or not...

ggplot(mtcars, aes(mpg, factor(cyl))) +
  stat_bin(aes(fill = after_stat(count)), geom = "raster", position = "identity")

@yutannihilation
Copy link
Member Author

As this pull request seems impossible, I'm giving up this. Sorry that I didn't come up with the usage.

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.

Confusing error message and documentation for geom_density

3 participants