9

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!

3 Answers 3

3

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.

0
2

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.

1
  • Unfortunately the bit at the end of that link said it does not apply to pdf devices.
    – IRTFM
    Sep 6, 2011 at 20:53
0

Maybe try to use pointsize = 12, within your quartz()? https://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/quartz.html

quartz(pointsize = 12)

For some reason, my family="Helvetica" doesn't work, when placed within quartz().

Both changes - change font and fontsize works in this order:

quartz(pointsize = 12) # define point size
par(mar=c(3,3,1,1), family = "Helvetica")    # define family
plot(...)

Thus, for pdf() plot exporting and quartz() output, as they don't run at the same time - I'm using the pdf() for exporting my plots, but quartz() just to copy a plot to MS Word document

library(extrafont)       # library needed to have your fonts
loadfonts() ## for pdf() 

# pdf plot export - now doesn't run, because now I want just check changes in my quartz() plotting
# pdf("my_plot_in_pdf.pdf", height = 4, width = 4, family = "Helvetica") 

quartz(height = 4, width = 4, pointsize = 12)  # check my changes in plot, if I want to export my plot, I just set #quartx(...)
    par(mar=c(4,4,1,1), family = "Helvetica")
    plot(cars, main = "Helvetica, 12", ylab = "y label", xlab = "x label", cex = 1)
    dev.off()

enter image description here

OR change my family and points size:

quartz(height = 4, width = 4, pointsize = 20)
par(mar=c(4,4,1,1), family = "Times New Roman")
plot(cars, main = "Times New Roman, 20", ylab = "y label", xlab = "x label", cex = 1)
dev.off()

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.