I have this awkward problem with trellis (lattice). I am trying to generate some plots through loops but the .eps file is empty. When I generate them in a list and print them outside the loop all is fine. this is an example below:( nothing shows up in foo.eps, but all show up in foo1.eps) R vesion 2.0.1, lattice version 0.10-16, on a debian 2.6.8-1 kernel. X <- data.frame(x=rnorm(10000), y=rnorm(10000), z=sample(c("foo1","foo2"), 10000,replace=T), year=sample(c(89:94), 10000,replace=T)) trellis.device("postscript", file="foo.eps") for(i in unique(X$year)){ temp <- X[X$year%in%i, ] xyplot(temp$x~temp$y|temp$z) } dev.off() mylist <- list() for(i in unique(X$year)){ temp <- X[X$year%in%i, ] mylist[[i]] <- xyplot(temp$x~temp$y|temp$z) } trellis.device("postscript", file="foo1.eps") mylist[[89]] mylist[[90]] mylist[[91]] mylist[[92]] mylist[[93]] mylist[[94]] dev.off() Thank you, Jean
Wrap the xyplot in print: X <- data.frame(x=rnorm(10000), y=rnorm(10000), z=sample(c("foo1","foo2"), 10000,replace=T), year=sample(c(89:94), 10000,replace=T)) trellis.device("postscript", file="foo.eps") for(i in unique(X$year)){ temp <- X[X$year%in%i, ] print(xyplot(temp$x~temp$y|temp$z)) } dev.off() hope this helps, Chuck Cleland Jean Eid wrote:> I have this awkward problem with trellis (lattice). I am trying to > generate some plots through loops but the .eps file is empty. When I > generate them in a list and print them outside the loop all is fine. this > is an example below:( nothing shows up in foo.eps, but all show up in > foo1.eps) > R vesion 2.0.1, lattice version 0.10-16, on a debian 2.6.8-1 kernel. > > > X <- data.frame(x=rnorm(10000), y=rnorm(10000), z=sample(c("foo1","foo2"), > 10000,replace=T), year=sample(c(89:94), 10000,replace=T)) > trellis.device("postscript", file="foo.eps") > for(i in unique(X$year)){ > temp <- X[X$year%in%i, ] > xyplot(temp$x~temp$y|temp$z) > } > dev.off() > > mylist <- list() > for(i in unique(X$year)){ > temp <- X[X$year%in%i, ] > mylist[[i]] <- xyplot(temp$x~temp$y|temp$z) > } > > trellis.device("postscript", file="foo1.eps") > mylist[[89]] > mylist[[90]] > mylist[[91]] > mylist[[92]] > mylist[[93]] > mylist[[94]] > dev.off() > > > Thank you, > > Jean > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 452-1424 (M, W, F) fax: (917) 438-0894
Jean, On 30 January 2005 at 10:52, Jean Eid wrote: | | I have this awkward problem with trellis (lattice). I am trying to | generate some plots through loops but the .eps file is empty. When I | generate them in a list and print them outside the loop all is fine. this That is a FAQ -- wrap a 'print()' around the calls to xyplot() and friends: > X <- data.frame(x=rnorm(10000), y=rnorm(10000), z=sample(c("foo1","foo2"), 10000,replace=T), year=sample(c(89:94), 10000,replace=T)) > pdf("/tmp/jean.pdf") > for(i in unique(X$year)) { temp <- X[X$year%in%i, ]; print(xyplot(temp$x~temp$y|temp$z)) } > dev.off() null device 1 > creates fine pdf with six pages: edd at basebud:~> ls -l /tmp/jean.pdf -rw-r--r-- 1 edd edd 592537 Jan 30 10:34 /tmp/jean.pdf Hth, Dirk | is an example below:( nothing shows up in foo.eps, but all show up in | foo1.eps) | R vesion 2.0.1, lattice version 0.10-16, on a debian 2.6.8-1 kernel. | | | X <- data.frame(x=rnorm(10000), y=rnorm(10000), z=sample(c("foo1","foo2"), | 10000,replace=T), year=sample(c(89:94), 10000,replace=T)) | trellis.device("postscript", file="foo.eps") | for(i in unique(X$year)){ | temp <- X[X$year%in%i, ] | xyplot(temp$x~temp$y|temp$z) | } | dev.off() | | mylist <- list() | for(i in unique(X$year)){ | temp <- X[X$year%in%i, ] | mylist[[i]] <- xyplot(temp$x~temp$y|temp$z) | } | | trellis.device("postscript", file="foo1.eps") | mylist[[89]] | mylist[[90]] | mylist[[91]] | mylist[[92]] | mylist[[93]] | mylist[[94]] | dev.off() | | | Thank you, | | Jean | | ______________________________________________ | R-help at stat.math.ethz.ch mailing list | https://stat.ethz.ch/mailman/listinfo/r-help | PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Better to have an approximate answer to the right question than a precise answer to the wrong question. -- John Tukey as quoted by John Chambers
Jean Eid <jeaneid at chass.utoronto.ca> writes:> I have this awkward problem with trellis (lattice). I am trying to > generate some plots through loops but the .eps file is empty. When I > generate them in a list and print them outside the loop all is fine. this > is an example below:( nothing shows up in foo.eps, but all show up in > foo1.eps) > R vesion 2.0.1, lattice version 0.10-16, on a debian 2.6.8-1 kernel. > > > X <- data.frame(x=rnorm(10000), y=rnorm(10000), z=sample(c("foo1","foo2"), > 10000,replace=T), year=sample(c(89:94), 10000,replace=T)) > trellis.device("postscript", file="foo.eps") > for(i in unique(X$year)){ > temp <- X[X$year%in%i, ] > xyplot(temp$x~temp$y|temp$z) > } > dev.off()You need to print(xyplot(....)). -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907