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

Fix error message for geom_density() when using y #3514

Closed
Maschette opened this issue Sep 2, 2019 · 8 comments
Closed

Fix error message for geom_density() when using y #3514

Maschette opened this issue Sep 2, 2019 · 8 comments

Comments

@Maschette
Copy link
Contributor

Hi,
The error message for geom_density() when using x and y comes up and says y is missing. My suggestion would be to change the error when x and y are present but stat is not identity to "y is present, did you mean to use stat = 'identity'" or something like that. Also adding an example that uses x and y to https://ggplot2.tidyverse.org/reference/geom_density.html would be great.

x<-data.frame(value=seq(0,1,by=0.2), count=rnorm(6, mean = 10) )

library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 3.6.1

ggplot(x)+geom_density(aes(x=value, y=count))
#> Error: geom_density requires the following missing aesthetics: y

ggplot(x)+geom_density(aes(x=value, y=count), stat = 'identity')

Created on 2019-09-02 by the reprex package (v0.3.0)

@batpigandme
Copy link
Contributor

Hi Dale,
Would you want to do a PR for this?

@Maschette
Copy link
Contributor Author

Hi Mara,
If i knew how I might. I find tracking of error messages in ggplot really hard so I might leave it to someone else.

Thanks for asking though.

@batpigandme
Copy link
Contributor

Completely understood!

@yutannihilation
Copy link
Member

I agree about the error message, but I don't feel it's nice to use geom_density() without stat_density(). Maybe you should use geom_area()?

@carywreams
Copy link
Contributor

carywreams commented Dec 8, 2019

Question 1

Should this have been closed as indicated in #3519 ?

Question 2

Looks like a check for/warning of 'supplied x and y but specified stat="density" by default') could be applied in R/geom-density.r during the GeomDensity call to ggplot.

Right track ?

I'll be looking through other geom- source for similar compatibility checks.

My Notes

@stragu
Copy link
Contributor

stragu commented Aug 10, 2020

@thomasp85 , sorry if I misunderstood this, but it seems the issue as described by @Maschette is still the same in ggplot2 3.3.2:

x <- data.frame(value = seq(0, 1, by = 0.2),
                count = rnorm(6, mean = 10))
library(ggplot2)
ggplot(x) +
  geom_density(aes(x = value, y = count))
#> Error: geom_density requires the following missing aesthetics: y

Created on 2020-08-10 by the reprex package (v0.3.0)

@chasemc
Copy link

chasemc commented Mar 30, 2022

Same for v3.3.5

@francisbarton
Copy link

@Maschette this helped me solve the error message, when nothing else on the internet did. Thank you.

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 a pull request may close this issue.

8 participants