I have the following codes in 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")
Now, I want to change the background color to theme_bw, but then the main title and the x-axis options will be changed back to default.
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()
So, how can I change the theme to be the same as theme_bw but without losing other options?
Thanks
Here's the solution (make sure that theme_bw()
is used before the theme()
that you want to apply:
ggplot(df , aes(x,y)) + geom_point(size = 3) +
theme_bw() +
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With