I have a list object with several (64) data frames. While I could successfully manage to plot multiple histograms for each data frame in a loop (in a 64-page PDF document, with each plot on a new page), I am having a hard time producing a 8 page PDF document with 8 plots per page.
The code I have used :
listfinal1 <- list()
listfinal2 <- list()
for (i in 1:64){
listfinal1[[i]] <- data.frame(rnorm(100,10))
colnames(listfinal1[[i]]) <- c("Column A")
}
for (i in 1:64){
listfinal2[[i]] <- data.frame(rnorm(10,1))
colnames(listfinal2[[i]]) <- c("Column B")
}
plot_list <- list()
pdf("jnk1.pdf")
plotlist <- list()
for (i in 1: length(listfinal1)){
P1 <- hist(listfinal1[[i]][,1],breaks=seq(-30,30,by=2),plot=FALSE)
P2 <- hist(listfinal2[[i]][,1],breaks=seq(-30,30,by=2),plot=FALSE)
P3 <- plot(0,0,type="n",xlim=c(-30,30),ylim= c(0,max(P1$counts)+2),xlab="Costum Lenghts (mm)",ylab= "Frequency")
grid(col="lightgray",lty="solid")
plot1 <- plot(P1,col="black",density=0,angle=135,add=TRUE)
plot2 <- plot(P2,col="red",density=50,angle=45,add=TRUE)
plotlist[[i]] <- plot2
}
dev.off()