Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export a graph to .eps file with R

Tags:

graph

r

eps

People also ask

How do I Export a graph in R?

Plots panel –> Export –> Save as Image or Save as PDF It's also possible to save the graph using R codes as follow: Specify files to save your image using a function such as jpeg(), png(), svg() or pdf(). Additional argument indicating the width and the height of the image can be also used.

How do I save Ggplot as EPS?

The plot can be saved in the eps format using the ggplot. save() method, which takes as argument the string name of the plot.


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()

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


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()

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()