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

Use alpha for lines of geom_density(), geom_bar(), and so on #1371

Closed
yutannihilation opened this Issue Oct 15, 2015 · 7 comments

Comments

Projects
None yet
3 participants
@yutannihilation
Member

yutannihilation commented Oct 15, 2015

Hi, thanks for this great package!

I saw many people (including me) are confused at the behavior of alpha when used in Geoms which draw areas or rects (e.g. geom_desity()). So, let me ask if this is your design decision or not.

When I draw a chart with alpha, I expect that the whole layer, the line and fill, will become transparent. But the line stays clear red.

ggplot(diamonds, aes(carat)) +
    geom_density(fill = "red", colour = "red", alpha = 0.1)

plot3

I expect the one like this.

plot1

I know we can draw the latter chart by using colour=alpha("red", 0.1), but I believe alpha is a transparency param for the entire layer, not only for the line or the fill. For me, this is a matter of semantics. Are there any reason not to use alpha for colour?

The possible implementation is very simple. We just need to change those two lines to col = alpha(aes$colour, aes$alpha):

https://github.com/hadley/ggplot2/blob/bbc1b5ad3c0f55e8809d4fe1a9bd2783eb9fa29c/R/geom-rect.r#L55
https://github.com/hadley/ggplot2/blob/bbc1b5ad3c0f55e8809d4fe1a9bd2783eb9fa29c/R/geom-ribbon.r#L95

If this looks good to you, I'm happy to submit PR 😄

@hadley

This comment has been minimized.

Member

hadley commented Oct 15, 2015

It was a deliberate design decision. But now I can't remember why 😦 I think I had a good reason though.

@yutannihilation

This comment has been minimized.

Member

yutannihilation commented Oct 15, 2015

Hmm..., thanks for your quick answer, anyway.

I found the behavior of alpha have been this way from the time it was born, but no background is described in the commit message.

36d5ad2

Okay, I trust in you this time. You always have a good reason; the very fact can be a good reason for me to close this issue 👍. Please close this issue anytime!

But, I hope you will occasionally remember that not a few people are confused at this. At least, this should be included in ggplot2 book.

@hadley hadley closed this in 2105a02 Nov 9, 2015

@hadley hadley added the feature label Nov 9, 2015

@hadley hadley added this to the v1.1.0 milestone Nov 9, 2015

@hadley

This comment has been minimized.

Member

hadley commented Nov 9, 2015

You're right - it's more consistent to affect both. Done!

@yutannihilation

This comment has been minimized.

Member

yutannihilation commented Nov 9, 2015

Wow!!! Thanks for your decision! You are always great 👍

@antoine-lizee

This comment has been minimized.

antoine-lizee commented Jan 27, 2016

I am so sorry to see this! You should believe in yourself more hadley :-).
As a result, there is no way to separately tune the line and the fill without using two geoms now, one with fill = NA and another with color = NA. My very common use case is to have a transparent filing with a solid line - it is now impossible:

ggplot(diamonds %>% filter(cut %in% c("Very Good", "Ideal")), aes(x = price, fill = cut)) + theme_bw() + 
  geom_histogram(binwidth = 1000) +
  geom_density(aes(x = price, y = ..count.. * 1000), color = "black", alpha = 0.3) +
  geom_density(aes(x = price, y = ..count.. * 1000), color = "black", fill = NA) +
  facet_grid(cut ~ ., scales = "free_y")

While if you wanted to get the line lighter, you can always change its color!

Could we revert this? I'm pretty sure it's breaking more code now than it would if reverted for 2.1...

@hadley

This comment has been minimized.

Member

hadley commented Jan 27, 2016

@antoine-lizee can you please file a new issue? I'm likely to lose track of an old issue with a comment.

@antoine-lizee

This comment has been minimized.

antoine-lizee commented Jan 27, 2016

Of course. #1523

hadley added a commit that referenced this issue Feb 4, 2016

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

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