Matt Bannert
Matt Bannert

Reputation: 28264

saving plots to pdf fails

When I use pdf("somefile.pdf") to save my plots to a pdf file, everything seems to work. No error messages or whatsoever. Still the result is screwed (file size is NOT 0 KB) but I can't open it using preview nor adobe reader. I am running Mac OS 10.6 and the latest R Studio release. Any suggestions? Note png()works perfectly fine, so does sweave and pdf plots from ggplot.

Upvotes: 0

Views: 3605

Answers (2)

Greg Snow
Greg Snow

Reputation: 49640

The pdf and png devices work a little different. The pdf device by default will put multiple plots into a single file, so it will not finalize the file until you tell it that you are finished creating the plots (with dev.off). The png device will put 1 plot in 1 file, so will create multiple files for multiple plots. So as soon as you start a second plot, the 1st file will be finalized and can be opened and used. You still need dev.off to finalize the last file after the last plot.

Upvotes: 1

Ben Bolker
Ben Bolker

Reputation: 226182

Did you remember to close the file via dev.off() before trying to view it?

(See also: problem saving pdf file in R with ggplot2 )

Upvotes: 7

Related Questions