Change the font size of a ggplot chart

Size of texts are changed using function theme() and then choosing element you need to modify. To set font size for all texts in plots attribute text should be changed.

ggplot(mtcars,aes(cyl,mpg))+geom_point()+theme(text=element_text(size=21))

There are two ways to set the global font size in a ggplot object p = ggplot(data, aes(x=x, y=y)). As Didzis pointed out one can specify:

global_size = 10
p + theme(text = element_text(size=global_size))

Alternatively, if you are using one of the ggplot themes, pass base_size argument:

p +  theme_classic(base_size = global_size)

This is subjective, but I would advise against using font size 21. It is better to use "standard" font sizes (9-12 pt) and adjust the height and width when saving the ggplot object to match your final printed output.

Just measure the width / height in inches (or cm) of the figure in your presentation, report, etc and save the plot p with exactly those dimensions

ggsave(p, filename=filename,
 width=width_measured, height=height_measured, units='cm')

Tags:

R

Ggplot2