[R] Multiple groupedData plots in a postscript file using a loop

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Jan 17 16:40:28 CET 2004


On Sat, 17 Jan 2004, Uwe Ligges wrote:

> Karl Knoblick wrote:
> > Hallo!
> > 
> > I want to plot multiple grouped data in a postscript
> > file using a loop. As I use a loop no plot (or just
> > one empty plot) is generated. Here an example:
> > 
> > library(nlme)
> > data(Loblolly) # example data from nlme
> > postscript("PSFile.ps")
> > for (i in 1:1) # just as example
> > {
> > 	plot(Loblolly)
> > }
> > dev.off()
> 
> Note that this is a lattice plot:
> 
>   class(Loblolly)
> [1] "nfnGroupedData" "nfGroupedData"  "groupedData"    "data.frame"
> 
> Thus, the method plot.nfnGroupedData() producing a lattice plot is 
> called by the generic plot().
> 
> So, you don't want to start postscript(), but
>   trellis.device("postscript", file = "PSFile.ps")
>   plot(Loblolly)
>   dev.off()
> 

Or inside a loop

trellis.device("postscript", file = "PSFile.ps")
for (i in 1:1)
  print(plot(Loblolly))
# ^^^^^
dev.off()

Although Uwe is right that trellis.device should be used, recent versions 
of lattice do make correct use of an open postscript() device.

Not that Master Knoblick *is* using recent lattice, as we know from an
earlier posting.  See

https://www.stat.math.ethz.ch/pipermail/r-help/2004-January/042780.html

Once again he has omitted to let us know what versions he is using.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list