I need to make a bunch of PDF files of histograms. I tried gatelist = unique(mdf$ArrivalGate) for( gate in gatelist) { outfile = paste("../", airport, "/", airport, "taxiHistogram", gate, ".pdf", sep="") pdf(file = outfile, width = 10, height=8, par(lwd=1)) title=paste("Taxi time for Arrival Gate", gate, "by Runway at", airport) gdf = mdf[mdf$ArrivalGate == gate, ] gdf$tt= gdf$TaxiTime/60 histogram(~(gdf$tt) | gdf$Runway, data=gdf, type="count", ylab="Count", breaks=20, main=title, xlab="taxi time (min)", par.strip.text=list(cex=0.7)) dev.off() } But when I do this, the pdf files are all empty. If I eliminate the call to pdf() and dev.off(), and step through the loop manually, the histograms still do not plot, even though any one of them will plot. What am I doing wrong? Thanks, Jim Rome
G'day James, On Wed, 31 Mar 2010 21:44:31 -0400 James Rome <jamesrome at gmail.com> wrote:> I need to make a bunch of PDF files of histograms.[...]> What am I doing wrong?http://cran.ms.unimelb.edu.au/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f HTH. Cheers, Berwin ========================== Full address ===========================Berwin A Turlach Tel.: +61 (8) 6488 3338 (secr) School of Maths and Stats (M019) +61 (8) 6488 3383 (self) The University of Western Australia FAX : +61 (8) 6488 1028 35 Stirling Highway Crawley WA 6009 e-mail: berwin at maths.uwa.edu.au Australia http://www.maths.uwa.edu.au/~berwin
Have you tried plot(pic) -----Original Message----- From: Berwin A Turlach <berwin at maths.uwa.edu.au> Sent: Wednesday, March 31, 2010 10:15 PM To: James Rome <jamesrome at gmail.com> Cc: r-help at r-project.org <r-help at r-project.org> Subject: Re: [R] pdf files in loops On Wed, 31 Mar 2010 22:06:48 -0400 James Rome <jamesrome at gmail.com> wrote:> print() did not help, and I get strange messages about mode(onefile) > not being changed:Either: R> pic <- histogram(...) R> print(pic) or R> print(histogram(...))> I would actually like all the histograms in one pdf file too...Then move the pdf() and the dev.off() commands outside the loop. HTH. Cheers, Berwin ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.