我有以下的代碼在GGPLOT2:如何在ggplot2中創建類似於theme_bw的自定義主題?
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',然後再更改其他主題元素。 – aosmith
謝謝,夥計們。是的,它的工作。偉大的解決方案 – Alirsd