Skip to content

Setting the pointsize of fonts in base R graphics

June 20, 2012

I’ve always used the cex family of graphics parameters to change the size of fonts in a base R graphic. But I always just worked by trial and error, stopping when it ‘looks good’. But I think its better to just set the pointsize directly. However, the cex parameters aren’t set in pointsize units, and the pointsize that results depends on the graphics device (e.g. pdf, quartz, png, etc.) with which the plot is being created. There are two key ideas.

First, each device can have a different baseline pointsize associate with it. For almost all the devices that I ever use (e.g. pdf, png, quartz, etc…) the default baseline is 12pt. To change it to 10pt use,

pdf('myfigure.pdf', pointsize = 10)

This example used the pdf device but it should work the same for most (if not all) other devices.

Second, this baseline pointsize can be expanded using a cex command. For example, if we are using a device with a 12pt baseline font, the point size of the axis labels for a simple example plot can be changed to 10pt with the command,

plot(1:10, 1:10, cex.lab = 10/12)

and to 18.52pt font using,

plot(1:10, 1:10, cex.lab = 18.52/12)

Make sense? If not let me know. Am I wrong about something? If so let me know.

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: