Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't open saved plot in R

Tags:

plot

r

save

I am not able to open the plot when saved as pdf or other format. Consistently getting the following error. I am working on mac.

> plot(1:10)
> pdf('deleteIt.pdf')
> dev.off()
RStudioGD 
        2 


> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] pROC_1.5.4 plyr_1.7.1

loaded via a namespace (and not attached):
[1] tools_2.15.1

I am getting the following error. Itried with png and jpeg too, but no luck..

The file “deleteIt.pdf” could not be opened.
It may be damaged or use a file format that Preview doesn’t recognize.
like image 777
user1140126 Avatar asked Dec 09 '22 18:12

user1140126


1 Answers

You did it backwards. Try this

pdf("deleteIt.pdf")
plot(1:10)
dev.off()

Start the device. Write to it. Turn it off.


Alternatively, as pointed out by @Spacedman in a comment, you can create a pdf with whatever is currently plotted by using dev.copy like this:

plot(1:10)
dev.copy(pdf, "deleteIt.pdf")
dev.off()
like image 114
GSee Avatar answered Dec 11 '22 07:12

GSee