I found a possible problem with guide_legend()
s effectiveness within guides()
depending on the order of aesthetic mappings in the ggplot()
call.
I expected that nrow = 2
in the guide_legend()
call for shape
in guides
would have an effect, but it doesn't seem to be working. It does work if I switch shape
to be mapped before color though.
Here is the code to reproduce the bug:
library(ggplot2)
ggplot(
mtcars,
aes(x = wt, y = mpg, color = as.factor(cyl), shape = as.factor(cyl))
) +
geom_point() +
guides(shape = guide_legend(nrow = 2))
ggplot(
mtcars,
aes(x = wt, y = mpg, shape = as.factor(cyl), color = as.factor(cyl))
) +
geom_point() +
guides(shape = guide_legend(nrow = 2))
Should the order of the aesthetic mappings matter here?