How to create a continuous legend (color bar style) for scale_alpha?

Viewed 5235

Currently, a continuous colour bar legend, guide_colorbar is available only with scale_fill and scale_colour, and not with scale_alpha. The legend which is generated with scale_alpha is of a discrete type (guide_legend).

A small example where color and alpha are mapped to a continuous variable:

scale_color generates a continuous color bar type legend :

ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width, color = Sepal.Width)) +
  geom_point()

enter image description here

scale_alpha generates a discrete legend, despite alpha is mapped to a continuous variable:

ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width, alpha = Sepal.Width)) +
  geom_point()

enter image description here

Is there some way to get a continuous color bar legend also for scale_alpha?

1 Answers
Related