Skip to content

Bring stat_ydensity behavior in line with stat_density #4112

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 2 commits into from
Jul 6, 2020

Conversation

andrewwbutler
Copy link
Contributor

Addresses #4111

stat_ydensity now drops groups with fewer than 2 data points (previously 3) and displays a warning.

library(ggplot2)
table(mtcars$cyl, mtcars$am)
#>    
#>      0  1
#>   4  3  8
#>   6  4  3
#>   8 12  2
ggplot(mtcars, aes(x = factor(cyl), y = mpg, fill = factor(am))) + 
  geom_violin(scale = "width")

# warn when fewer than 2 in group
mtcars_sub <- mtcars[-31, ]
table(mtcars_sub$cyl, mtcars_sub$am)
#>    
#>      0  1
#>   4  3  8
#>   6  4  3
#>   8 12  1
ggplot(mtcars_sub, aes(x = factor(cyl), y = mpg, fill = factor(am))) + 
  geom_violin(scale = "width")
#> Warning: Groups with fewer than two data points have been dropped.

Created on 2020-07-01 by the reprex package (v0.3.0)

This change is intended to bring behavior of stat_ydensity in line
with stat_density. Previously dropped with fewer than 3, now drops
with fewer than 2 and will display a warning message when dropping.
Copy link
Member

@yutannihilation yutannihilation 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 to me. Added some minor comments.

Could you also add a NEWS item for this?

@andrewwbutler
Copy link
Contributor Author

Thanks! Committed the requested changes.

@yutannihilation
Copy link
Member

Thanks!

Could you also add a NEWS item for this?

Sorry, I'm not sure what I was saying while I was reviewing the NEWS item... 🙄

@yutannihilation yutannihilation merged commit 9c66494 into tidyverse:master Jul 6, 2020
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.

2 participants