使用facet_wrap()时无法控制ggplot2中的legend.position

问题描述 投票:0回答:1
[在下面的代码和图形中,以mtcars数据为例,我尝试将图例放在bottom。在第一张图表中不使用theme_bw()即可正常工作。添加theme_bw()后,图例将向右移动。我做错了什么,如何解决?谢谢。

library(tidyverse) mtcars %>% ggplot(aes(x = factor(cyl), y = mpg, color = factor(am) ) ) + geom_boxplot() + facet_wrap(vars(vs)) + theme(legend.position = "bottom", legend.title = element_blank())

“”

mtcars %>% ggplot(aes(x = factor(cyl), y = mpg, color = factor(am))) + geom_boxplot() + facet_wrap(vars(vs)) + theme(legend.position = "bottom", legend.title = element_blank()) + theme_bw()

“”

reprex package(v0.3.0)在2020-02-20创建

在下面的代码和图形中,以mtcars数据为例,我尝试将图例放在底部。无需在第一个图中使用theme_bw()即可正常工作。一旦添加theme_bw(),图例将移至...
r ggplot2
1个回答
0
投票
您需要颠倒themetheme_bw的顺序,因为如果theme_bw位于结尾,则theme会覆盖theme_bw中的设置。
© www.soinside.com 2019 - 2024. All rights reserved.