1

I have data set as below

set.seed(10)
test <- data.frame(exp = rep(LETTERS[1:5], each = 4), x = rnorm(20, 10, 2), y = rnorm(20, 11, 1))

I'd like to plot several figures for each level in the data and save the result to the one pdf file without using Acrobat Pro

I made one attempt that create single plots but I don't knot if it is possible to make one file out of it.

for (i in levels(test$exp)){
  da <-  subset(test, exp == i)
    pdf(paste(i, ".pdf", sep=""))
      plot(da$x, da$y)
    dev.off()
}
Mateusz1981
  • 1,817
  • 17
  • 33

1 Answers1

1

If we need a single pdf, then remove the pdf line and dev.off and keep it outside the for loop.

pdf("somefile.pdf")
for (i in levels(test$exp)){
   da <-  subset(test, exp == i)
   plot(da$x, da$y)
 }
dev.off()
akrun
  • 874,273
  • 37
  • 540
  • 662