[R] boxplot question

Marc R. Feldesman feldesmanm at pdx.edu
Fri Aug 3 04:13:30 CEST 2001

At 01:39 PM 7/27/01, Thomas Lumley wrote:
 >On Fri, 27 Jul 2001, Marc Feldesman wrote:
 >> I'm graphing a series of boxplots of grouped data inside a function that
 >> passes the data.frame, the names vector, and a title vector.
 >> Because both the data subset changes with each successive pass through the
 >> function, occasionally the names vector turns up with only one group to
 >> plot.  This is an expected result.  However, when the names argument in
 >> boxplot has only a single name, it doesn't put in on the
 >> boxplot.  (Actually, this is true whether the names argument is present or
 >> not.  If the call to boxplot is in formula form (e.g. variable ~ group),
 >> the plot doesn't name the group if there is only one group.)
 >Yes. In order to get around this you need to modify the bxp() function
 >that does the actual plotting.
 >My recommended change is to add a show.names argument:
 >  function (z, notch = FALSE, width = NULL, varwidth = FALSE, notch.frac =
 >  0.5,  boxwex = 0.8, border = par("fg"), col = NULL, log = "", pars =
 >  NULL, frame.plot = axes, horizontal = FALSE, add = FALSE, at = NULL,
 >  show.names=NULL, ...)
 >and then near the end of the function replace the if(axes) conditional
 >    if (axes) {
 >        ax.pars <- pars[names(pars) %in% c("xaxt", "yaxt", "las")]
 >	if(is.null(show.names)) show.names<-(n>1)
 >        if (show.names)
 >            do.call("axis", c(list(side = 1 + horizontal, at = at,
 >                labels = z$names), ax.pars))
 >        do.call("axis", c(list(side = 2 - horizontal), ax.pars))
 >    }
 >Now the standard behaviour is the same but you can override it with
 >  temp<-boxplot(y~g,plot=FALSE)
 >  bxp(temp,show.names=TRUE)
 >or if you have multiple groups but don't want names for some strange
 >  bxp(temp,show.names=FALSE)

This is a handy solution that works well as long as one remembers to put 
parameters usually included in the boxplot() call in the call to bxp().

Any chance of making this a part of the next release of R?  It doesn't seem 
like it should/would break existing code.

r-help 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-help-request at stat.math.ethz.ch

More information about the R-help mailing list