Skip to content

Multiple groupedData plots in a postscript file using a loop

8 messages · Karl Knoblick, Uwe Ligges, Deepayan Sarkar +1 more

#
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()

Result: Just an empty PSFile.ps.
(Withoput the loop it works.

May anybody help?

Karl


__________________________________________________________________
#
Karl Knoblick wrote:
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()

Uwe Ligges
#
On Saturday 17 January 2004 08:58, Karl Knoblick wrote:
replace this line with 

        print(plot(Loblolly))

(plot(Loblolly) produces a ``trellis'' object, which needs to be 'print'-ed 
for anything to be actually plotted. Inside a loop (or a function), this does 
not happen unless you call print() explicitly)
#
Thanks, but it does NOT work using a loop (your
example without loop works):

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

Just an empty postscript file.

Karl.

 --- Uwe Ligges <ligges at statistik.uni-dortmund.de> :>
__________________________________________________________________
#
Karl Knoblick wrote:

            
Yep, sorry. You need to print() a lattice plot in this case:

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


Uwe Ligges
#
On Sat, 17 Jan 2004, Uwe Ligges wrote:

            
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.
#
My problem was solved by using 
trellis.device(win.metafile,file="Loblolly.wmf",
color=F)
instead of win.metafile("Loblolly.wmf").
(other answers helped also)

(What I found for getting similiar plots as postscript
was color=F in the trellis.device(...) command)

Thanks to all!
Karl.

BTW win.metafile("Loblolly.wmf") does not work for me
with the following versions I updated recently:

R version 1.8.0, 2003-10-08
package.description("lattice")
Package "lattice" 
Version "0.8-7" 
Date "2003/10/17" 
Built "R 1.8.0; i386-pc-mingw32; 2003-10-29 16:36:53;
windows" 

package.description("nlme")
Package "nlme" 
Version "3.1-45" 
Date "2003/08/29" 
Built "R 1.8.0; i386-pc-mingw32; 2003-10-09 00:21:55;
windows" 


__________________________________________________________________
#
On Sat, 17 Jan 2004, Karl Knoblick wrote:

            
But, the current version is R 1.8.1 and it *does* work in a current
version of R (1.8.1 or R-patched or R-devel).