Recently, I wanted to use two separate colour schemes on a chart, while keeping the information in the legend. In this case there was one colour scale for a set of points, and one for a set of lines.
I came up with a workaround whereby I mapped my chosen aesthetic to
fill in the points instead, and used
pch = 1 (circle with outline and fill) and
stroke = 0. If this seems a bit confusing, refer to the reprex below.
However, another bit of data was mapped to the points' alpha (transparency)*. This leads to the points' alphs not being present in the legend (since the legend only shows the outline of the points, which is now
stroke = 0).
library(ggplot2) ggplot(mtcars, aes(x = disp, y = mpg)) + geom_point(aes(fill = vs, alpha = wt), pch = 21, # Make points into filled points stroke = 0) + # Remove outline from filled points ggtitle("Alpha in legend with stroke = 0")
I should also note that this is with
My questions are:
- Is this a bug? I.e. should I file an issue on github?
- Is there a handier workaround to the initial issue?
* If you're thinking this is a sign there's too much going on in the chart, I would probably agree with you. Still, please bear with me.