Friday 2011-06-17

Plotting multi lines in R can get annoying with the color selections, people normally just use rainbow() or something like it, however that ignores using solid and dashed lines to get a two-fold gain in color disparity.

Using the colors_term() below with lty=1:2 works for computer displays. Presentations via projectors should use colors_projector().

# sat idea from http://rankexploits.com/musings/2011/less-sucky-colors-in-r/
colors_term <- function(n){
	c_ <- c('black', rainbow(n-1, s = 1, v = 0.7))
	c(rbind(c_, c_))
}
colors_projector <- function(n){
	c_ <- c('black', 'red', 'blue')
	c(rbind(c_, c_))
}

z <- ts(matrix(runif(50), 5, 10), start=c(2000,1))
plot(z, plot.type="single", col=colors_term(5), lty=1:2)