Home > Mobile >  Center align ggplot title when title is placed within the plot area
Center align ggplot title when title is placed within the plot area

Time:04-20

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

enter image description here

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)))
  • Related