(This is a very old question, but I had the same issue and couldn't find an answer. The previous solution by hugh-allan is, as indicated in the Edit note, producing an incorrect legend.)
The settings of the scale should really be in the scale_alpha*
parameter. That's where you manage this. The geoms
are used for adding the data or setting a style for all points, not tuning a specific scale (otherwise, it would need to be inside the aes()
mapping).
To be clear, there are two options in current versions of ggplot2 (using version 3.3.5):
tibble(x = 1:10, y = 1) %>%
ggplot(aes(x, y, alpha = x) +
geom_point(size = 5) +
scale_alpha(trans = reverse_trans())
or, probably more in line with current ggplot documentation:
scale_alpha(range = c(1, 0.1))
i.e., reversing the range of the alpha scale (the default is range = c(1, 0.1)
).
geom_point(aes(colour=variableA, alpha=-variableB)
? But you might want to modify the scale labels then.rev
instead ofREVERSE
.rev(variableB)
is not what you want. For each point, you're getting the alpha value from another row from the data this way...