Freitag, 3. Juni 2016

panel.first in formula plot revisited

Today I scouted an issue, which I already have solved at least twice formerly - and couldn't remember at all. Getting older and older...  

d.my <- data.frame(cal_d=as.Date(c("2011-12-30","2012-01-03","2012-04-07","2012-07-08")), y=1:4)  

The following code would fail to produce a grid():
plot(y ~ cal_d, d.my, panel.first=grid())

This will paint the grid, but choose the wrong ticks:
plot(y ~ cal_d, d.my, panel.first=quote(grid()))

This will paint the grid correctly:
plot(y ~ cal_d, d.my, panel.first=quote({
    grid(nx=NA, ny=NULL)
    abline(v=axis.Date(1, x=d.my$cal_d, labels=NA, col=NA), col="grey", lty="dotted")
}))  

Reference found: https://stat.ethz.ch/pipermail/r-help/2011-May/279169.html