I am trying to loop through multiple headers using a for loop, in order to create multiple plots. I'm just not sure what I'm doing wrong when passing my header variable into my for loop, as I keep getting warnings and errors from R.
Here is the for loop I am using:
dflist <- c('ABStemp', 'ABSelec', 'ABSheat')
for (i in dflist) {
plot1<-contourplot(i ~ hour * weekday | month,
data = HourlyTotal,
cuts = 200,
labels=TRUE,
contour=FALSE,
drop.unused.levels = lattice.getOption("drop.unused.levels"),
region = TRUE,
pretty=FALSE,
xlab = "",
ylab = "Day of Week",
col.regions=colorRampPalette(c("blue","yellow","red")),
main = "Absolute Error (Temperature)",
layout=c(2,4),
as.table= TRUE)
plot2<-contourplot(i ~ hour * weekday,
aspect=0.3,
data = HourlyTotal,
cuts = 200,
#labels=TRUE,
contour=FALSE,
region = TRUE,
pretty=FALSE,
xlab = "Hour of Day",
ylab = "Day of Week",
col.regions=colorRampPalette(c("blue","yellow","red"))
)
plot3<-contourplot(i ~ hour * month,
aspect=0.3,
data = HourlyTotal,
cuts = 200,
#labels=TRUE,
contour=FALSE,
region = TRUE,
pretty=FALSE,
xlab = "Hour of Day",
ylab = "Month of Year",
col.regions=colorRampPalette(c("blue","yellow","red"))
)
pdf(paste('Rplot',i,'.pdf'), width=8, height=12)
print(plot1, more=TRUE)
print(plot2, more=TRUE)
print(plot3, more=FALSE)
dev.off()
}
I have tried numerous variations on the above, but each time, the i variable fails to pass into the loop correctly, and I get NA's in each trellis plot.
The dataset I am using can be found here: SummaryData. Also, my full code is available online here: http://danielcoakley.com/projects/energy-simulation/
Thank You!