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.
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.)
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.
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.
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.
Use theme_set()
theme_set(theme_gray(base_size = 18)) qplot(1:10, 1:10)
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With