Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify font size in a plot (for PDF output)?

Any ideas on how to calibrate cex to font size units?

Specifically, I'd like to work with the default family 'Helvetica' and specify font sizes to correspond to .doc font sizes. For example, use font size 12 for main titles and font size 10 for axis titles.

I'd appreciate your advise and suggestions. thanks!

like image 960
Adam SO Avatar asked Sep 06 '11 19:09

Adam SO


People also ask

How do I change font size in plot in R?

How to change font size in r? To change the font size of text, use cex (character expansion ratio). The default value is 1. To reduce the text size, use a cex value of less than 1; to increase the text size, use a cex value greater than 1.

What are the three ways to specify the size of a font?

The font-size property is specified in one of the following ways: As one of the absolute-size, relative-size or math keywords. As a <length> or a <percentage> , relative to the element's font size.


2 Answers

You can set the default font on a plot by plot basis.

par(family = 'Helvetica')
plot(rnorm(10), main = 'Something In Helvetica')

There is also a par('font') that you can use to set whether the font is bold, italic, etc. For the size, besides the cex group of parameters mentioned by Brandon that allow one to set the font size as a relative term, there is also cin, cra, and I believe more that allow one to set sizes in inches or in pixels. Unfortunately, you can't specify in a standard font size of 10 or 12.

Check the help for par() and read it very carefully.

like image 181
John Avatar answered Oct 24 '22 19:10

John


Your first question requires a bit of heavy lifting. There is a good set of instructions here: http://www.jameskeirstead.ca/typography/changing-the-fonts-in-r-plots/ I'm not aware of an "easier way". But I'd love to see one.

For your second question: See ?par specifically the part about cex.

cex
cex.axis
cex.lab
cex.main

Additionally, you can mess with the pointsize setting in ?pdf to adjust the relative sizes.

like image 42
Brandon Bertelsen Avatar answered Oct 24 '22 19:10

Brandon Bertelsen