Let say I have below ggplot
set.seed(1)
x<-rnorm(20)
y<-rnorm(20)
df<-data.frame(x,y)
df
library(ggplot2)
ggplot(df,aes(x,y)) geom_point() ggtitle("Scatterplot") theme(plot.title=element_text(margin=margin(t=10,b=-20)))
With this I am getting below ggplot
While this is fine, I want to centre align the title without changing it's vertical position.
Is there any way to achieve this?
CodePudding user response:
theme(plot.title = element_text(hjust = 0.5, margin = margin(t=10,b=-20)))