Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the default font size in ggplot2

I'd like to know if it is possible to change some default parameters of ggplot2 graphics, like font size for instance, for a whole R session. The idea is to avoid setting them for each plot.

like image 552
jeannot Avatar asked Aug 14 '12 15:08

jeannot


People also ask

Can you change the font in ggplot2?

ggplot allows you to change the font of each part of the figure: you just need to know the correct option to modify in the theme. (For a full list of customizable components of the theme, see this documentation.)

What is the default font in ggplot2?

R and ggplot can create fantastic graphs, but the default Arial/Helvetica font is too boring and standard. You can change the font used in a plot fairly easily three different ways: All of the built-in ggplot themes have a base_family argument for setting the overall font family for the plot.

How do I change the font size in R script?

Go to the menu in RStudio and click on Tools and then Global Options. Select the Appearance tab on the left. Again buried in the middle of things is the font size. Change this to 14 or 16 to start with and see what it looks like.

What is the default font size in R?

For all of R's graphical devices, the default text size is 12 points but it can be reset by including a pointsize argument to the function that opens the graphical device.


2 Answers

Use theme_set()

theme_set(theme_gray(base_size = 18)) qplot(1:10, 1:10) 

enter image description here

like image 119
Luciano Selzer Avatar answered Oct 15 '22 20:10

Luciano Selzer


Use theme_set if you want to update for the remainder of your active session:

theme_set(theme_grey(base_size = 18))  

If you only want to change one graph you can set the base_size in the theme:

qplot(1:10, 1:10) + theme_grey(base_size = 18)  ggplot(mtcars, aes(x = mpg, y = cyl)) +  geom_point() + theme_grey(base_size = 18)  
like image 21
Thierry Avatar answered Oct 15 '22 20:10

Thierry