Book Image

R Graphs Cookbook Second Edition

Book Image

R Graphs Cookbook Second Edition

Overview of this book

Table of Contents (22 chapters)
R Graphs Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Choosing fonts for PostScripts and PDFs


The pdf and postscript graphic devices in R have special functions that handle the translation of an R graphics font family name to a PostScript or PDF file. In this recipe, we will see how to choose the fonts for these vector formats.

Getting ready

We will only use the base graphics functions for this recipe. So, just open up the R prompt and type in the following code. You might wish to save the code as an R script for later use.

How to do it...

Let's create a PDF of an rnorm() graph with the title and axis annotations in the Avant Garde font:

pdf("fonts.pdf",family="AvantGarde")
plot(rnorm(100),main="Random Normal Distribution")
dev.off()

To save the same graph as a postscript file, we use the following code:

postscript("fonts.ps",family="AvantGarde")
plot(rnorm(100),main="Random Normal Distribution")
dev.off()

How it works...

As shown in the examples, the font family for a PDF or PostScript output is set exactly the same way as in the previous recipe, by...