另一个“传奇 - 问题” .
我有几个美学,并希望指定每个美学的传说的顺序 . 大多数线程都是关于改变审美中项目的顺序,但这不是我的问题 . 在我的例子中,我想指定填充图例的位置 . 有趣的是,在底部绘制图例时,颜色图例绘制在填充图例的顶部,但是"right"绘制到填充图例 . 这对于像我这样的左右读者来说似乎有些随意,他们也从顶部到底部阅读 .
该图显然是随机的,并且很快就是为了表示目的 .
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包创建于2018-12-10(v0.2.1)
1 回答
您可以使用
guide_legend
的order
选项: