0

I am doing loop ploting, and want to print plots into pdf. what should I do. I am very confused.

the looping codes looks like this:

for (i in 1:12)){

   df<-Sample.Data %>% filter(ID==i) 
         p1 <- ggplot(data =df)+
   geom_line(aes(x = Days, y = Result, color = Item))+
      
 print(p1)
 }

then, what should I do?

Stataq
  • 2,237
  • 6
  • 14

1 Answers1

1

Try this with pdf function (No data provided so it is not possible to add some output):

#Pdf
pdf('Example.pdf',width = 14)
#Loop
for (i in 1:12)){
  #Data
  df<-Sample.Data %>% filter(ID==i) 
  #Plot
  p1 <- ggplot(data =df)+
    geom_line(aes(x = Days, y = Result, color = Item))
  #Print
  plot(p1)
}
dev.off()
Duck
  • 39,058
  • 13
  • 42
  • 84