[R] boxplot question

Thomas Lumley tlumley at u.washington.edu
Fri Jul 27 22:39:36 CEST 2001

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


or if you have multiple groups but don't want names for some strange


Thomas Lumley			Asst. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle

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