How to append a plot to an existing pdf file

前端 未结 4 1098
刺人心
刺人心 2020-12-13 09:46

I want to append a plot to an existing pdf long after dev.off() has been called*. After reading the pdf() help file and after reading the Q &

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-13 09:52

    You could use recordPlot to store each plot in a list, then write them all to a pdf file at the end with replayPlot. Here's an example:

    num.plots <- 5
    my.plots <- vector(num.plots, mode='list')
    
    for (i in 1:num.plots) {
        plot(i)
        my.plots[[i]] <- recordPlot()
    }
    graphics.off()
    
    pdf('myplots.pdf', onefile=TRUE)
    for (my.plot in my.plots) {
        replayPlot(my.plot)
    }
    graphics.off()
    

提交回复
热议问题