pp.timeplot <- function (x, div="year", type="l", xlab="", xnam=NULL, ...) { ## simple-minded function to plot time series nicely ## placed in the public domain by Burns Statistics 2010 ## if(is.data.frame(x)) x <- as.matrix(x) if(is.matrix(x)) { matplot(x, axes=FALSE, type=type, xlab=xlab, ...) if(!length(xnam)) { xnam <- row.names(x) } else if(length(xnam) != nrow(x)) { stop("'xnam' is the wrong length") } } else { plot(x, axes=FALSE, type=type, xlab=xlab, ...) if(!length(xnam)) { xnam <- names(x) } else if(length(xnam) != length(x)) { stop("'xnam' is the wrong length") } } axis(2) switch(div, decade={ tim <- substring(xnam, 1, 3) tlab <- paste(unique(tim), "0's", sep="") }, year={ tim <- substring(xnam, 1, 4) tlab <- unique(tim) } ) tcount <- cumsum(table(tim)) tbrk <- tcount[-length(tcount)] + .5 axis(1, at=tbrk, labels=rep("", length(tbrk)), tck=1, lty=2, col=2) axis(1, at=tbrk, labels=rep("", length(tbrk)), lty=2, col=2) maxd <- max(diff(tcount)) # adjust last one if only partial period tcount[length(tcount)] <- tcount[length(tcount) - 1] + maxd axis(1, at=tcount - maxd/2, labels=tlab, tck=0) box() }