(Originally commented at #3725 (comment))
Currently, legends reflect the value of after_scale(). But, it's not always possible because the expression of after_scale() might refer to the variable unavailable at the stage of drawing legends.
For example, I think it is a proper usage of stage() to modify scaled colours by combining other aesthetics. But, the following example has two problems:
x is not available on drawing legends
- even if we manage to make
x available, it's not clear what legends should be drawn because the scaled colours are discrete but the after_scale()ed values are continuous.
Especially because of the problem 2., I think legends should use the raw scaled values, not the after_scale()ed ones.
library(ggplot2)
set.seed(88)
d <- data.frame(x = runif(9), y = runif(9), g = rep(c("a", "b", "c"), each = 3))
p <- ggplot(d) +
geom_point(aes(x, y, colour = stage(g, after_scale = alpha(colour, x))), size = 10)
# fail
p
#> Error in alpha(colour, x): object 'x' not found
# ok
p + theme(legend.position = "none")

Created on 2020-01-14 by the reprex package (v0.3.0)
(Originally commented at #3725 (comment))
Currently, legends reflect the value of
after_scale(). But, it's not always possible because the expression ofafter_scale()might refer to the variable unavailable at the stage of drawing legends.For example, I think it is a proper usage of
stage()to modify scaledcolours by combining other aesthetics. But, the following example has two problems:xis not available on drawing legendsxavailable, it's not clear what legends should be drawn because the scaledcolours are discrete but theafter_scale()ed values are continuous.Especially because of the problem 2., I think legends should use the raw scaled values, not the
after_scale()ed ones.Created on 2020-01-14 by the reprex package (v0.3.0)