Skip to content

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

Closed
@yutannihilation

Description

@yutannihilation

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 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions