Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot save ggplot as eps

Tags:

r

ggplot2

I've read this and this but cannot make it work.

vDF <- data.frame(v = rnorm(50,1,40))
g <- ggplot(vDF, aes(x = vDF)) + geom_histogram()
ggsave(g, file="name.eps") 

I keep getting the error

Error in grDevices::postscript(..., onefile = FALSE, horizontal = FALSE, : cannot open file 'name.eps'

Why can't I make this work? I've see advice saying 'hey just do...

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

But I can't even save the original .eps file in the first place.

like image 758
llewmills Avatar asked Mar 16 '26 07:03

llewmills


1 Answers

First, there's an error in your code. It should be:

vDF <- data.frame(v = rnorm(50,1,40))
g <- ggplot(vDF, aes(x = v)) + geom_histogram()

(note the aes).

Now, to save the plot as eps, you have to use the option device=eps in ggsave:

ggsave(g, file="name.eps", device="eps")
like image 189
Stéphane Laurent Avatar answered Mar 18 '26 19:03

Stéphane Laurent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!