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
__________________________________________________________________
Multiple groupedData plots in a postscript file using a loop
8 messages · Karl Knoblick, Uwe Ligges, Deepayan Sarkar +1 more
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()
Uwe Ligges
Result: Just an empty PSFile.ps. (Withoput the loop it works. May anybody help? Karl
__________________________________________________________________ ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
On Saturday 17 January 2004 08:58, 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)
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)
} dev.off() Result: Just an empty PSFile.ps. (Withoput the loop it works. May anybody help? Karl
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> :>
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
__________________________________________________________________
Karl Knoblick wrote:
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()
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
Just an empty postscript file. Karl. --- Uwe Ligges <ligges at statistik.uni-dortmund.de> :>
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 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
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:
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
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).
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