Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Center align ggplot title when title is placed within the plot area

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

While this is fine, I want to centre align the title without changing it’s vertical position.

Is there any way to achieve this?

>Solution :

theme(plot.title = element_text(hjust = 0.5, margin = margin(t=10,b=-20)))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading