I've thrown a couple of useful functions into a new package "gregmisc" and uploaded them to ftp://ftp.ci.tuwien.ac.at/incoming/gregmisc_0.1.1.tgz Here's DESCRIPTION: Package: gregmisc Description: Misc Functions written/maintained by Gregory R. Warnes Title: Greg's Miscellaneous Functions Version: 0.1 Date: 2001/05/24 Depends: R Maintainer: Gregory R. Warnes <Gregory_R_Warnes@groton.pfizer.com> Author: Gregory R. Warnes. Includes code provided by William Venables and Ben Bolker. License: GPL (version 2 or later) and INDEX: boxplot.n Produce a Boxplot Annotated with the Number of Observations ci Compute Confidence Intervals plotCI Plot Error Bars plotmeans Plot Group Means and Confidence Intervals I'm perfectly happy for these functions to get incorporated into other packages. Feel free to email comments/criticisms/whatever. -Greg -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Do you have the latest version of plotCI? (attached below, I didn't send it as an attachment for the sake of R-devel) It uses arrows() instead of segments(), which simplifies the code a bit and incidentally makes it work with logarithmic axes as well (since the sizes of the bar ends are specified in absolute rather than user units). Should this code be the first entry in the "miscellaneous code" repository at CRAN that was discussed a while back? By the way, something occurred to me ... my "miscellaneous packages" function (which I haven't made available to CRAN yet, although I probably will eventually) is called "bbmisc". Yours is called "gregmisc". Would it make any sense to standardize these on "<lastname>misc" or "<first_initial><lastname>misc" (bolkermisc, bbolkermisc) to avoid confusion once we have a whole bunch of these packages? Also by the way, congratulations for actually getting around to posting your miscellaneous functions to CRAN! I hope to do as well. Ben Bolker plotCI <- function (x, y = NULL, uiw, liw = uiw, aui=NULL, ali=aui, err="y", ylim=NULL, xlim=NULL, sfrac = 0.01, gap=0, add=FALSE, col=par("col"), lwd=par("lwd"), slty=par("lty"), xlab=NULL, ylab=NULL, main="", pt.bg = NA, scol=col, axes=TRUE, ...) { # from Bill Venables, R-list if (is.list(x)) { y <- x$y x <- x$x } if (is.null(y)) { if (is.null(x)) stop("both x and y NULL") y <- as.numeric(x) x <- seq(along = x) } if (missing(xlab)) xlab <- deparse(substitute(x)) if (missing(ylab)) ylab <- deparse(substitute(y)) if (missing(uiw)) { ## absolute limits ui <- aui li <- ali } else { ## relative limits if (err=="y") z <- y else z <- x ui <- z + uiw li <- z - liw } if (err=="y" & is.null(ylim)) ylim <- range(c(y, ui, li), na.rm=TRUE) else if (err=="x" & is.null(xlim)) xlim <- range(c(x, ui, li), na.rm=TRUE) if (!add) plot(x, y, ylim = ylim, xlim = xlim, col=col, lwd=lwd, xlab=xlab, ylab=ylab, main=main, type="n", axes=axes, ...) if (gap==TRUE) gap <- 0.01 ## default gap size ul <- c(li, ui) if (err=="y") { gap <- rep(gap,length(x))*diff(par("usr")[3:4]) smidge <- par("fin")[1] * sfrac arrows(x , li, x, pmax(y-gap,li), col=col, lwd=lwd, lty=slty, angle=90, length=smidge, code=1) arrows(x , ui, x, pmin(y+gap,ui), col=col, lwd=lwd, lty=slty, angle=90, length=smidge, code=1) } else if (err=="x") { gap <- rep(gap,length(x))*diff(par("usr")[1:2]) smidge <- par("fin")[2] * sfrac arrows(li, y, pmax(x-gap,li), y, col=col, lwd=lwd, lty=slty, angle=90, length=smidge, code=1) arrows(ui, y, pmin(x+gap,ui), y, col=col, lwd=lwd, lty=slty, angle=90, length=smidge, code=1) } ## _now_ draw the points (in case we want to have "bg" set for points) points(x, y, col=col, lwd=lwd, bg=pt.bg, ...) invisible(list(x = x, y = y)) } On Thu, 24 May 2001, Warnes, Gregory R wrote:> I've thrown a couple of useful functions into a new package "gregmisc" and > uploaded them to ftp://ftp.ci.tuwien.ac.at/incoming/gregmisc_0.1.1.tgz > > Here's DESCRIPTION: > > Package: gregmisc > Description: Misc Functions written/maintained by Gregory R. Warnes > Title: Greg's Miscellaneous Functions > Version: 0.1 > Date: 2001/05/24 > Depends: R > Maintainer: Gregory R. Warnes <Gregory_R_Warnes@groton.pfizer.com> > > Author: Gregory R. Warnes. Includes code provided by William > Venables > and Ben Bolker. > License: GPL (version 2 or later) > > and INDEX: > > boxplot.n Produce a Boxplot Annotated with the Number > of > Observations > ci Compute Confidence Intervals > plotCI Plot Error Bars > plotmeans Plot Group Means and Confidence Intervals > > > I'm perfectly happy for these functions to get incorporated into other > packages. Feel free to email comments/criticisms/whatever. > > -Greg > > > > > LEGAL NOTICE > Unless expressly stated otherwise, this message is confidential and may be privileged. It is intended for the addressee(s) only. Access to this E-mail by anyone else is unauthorized. If you are not an addressee, any disclosure or copying of the contents of this E-mail or any action taken (or not taken) in reliance on it is unauthorized and may be unlawful. If you are not an addressee, please inform the sender immediately. > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-- 318 Carr Hall bolker@zoo.ufl.edu Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker Box 118525 (ph) 352-392-5697 Gainesville, FL 32611-8525 (fax) 352-392-3704 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> From: ben@zoo.ufl.edu [mailto:ben@zoo.ufl.edu]> > > Do you have the latest version of plotCI? (attached > below, I didn't > send it as an attachment for the sake of R-devel) It uses arrows() > instead of segments(), which simplifies the code a bit and > incidentally > makes it work with logarithmic axes as well (since the > sizes of the bar > ends are specified in absolute rather than user units). Hmmm. I merged our two versions together. The revised version is pasted in below and is included in revisions 0.1.3 of gregmisc, as is an updated .Rd file. > > Should this code be the first entry in the "miscellaneous code" > repository at CRAN that was discussed a while back? > > By the way, something occurred to me ... my > "miscellaneous packages" > function (which I haven't made available to CRAN yet, > although I probably > will eventually) is called "bbmisc". Yours is called > "gregmisc". Would > it make any sense to standardize these on "<lastname>misc" or > "<first_initial><lastname>misc" (bolkermisc, bbolkermisc) to avoid > confusion once we have a whole bunch of these packages? I think that it is a better idea to create packages with coherent themes and make it easy for people to submit single functions to them. Perhaps we should create: plotmisc to hold things like boxplot.n(), plotCI(), plotmeans(), ... modelmisc to hold things like CI(),... datamisc to hold example data sets ... and encourage contributions. > > Also by the way, congratulations for actually getting > around to posting > your miscellaneous functions to CRAN! I hope to do as well. YES, the jump from "I wrote this useful function" to "posting to CRAN" is too big. Hence the idea of the "*misc" packages... So, if you have some functions, just send along a function and a .Rd file and I'll create the packages... > > Ben Bolker > =============== revised plotCI code ===================plotCI <- function (x, y = NULL, uiw, liw = uiw, # bar widths -OR- ui, li, # bar ends err='y', # bar direction, 'y' or 'x' col=par("col"), ylim=NULL, xlim=NULL, barcol=col, sfrac = 0.01, gap=1, lwd=par("lwd"), lty=par("lty"), labels=FALSE, add=FALSE, xlab, ylab, ... ) { if (is.list(x)) { y <- x$y x <- x$x } if(missing(xlab)) xlab <- deparse(substitute(x)) if(missing(ylab)) { if(is.null(y)) { xlab <- "" ylab <- deparse(substitute(x)) } else ylab <- deparse(substitute(y)) } if (is.null(y)) { if (is.null(x)) stop("both x and y NULL") y <- as.numeric(x) x <- seq(along = x) } if(err=="y") z <- y else z <- x if(missing(ui)) ui <- z + uiw if(missing(li)) li <- z - liw if(err=="y" & is.null(ylim)) { ylim <- range(c(y, ui, li), na.rm=TRUE) } else if(err=="x" & is.null(xlim)) { xlim <- range(c(x, ui, li), na.rm=TRUE) } if(!add) { if(missing(labels) || labels==F ) plot(x, y, ylim = ylim, xlim=xlim, col=col, xlab=xlab, ylab=ylab, ...) else { plot(x, y, ylim = ylim, xlim=xlim, col=col, type="n", xlab=xlab, ylab=ylab, ...) text(x, y, label=labels, col=col ) } } if(err=="y") { if(gap!=FALSE) gap <- strheight("O") * gap smidge <- par("fin")[1] * sfrac # draw upper bar if(!is.null(li)) arrows(x , li, x, pmax(y-gap,li), col=barcol, lwd=lwd, lty=lty, angle=90, length=smidge, code=1) # draw lower bar if(!is.null(ui)) arrows(x , ui, x, pmin(y+gap,ui), col=barcol, lwd=lwd, lty=lty, angle=90, length=smidge, code=1) } else { if(gap!=FALSE) gap <- strwidth("O") * gap smidge <- par("fin")[2] * sfrac # draw left bar if(li!=NULL) arrows(li, y, pmax(x-gap,li), y, col=col, lwd=lwd, lty=slty, angle=90, length=smidge, code=1) if(ui!=NULL) arrows(ui, y, pmin(x+gap,ui), y, col=col, lwd=lwd, lty=slty, angle=90, length=smidge, code=1) } invisible(list(x = x, y = y)) } LEGAL NOTICE Unless expressly stated otherwise, this message is confidential and may be privileged. It is intended for the addressee(s) only. Access to this E-mail by anyone else is unauthorized. If you are not an addressee, any disclosure or copying of the contents of this E-mail or any action taken (or not taken) in reliance on it is unauthorized and may be unlawful. If you are not an addressee, please inform the sender immediately. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._