## Are US presidential approval ratings linked to sunspot activity?
## 'ts' method; set block height, default justification is at bottom.
xyplot(presidents) + layer(panel.xblocks(sunspot.year > 50, height = 3))
## blocks in a light shading colour, full panel height.
xyplot(presidents) +
layer(panel.xblocks(sunspot.year > 50, col = "#e6e6e6"), under=TRUE)
## multiple colour values given in the 'y' argument.
sscols <- cut(sunspot.year, c(50,150,Inf), labels=c("yellow","orange"))
xyplot(presidents, lwd = 2) +
layer(panel.xblocks(time(sunspot.year), y = sscols, alpha = 0.5))
Run the code above in your browser using DataLab