1

Possible Duplicate:
Generate multiple graphics from within an R function

I have tried to make an eps-file of a lattice plot. The .eps-file is created, but the plot seem to be blank (using 'gv'). I have been searching the inter-net for a solution, but without luck.

My code is as follows:

mydf <- data.frame(col1=c(1,1,2,2,3), col2=c(1,2,1,2,1), col3=rnorm(5))
library(lattice)
filename <- "myfile.eps"
postscript(file = filename,
           width = 10, height = 10,
           horizontal = FALSE, onefile = FALSE, paper = "a4")
 xyplot(col3 ~ col1 | col2, data = mydf)
 dev.off()

I have tried to substitute the postscript(...) expression with

  trellis.device("postscript", color = TRUE,
                 height = 10, width = 10,
                 horizontal = FALSE, onefile = FALSE, paper = "a4")

The '.eps-file' is created using both postscript(...) and trellis.device(...), but seems blank looking at it with 'gv' no matter what I do.

I am greatful for any help or guidance. Sisse

Community
  • 1
  • 1
Sisse
  • 291
  • 1
  • 4
  • 14
  • Would it be possible for you to go through your previous questions, and if any of the answers happened to have solved your problem, click the check mark next to them? Doing so is entirely up to you, but marking answers that solved your problem as "Accepted" greatly improves the value of the site for future readers. – joran Mar 02 '12 at 22:20
  • I feel a little insecure about what you mean. – Sisse Mar 02 '12 at 22:32
  • 1
    See [this](http://stackoverflow.com/faq#howtoask) part of the FAQ. And I want to emphasize that marking an answer as accepted is _totally your decision_. But when ans answer solves your problem, marking it as "Accepted" indicates to people reading the question which answer worked for you. This greatly enhances the value of the site as a whole. – joran Mar 02 '12 at 22:36
  • I will consider this, of course! – Sisse Mar 02 '12 at 22:41
  • 1
    @joran is giving you a nice hint, in his own unfailingly polite way. You really really really might want to do more than just consider following his advice (hint hint ;). – Josh O'Brien Mar 02 '12 at 22:50
  • It's not empty when viewed with three different viewers. – IRTFM Mar 03 '12 at 00:03
  • 1
    ` print(xyplot(col3 ~ col1 | col2, data = mydf))` ? – Ben Bolker Mar 03 '12 at 04:41
  • But I need an eps-file to fit in my latex document. – Sisse Mar 03 '12 at 14:52
  • print(xyplot(co3 ~ col1 | col2, data = mydf)) did the trick! – Sisse Mar 03 '12 at 16:41
  • @Sisse ...and so, since that's Ben Bolker's answer below, and you say it worked, you should click on the checkmark next to his answer. It's both a way of saying "thank you" and let's everyone know at a glance that it did the trick. – Gregor Thomas Mar 03 '12 at 20:39

1 Answers1

1

This is R FAQ 7.22: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f

As indicated in comments above,

print(xyplot(co3 ~ col1 | col2, data = mydf)) 

should work

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453