############################################################# # these colors were shamefully stolen from the guide at # http://jfly.iam.u-tokyo.ac.jp/color/ # entitled "How to make figures and presentations that are # friendly to color blind people" ############################################################# cb_colors <- c(rgb(0, 0 , 0 , maxColorValue=255), rgb(230, 159, 0 , maxColorValue=255), rgb( 86, 180, 233, maxColorValue=255), rgb( 0, 158, 115, maxColorValue=255), rgb(240, 228, 66, maxColorValue=255), rgb( 0, 114, 178, maxColorValue=255), rgb(213, 94, 0, maxColorValue=255), rgb(204, 121, 167, maxColorValue=255)) ############################################### # read.rdb(filename) # reads in an RDB file to an R data frame ############################################### read.rdb <- function(file) { rdb.header.lines <- function(file) { fh <- file(file) header.lines <- 0 while(substr(readLines(fh, n=header.lines+1)[header.lines+1],1,1)=="#") header.lines <- header.lines + 1 close(fh) header.lines } format.rdb.to.r.element <- function(elem) { if(substr(elem,nchar(elem),nchar(elem)) == "N") return("numeric") else return("character") } header.lines <- rdb.header.lines(file) data <- read.delim(file, skip=header.lines, nrows=1, colClasses="character") col.names <- colnames(data) col.classes <- sapply(as.vector(data[1,], mode="character"), format.rdb.to.r.element) read.delim(file, skip=header.lines+2, header=FALSE, col.names=col.names, colClasses=col.classes) } ############################################################# # pmulthist # is just like multhist from the plotrix library except # this does a density histogram rather than using counts # (code from Ben Bolker at the University of Flordia; # slightly modified for rescaling y-axis to make room for # legends) ############################################################# pmulthist <- function (x, breaks = "Sturges", yscale = 1, ...) { allhist <- hist(unlist(x), breaks = breaks, plot = FALSE) combhist <- sapply(x, function(z) hist(z, breaks = allhist$breaks, plot = FALSE)$density) ylim = c(0, max(unlist(combhist)) * yscale) barplot(t(combhist), beside = TRUE, names = signif(allhist$mids, 2), ylim=ylim, ...) } ############################################### # denplot(data, ...) # computes a kernel density estimate for each # column of the input and plots it; # ... is passed as parameters to matplot ############################################### denplot <- function (a, ...) { denlist <- lapply(a, density, na.rm=TRUE) xmat <- sapply(1:length(denlist), function(i) denlist[[i]]$x) ymat <- sapply(1:length(denlist), function(i) denlist[[i]]$y) matplot(xmat, ymat, type="l", lty="solid", ...) } ################################################ # eps_output(filename) # open filename for eps output using graphics # parameters that I like ################################################ eps_output <- function(file) { postscript(file, family="Times", height=5, width=6, horizontal=FALSE, onefile=FALSE, paper= "special") }