50

I would like to increase the font size of ggtitle and also the font should be bold. My code is as follows.

ggplot(df, aes(x1, y = value, colour = variable)) + geom_point(size=2) + ggtitle("male vs.female") + theme(axis.text=element_text(size=14), axis.title=element_text(size=14,face="bold")) + theme(legend.text=element_text(size=12)) + labs(x = "x axis", y = "y axis") + ylim(0,100) + xlim(0,100) + scale_colour_manual(values = c("red", "blue"), labels = c("male", "female")) 
2

2 Answers 2

107

Use theme(), here is an example :

ggplot(cars, aes(x=speed,y=dist)) + ggtitle("cars") + geom_point() + theme(plot.title = element_text(size = 40, face = "bold")) 

enter image description here

Inspired by this answer.

Sign up to request clarification or add additional context in comments.

2 Comments

stating the obvious here, but took me 10 minutes to figure it out, if you're using a theme that sets a plot.title size, make sure to insert the theme(plot.title = element_text(size = 40, face = "bold")) line after your call to theme_blabla(), otherwise your theme's plot title size will override it.
Also you must set plot.title not title.
1

You can also use ggtext::element_markdown to change title font size. It provides markdown and HTML rendering for ggplot2. So you can use inline HTML styling to change font size. For example, to make the title 40pt in bold, we can use the following:

ggplot(cars, aes(x=speed, y=dist)) + ggtitle("<b style='font-size:40pt;'>Cars</b>") + geom_point() + theme(plot.title = ggtext::element_markdown()) 

result

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.