I am trying to generate a pdf for each station using ggplot. The code is running with no errors, though, the pdf is empty at my directory.
`structure(list(Agency.Station.ID = structure(c(41L, 31L, 30L,
42L, 1L, 32L, 32L, 28L, 3L, 42L, 34L, 42L, 30L, 36L, 30L), .Label = c("MI064E009.1D",
"MI064E009.8D", "MI064E010-0D", "MI064E011.2D", "MI064E012.8D",
"MI064E013.6D", "MI064E015.2D", "MI064E016.3D", "MI064E017.0D",
"MI064E018.1D", "MI064E018.9D", "MI064E020.9D", "MI064E021.9D",
"MI064E023.2D", "MI064E024.2D", "MI064W009.2D", "MI064W010.0D",
"MI064W011.1D", "MI064W012.8D", "MI064W013.6D", "MI064W015.1D",
"MI064W015.9D", "MI064W017.0D", "MI064W017.9D", "MI064W018.4D",
"MI064W018.9D", "MI064W020.2D", "MI064W021.9D", "MI064W023.2D",
"MI064W024.2D", "MI070E206.0D", "MI070E208.5D", "MI070E209.6D",
"MI070E210.0D", "MI070E211.0D", "MI070E230.7D", "MI070E232.7D",
"MI070E235.0D", "MI070W208.2D", "MI070W209.5D", "MI070W210.0D",
"MI070W232.7D"), class = "factor"), date1 = structure(c(16753,
16436, 16591, 16638, 16742, 16748, 16593, 16769, 16575, 16737,
16540, 16521, 16447, 16723, 16749), class = "Date"), DT = structure(c(1447499400,
1420138500, 1433557500, 1437618900, 1446587100, 1447108500, 1433691900,
1448924700, 1432161900, 1446111600, 1429095000, 1427514900, 1421096400,
1444911600, 1447177200), tzone = "", class = c("POSIXct", "POSIXt"
)), variables = c("Speed", "Total.Volume", "Total.Volume", "Total.Volume",
"Total.Volume", "Total.Volume", "Occupancy", "Speed", "Speed",
"Occupancy", "Total.Volume", "Speed", "Total.Volume", "Total.Volume",
"Occupancy"), values = c(58, 57, 76.7, 40.7, NA, NA, 7.3, 14,
62, 1.1, 49.5, 44, 153.3, 112.8, NA)), row.names = c(NA, -15L
), class = c("tbl_df", "tbl", "data.frame"))`
The code I am using is
for(i in levels(df$Agency.Station.ID)) {
pdf(paste0(i,'.pdf'), width = 20)
for(j in levels(df$date1)) {
subset.data <- df[which(df$Agency.Station.ID==i & df$date1==j),]
if (nrow(subset.data)!=0) {
p <- ggplot(data=subset.data, aes(DT, values, group = variables))+
geom_line(aes(color=variables)) +
labs(title=paste('Station:',i, " Date:",j)) +
theme_bw()
invisible(print(p))
}
}
dev.off()
}