pp.timeline <- function (x, div = "year", xnam = NULL, lwd=3, legend="bottomright", colors=c("gold", "steelblue", "black", "forestgreen", "brown", "red"), ...) { if (is.data.frame(x)) x <- as.matrix(x) if(ncol(x) != 2) stop("'x' must be a two-column matrix") plot(x, type = "n", ...) if (!length(xnam)) { xnam <- rownames(x) } else if (length(xnam) != nrow(x)) { stop("'xnam' is the wrong length") } if (!is.character(div) || length(div) != 1) { stop("'div' must be a single character string -- given has mode ", mode(div), " and length ", length(div)) } div.menu <- c("years", "decades", "months") div.num <- pmatch(div, div.menu, nomatch = 0) if(div.num == 0) { stop("unknown or ambiguous value given for 'div' -- possible ", "values are: ", paste(div.menu, collapse=", ")) } div <- div.menu[div.num] switch(div, decades = { tim <- substring(xnam, 1, 3) tuniq <- unique(tim) tlab <- paste(tuniq, "0's", sep = "") }, years = { tim <- substring(xnam, 1, 4) tlab <- tuniq <- unique(tim) }, months = { tim <- substring(xnam, 1, 7) tlab <- tuniq <- unique(tim) }) if(length(colors) < length(tuniq)) stop("not enough colors specified") for(i in seq(along=tuniq)) { lines(x[tim == tuniq[i], , drop=FALSE], col=colors[i], lwd=lwd) } if(length(legend)) { legend(legend, legend=tlab, lwd=lwd, col=colors[1:length(tuniq)]) } }