I am using the following code to save multiple plots in a single pdf file. Individual plots work well, but with a loop I get a corrupt file that doesn't have pages
pdf("HistogramsAll.pdf", onefile=TRUE)
for (i in 1:nFilt) {
d.i<-dAll[,c(1,i+1)];
nameP.i<-names(dAll)[i+1];
names(d.i)<-c("cond", "p");
ggplot(data=d.i, aes(x=p, fill=cond))+
geom_histogram(binwidth=.3, position="dodge") +
ggtitle(eval(nameP.i));
}
dev.off()