[Rd] New Package: gregmisc

Warnes, Gregory R gregory_r_warnes@groton.pfizer.com
Tue, 29 May 2001 15:58:30 -0400



  > 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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._