Export a graph to .eps file with R

RGraphEps

R Problem Overview


How do I export a graph to an .eps format file? I typically export my graphs to a .pdf file (using the 'pdf' function), and it works quite well. However, now I have to export to .eps files.

R Solutions


Solution 1 - R

The easiest way I've found to create postscripts is the following, using the setEPS() command:

setEPS()
postscript("whatever.eps")
plot(rnorm(100), main="Hey Some Data")
dev.off()

Solution 2 - R

If you are using ggplot2 to generate a figure, then a ggsave(file="name.eps") will also work.

Solution 3 - R

The postscript() device allows creation of EPS, but only if you change some of the default values. Read ?postscript for the details.

Here is an example:

postscript("foo.eps", horizontal = FALSE, onefile = FALSE, paper = "special")
plot(1:10)
dev.off()

Solution 4 - R

Another way is to use Cairographics-based SVG, PDF and PostScript Graphics Devices. This way you don't need to setEPS()

cairo_ps("image.eps")
plot(1, 10)
dev.off()

Solution 5 - R

Yes, open a postscript() device with a filename ending in .eps, do your plot(s) and call dev.off().

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmStudentView Question on Stackoverflow
Solution 1 - RCompEconView Answer on Stackoverflow
Solution 2 - RMaiasauraView Answer on Stackoverflow
Solution 3 - RGavin SimpsonView Answer on Stackoverflow
Solution 4 - RUSER_1View Answer on Stackoverflow
Solution 5 - RDirk EddelbuettelView Answer on Stackoverflow