Reputation: 3568
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.
Upvotes: 3
Views: 9901
Reputation: 93
None of the above works for me. I had to specify the font in the ggsave()
ggsave(filename = "fig1.eps", plot=fig1,family="Times")
Upvotes: 0
Reputation: 3568
Discovered how to do this properly
ggplot2::ggsave(filename = "foo.eps",
plot = foo,
device = cairo_ps)
specifying cairo_ps
for the device is the key
Upvotes: 7
Reputation: 84529
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")
Upvotes: 7