Set fonts size in R plot

You probably have discovered that R usually gives you different size of fonts in different figures. That is because a numerical value (cex in par function) giving the amount by which plotting text and symbols is magnified relative to a default value. This starts as ‘1’ when a device is opened, and is reset when the layout is changed, e.g. by setting ‘mfrow’.

But the final fonts size for the main title (or axis, lab, sub) is determined by the product of the three variables, ps, cex, and cex.main (or cex.axis, cex.lab, cex.sub), respectively.

So if you want 12 points fonts in the title, you may set the following options

par(ps = 12, cex = 1, cex.main = 1)

Update: it is also possible to have different fonts in axes and title, use cex.main, cex.lab, cex.sub to change the magnification, respectively.

Published
Categorized as Default, R

By Feng Li

Dr. Feng Li is an Associate Professor of Statistics in the School of Statistics and Mathematics at Central University of Finance and Economics in Beijing, China. Feng obtained his Ph.D. degree in Statistics from Stockholm University, Sweden in 2013. His research interests include Bayesian computation, econometrics and forecasting, and distributed learning. His recent research output appeared in statistics and forecasting journals such as the International Journal of Forecasting and Statistical Analysis and Data Mining, AI journals such as Expert Systems with Applications, and medical journals such as BMJ Open.

8 comments

  1. Hi Thank you for information

    could with how to changing the axis text (8points) and axis labels (9 points) to different font size font size?

Leave a comment

Your email address will not be published. Required fields are marked *