[R] save plot

Gavin Simpson gavin.simpson at ucl.ac.uk
Sun Jul 18 00:21:50 CEST 2010


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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list