[R] pdf files in loops

James Rome jamesrome at gmail.com
Thu Apr 1 03:44:31 CEST 2010

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)",  

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?

Jim Rome

More information about the R-help mailing list