我有几种美学,并希望指定每种美学的图例绘制顺序。
大多数线程都是关于更改项目顺序的
在内部
美学,但这不是我的问题。在我的示例中,我想指定填充图例的位置。有趣的是,颜色图例绘制在填充图例的顶部,但在底部绘制图例时,颜色图例位于填充图例的“右侧”。对于像我这样的从左到右的读者来说,这似乎有些随机,他们也喜欢从上到下阅读。
该图显然有点随机,只是很快为reprex制作的。
library(ggplot2)
ggplot(mtcars) +
geom_boxplot(aes(cyl, hp, fill = as.character(gear))) +
geom_boxplot(aes(cyl, disp, color = as.character(cyl))) +
labs(fill = 'fill', color = 'color')
# here I would like the fill legend to be *above* the color legend
ggplot(mtcars) +
geom_boxplot(aes(cyl, hp, fill = as.character(gear))) +
geom_boxplot(aes(cyl, disp, color = as.character(cyl))) +
labs(fill = 'fill', color = 'color') +
theme(legend.position = 'bottom')
# here I would like the fill legend to be *right* and the color legend left
reprex package
(v0.2.1)