I came across this taken from here:
library(ggplot2)
p <- ggplot(iris, aes(x = Species, y = Sepal.Length))
colors <- c("black", "red", "green")
for(color in colors){
final.plot <- p + geom_boxplot(color = color)
pdf(paste0(color, ".pdf"))
print(final.plot)
dev.off()
}
It produces several pdfs. Can one also append several plots, tables, heading to one pdf inside such a loop? I have not found anything useful yet and do not think that knitr, rmarkdown etc. are appropriate for this use case?
Thanks.