plotCIgroup <- function(form, data, horiz=FALSE, set.range = TRUE, arrowlen = 0, includeOverall=TRUE, ...){ require(gmodels) mf <- model.frame(form, data) resp <- mf[,1] fac <- mf[,2] if(includeOverall){ lfac <- levels(fac) fac <- factor(c(as.character(fac), rep("All Obs", length(resp))), levels=c(lfac, "All Obs")) resp <- c(c(resp), c(resp)) } ag <- do.call(rbind, by(resp, list(fac), ci)) ngroup <- nrow(ag) if(!horiz){ yl <- range(c(ag[,2:3])) xd <- (ngroup-1)*.25 xl <- c(1-xd, ngroup + xd) plot(xl, yl, axes=F, type="n", xlab="", ...) points(1:ngroup, ag[,1], ...) axis(1, at=1:ngroup, labels=rownames(ag)) axis(2) box() arrows(1:ngroup, ag[,2], 1:ngroup, ag[,3], code=3, length=arrowlen) if(includeOverall){ abline(v=(max(as.numeric(fac))-.5), lty=2) } } if(horiz){ yl <- range(c(ag[,2:3])) xd <- (ngroup-1)*.25 xl <- c(1-xd, ngroup + xd) plot(yl, xl, axes=F, type="n", ylab="", ...) points(ag[,1], 1:ngroup, ...) axis(2, at=1:ngroup, labels=rownames(ag)) axis(1) box() arrows(ag[,2], 1:ngroup, ag[,3], 1:ngroup, code=3, length=arrowlen) if(includeOverall){ abline(h=(max(as.numeric(fac))-.5), lty=2) } } }