[R] save plot

dbandler at bandlerconsulting.com dbandler at bandlerconsulting.com
Mon Jul 19 17:39:01 CEST 2010


Is there an easy way to load plots in png files into R?  I'm using the png function to create the plots from a batch job and would like to view them later.

-----Original Message-----
From: "Gavin Simpson" <gavin.simpson at ucl.ac.uk>
Sent: Saturday, July 17, 2010 6:21pm
To: "linda.s" <samrobertsmith at gmail.com>
Cc: r-help at r-project.org
Subject: Re: [R] save plot

On Sat, 2010-07-17 at 14:52 -0400, linda.s wrote:
> > Open a new device before plotting, do your plotting, close the device.
> >
> > For example, using a PDF device via pdf():
> >
> > pdf("my_plots.pdf", height = 8, width = 8, pointsize = 10,
> >    version = "1.4", onefile = TRUE)
> > for(i in 1:10) {
> >    y <- rnorm(100)
> >    x <- rnorm(100)
> >    plot(y ~ x)
> > }
> > dev.off()
> >
> > The last line (dev.off() is very important as the file will not be valid
> > pdf without closing the device.
> >
> > HTH
> >
> > G
> 
> I got the error:
> > pdf("my_plots.pdf", height = 8, width = 8, pointsize = 10,
> +    version = "1.4", onefile = TRUE)
> > for(i in 1:10) {
> +    y <- rnorm(100)
> +    x <- rnorm(100)
> +    plot(y ~ x)
> + }
> > dev.off()
> null device
>           1

If by "error" you mean "null device \n 1", that is a notice informing
you what the now current plotting device is, i.e. in this cases there
isn't one.

Did you look in your current working directory (see what that is by
using getwd() ) for a pdf named "my_plots.pdf"?

G

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list