Skip to content

breaking change: alpha now impacts the line of stat_ based geoms. #1523

Closed

Description

@antoine-lizee

This has changed following #1371, and I think (personally) that this is the wrong decision.
Pros: it's slightly more 'natural' to have alpha impacting both the line and fill (?)
Cons: the line texture is modified by the alpha parameter in a way that is irreversible, and thus you need a different geom for the common use case (to me) of having a solid line with a transparent filling.
Here is an example:

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 = "NA", alpha = 0.3) +
  geom_density(aes(x = price, y = ..count.. * 1000), color = "black", fill = NA) +
  facet_grid(cut ~ ., scales = "free_y", space = "free_y")

I would vote for reverting this behavior, as I'm pretty sure it's breaking more graphing code now than it would if reverted for 2.1.

The downside of the old behavior is that you need to change the color directly if you want something lighter.

Activity

  1. antoine-lizee commented on Jan 27, 2016

    @antoine-lizee
    Author

    A solve-it-all solution would be to have two different alpha parameters.

  2. joanwa commented on Feb 2, 2016

    @joanwa

    yes, please either revert or two different alpha parameters. This change broke many of my graphs...

  3. added
    bug
    on Feb 4, 2016
  4. added this to the v2.1.0 milestone on Feb 4, 2016
  5. antoine-lizee commented on Feb 6, 2016

    @antoine-lizee
    Author

    Thanks!

  6. yutannihilation commented on Feb 6, 2016

    @yutannihilation
    Member

    I'm sorry for those who suffered with the change I proposed 😭
    Hope someday some great person will discover some great solution which has more easier alpha semantics both for beginners and those who already got used to ggplot2....

  7. dhimmel commented on Apr 20, 2016

    @dhimmel

    +1 for separate parameters for line_alpha and fill_alpha (or just alpha as it is currently).

  8. antoine-lizee commented on Apr 20, 2016

    @antoine-lizee
    Author

    To answer requests from @dhimmel and others who need lines representing densities with alpha, geom_density is the wrong tool as it is designed to show an area. To get a line, use directly stat_density(geom = "line", alpha = 0.1, ...). Example:

    ggplot(diamonds %>% filter(cut %in% c("Very Good", "Ideal")), aes(x = price, fill = cut)) + theme_bw() + 
      geom_histogram(binwidth = 1000) +
      stat_density(aes(x = price, y = ..count.. * 1000), geom = "line", color = "black", alpha = 0.3) +
      facet_grid(cut ~ ., scales = "free_y", space = "free_y")
    
  9. dhimmel commented on Apr 20, 2016

    @dhimmel

    @antoine-lizee thanks for the workaround. I had to add position='identity' in ggplot2::stat_density so the distributions were not stacked.

  10. locked as resolved and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions