【发布时间】:2017-06-16 16:38:40
【问题描述】:
我在ggplot2中有以下代码:
require("ggplot2")
df <- data.frame(x=factor(rep(1:2,5)), y=rnorm(10))
ggplot(df , aes(x,y)) + geom_point(size = 3) +
theme(axis.text.x = element_text(angle = 40, hjust = 1, colour = "black", size=12),
plot.title = element_text(size=16, face="bold", hjust=0.5)) +
labs(title = "Plot")
现在,我想将背景颜色更改为 theme_bw,但随后主标题和 x 轴选项将更改回默认值。
ggplot(df , aes(x,y)) + geom_point(size = 3) +
theme(axis.text.x = element_text(angle = 40, hjust = 1, colour = "black", size=12),
plot.title = element_text(size=16, face="bold", hjust=0.5)) +
labs(title = "Plot") +
theme_bw()
那么,我怎样才能将主题更改为与 theme_bw 相同但又不会丢失其他选项?
谢谢
【问题讨论】:
-
在
theme_bw()之后添加自定义主题怎么样? -
更改
theme元素的顺序。所以先把主题改成theme_bw,然后再改其他的主题元素。 -
谢谢各位。是的,它奏效了。很好的解决方案