wilkelab / ggridges

Ridgeline plots in ggplot2
https://wilkelab.org/ggridges
GNU General Public License v2.0
411 stars 31 forks source link

Alpha only controls ridge fill, not ridge color. #2

Closed mir-cat closed 6 years ago

mir-cat commented 7 years ago

Using the example from the README:

ggplot(diamonds, aes(x = price, y = cut)) +
    geom_density_ridges(scale = 2) + theme_ridges() +
    scale_y_discrete(expand = c(0.01, 0)) +   # will generally have to set the `expand` option
    scale_x_continuous(expand = c(0, 0))  

image


ggplot(diamonds, aes(x = price, y = cut)) +
    geom_density_ridges(scale = 2, alpha = 0.1) + theme_ridges() +
    scale_y_discrete(expand = c(0.01, 0)) +   # will generally have to set the `expand` option
    scale_x_continuous(expand = c(0, 0))  

image

In the help it says that alpha controls 'Transparency level of color and fill'. Right now it only seems to cover fill, as the outline remains unchanged with alpha.

Using ggridges version 0.4.1 on OSX

clauswilke commented 7 years ago

Yes, this is correct. The documentation is wrong. In general in ggplot2, for objects that have fill and color, alpha is only applied to fill. It's the same behavior as in geom_density(), for example.

If you absolutely want transparency on the lines, you can manually set a color that has the transparency you want:

ggplot(diamonds, aes(x = price, y = cut)) +
  # manually set color to black with 0.1 alpha (hex #0000001A)
  geom_density_ridges(scale = 2, alpha = 0.1, color = "#0000001A") + theme_ridges() +
  scale_y_discrete(expand = c(0.01, 0)) +   # will generally have to set the `expand` option
  scale_x_continuous(expand = c(0, 0))  
screen shot 2017-09-25 at 3 10 38 pm

Not sure how useful that is, though.

clauswilke commented 7 years ago

You can also use colors with transparency in scale_color_manual() if you want multiple different colors all with transparency.

mir-cat commented 7 years ago

Thanks! This solves my issue.

clauswilke commented 7 years ago

Reopening issue to flag that documentation needs to be fixed.