Exporting graphs in vector formats – SVG, PDF, and PS

In this recipe, we will learn how to save graphs in vector formats such as PDF, SVG, and PostScript (PS), which are resolution-independent.

Getting ready

Once again we will use the basic graph functions. So, just make sure that you have started R and type in the code at the R prompt.

How to do it...

Let's use the same scatter plot example from the previous recipe and save it in different vector formats, starting with PDF:


main="Relationship between car distance and speed",
xlab="Speed (miles per hour)",ylab="Distance travelled (miles)",


Similarly, we can save the graph as ...

Get R: Data Analysis and Visualization now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.