-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Set outline type for geom_density as geom_area #3708
Conversation
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.
Looks good, but..., I'm wondering if we can safely make this change.
Different from the case of GeomRibbon
, I guess there are already many usages of full-stroking outlines on GeomDensity
. That's why I didn't include GeomDensity
in #3529.
Probably I'm just too timid because changing the outline of GeomDensity
is one of my trauma around ggplot2. Let me think a bit more after drinking some coffee...
R/geom-density.r
Outdated
@@ -56,7 +57,9 @@ geom_density <- function(mapping = NULL, data = NULL, | |||
na.rm = FALSE, | |||
orientation = NA, | |||
show.legend = NA, | |||
inherit.aes = TRUE) { | |||
inherit.aes = TRUE, | |||
outline.type = 'upper') { |
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.
outline.type = 'upper') { | |
outline.type = "upper") { |
You need to add |
You are already breaking peoples code as geom_density now uses @hadley do you have any objections to this visual change? |
Hmm, you are right. Hope this is OK this time... |
@thomasp85 @hadley I want to propose renaming option |
I am honestly against. The full stroking of density plots has always looked ugly to my eye. I’m for the renaming, though The sides and lower bound in a density plot is not really data, and stroking them just creates visual noise IMO |
Thanks, agreed. After some investigation, I now agree that drawing the upper lines only is the right thing as base R does so. plot(density(diamonds$carat, adjust = 5)) What makes me uneasy with upper-only p <- ggplot(diamonds, aes(carat)) +
geom_density(adjust = 5)
patchwork::wrap_plots(
p + ggtitle("(default)"),
p + ggtitle("(expanded)") + expand_limits(x = -0.5)
)
Sure. |
I agree that the rightmost is more pleasing, but I think that ggplot2 has historically erred to the side of keeping the data-range. This is also done by default in violin plots. Extrapolating is something you have to do wilfully, as it creates data from thin air |
Sounds fair, but let me dig into the history... |
The new stroking of
geom_ribbon()
andgeom_area()
didn't make it togeom_density()
This PR adds it and make it behave likegeom_area()