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

geom_density error when all groups are dropped #2282

Closed
stla opened this Issue Oct 5, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@stla

stla commented Oct 5, 2017

Hello,

library(ggplot2)
dat <- structure(list(include = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE
), Petal_Width = c(0.1234567, 1.4321, 1.5, 1.5, 1.3, 1.5), Species = c("setosa", 
"versicolor", "versicolor", "versicolor", "versicolor", "versicolor"
), Date = structure(c(1484524800, 1484611200, 1484697600, 1484784000, 
1484870400, 1485043200), class = c("POSIXct", "POSIXt"), tzone = "UTC")), .Names = c("include", 
"Petal_Width", "Species", "Date"), class = c("tbl_df", "tbl", 
"data.frame"), row.names = c(NA, -6L))
ggplot(dat, aes(x=Petal_Width)) + geom_density() + facet_wrap("Date")

This generates this error:

Error: Discrete value supplied to continuous scale
In addition: Warning messages:
1: Groups with fewer than two data points have been dropped. 
2: Groups with fewer than two data points have been dropped. 
3: Groups with fewer than two data points have been dropped. 
4: Groups with fewer than two data points have been dropped. 
5: Groups with fewer than two data points have been dropped. 
6: Groups with fewer than two data points have been dropped.

In fact, all groups are dropped. Then I think the error message is not very appropriate.

@karawoo

This comment has been minimized.

Member

karawoo commented Oct 6, 2017

In your example all of the groups (dates) only have a single data point, so I think the warning messages are accurate.

@stla

This comment has been minimized.

stla commented Oct 10, 2017

Yes, exactly, the warnings are accurate, but not the error message.

@hadley

This comment has been minimized.

Member

hadley commented Oct 30, 2017

Thanks for providing some code that illustrates the problem — it's a great start 😄 However, your code is currently a bit too complicated: there's quite a bit of extraneous stuff in there that doesn't seem directly related to the problem. Can you please try and simplify your example some more? The more minimal you can make the reprex, the faster I can identify the problem and fix it.

@hadley

This comment has been minimized.

Member

hadley commented Oct 30, 2017

Minimal reprex:

df <- data.frame(x = 1)
ggplot(df, aes(x)) + geom_density()
@hadley

This comment has been minimized.

Member

hadley commented Oct 30, 2017

Fixed in 49619b7

@hadley hadley closed this Oct 30, 2017

@lock lock bot locked as resolved and limited conversation to collaborators Jun 18, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.