-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand ydensity range for nicer violin plots #1783
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
Conversation
Continuing examples from #1700: res <- data.frame(a = c(1:100),b=c(rep(0,50),rep(1,50)))
ggplot(res,aes(y=a,x=factor(b))) + geom_violin(trim=F) ggplot(res,aes(y=a,x=factor(b))) + geom_violin(trim=T) One visual regression is in how zero-range data is displayed is this now remains as a "violin" rather than a single line: dff <- data.frame(x = factor(rep(1, 10)), y = rep(0, 10))
ggplot(dff, aes(x, y)) + geom_violin() We can make a simple check for zero range condition and not expand in that case, but I'm not sure it is the right thing to do... |
I think that's the right behavior for zero range data |
The current or the proposed change (I personally prefer the current as it does not treat zero range differently) |
@@ -69,7 +69,22 @@ StatYdensity <- ggproto("StatYdensity", Stat, | |||
} else { | |||
range <- scales$y$dimension() | |||
} | |||
dens <- compute_density(data$y, data$w, from = range[1], to = range[2], | |||
if (is.character(bw)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind pulling this out into a separate function?
The plot that you included here seems like the correct behaviour to me. |
@@ -69,6 +69,8 @@ | |||
* The `theme()` constructor now has named arguments rather than ellipsis. This | |||
should make autocomplete substantially more useful. | |||
|
|||
* geom_violin now again has a nicer looking range that allow the density to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The range of each violin is now automatically extended 3 * bw for either end of the data range
LGTM |
I don't think this is the right behavior for |
@wch you mean it should also set the |
Yes, I think that's right. Here's what they looked like way back when they were first implemented: |
Then there's really no need for a fix? |
With |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
Fixes #1700