ggplot2 font size

posted on 09:11 PM on Tuesday 22 August 2023

Since I use ggplot2 on a regular basis to generate plots which the number of axis elements is often variable. I often need to determine the space taken by the axis labels.

So it appears that the default for ggplot2 is helvetica 9 points for the axis labels. I generate a PDF plot using theme_bw() and then open the plot in Affinity Designer to check and it was helvetica 9 points.

Now that I know the font and size, checking the following link gives me the average width of a character in Helvetica as being 0.53772 of its height.

https://www.math.utah.edu/~beebe/fonts/afm-widths.html

Therefore a character in 9 points will take up 9 / 72 of an inch while the width would be 0.53772 * 9 / 72. So using this values together with the max number of characters in the axis labels, I can determine the width and height of the axis labels.

On a side note, a point which is a measurement used for font is basically 1/72 inches. See:

https://en.wikipedia.org/wiki/Point_(typography)

bernett.net