Re: [R] Label / Tick under single Boxplot

From: Martin Maechler <>
Date: Wed 20 Apr 2005 - 22:55:22 EST

>>>>> "Marc" == Marc Schwartz <> >>>>> on Tue, 19 Apr 2005 21:26:47 -0500 writes:

    Marc> On Wed, 2005-04-20 at 02:08 +0200, Werner Wernersen wrote:
>> Hi!
>> I am trying to get the tick / label under a stacked
>> boxplot with only a single
>> data row. With >=2 rows it works, but with a single
>> one the tick resp. my class
>> name is not printed below the boxplot. Can anybody
>> point me to what am I doing
>> wrong?
>> For example:
>> boxplot(data.frame(c(3,4,5)),names=list("a"),beside=F)
>> Here, I would like to have the "a" below the single
>> box.
>> Thanks a lot,
>> Werner
>> using R 2.0.1 on Win2K

    Marc> Werner,

    Marc> Just to be sure that you do want a boxplot and not a barplot, as in the     Marc> former case, the 'beside=F' is unused.

    Marc> Presuming that you do want a boxplot, there is the following code in the     Marc> bxp() function, which actually does the plotting:

    Marc> if (is.null(show.names)) 
    Marc> show.names <- n > 1
    Marc> if (show.names) 
    Marc>"axis", c(list(side = 1 + horizontal, at = at, 
    Marc> labels = z$names),

    Marc> The result of the first if() statement in the case of a single group (n     Marc> = 1) is that the names are not plotted.

    Marc> Thus, you can do the following:

    Marc> boxplot(3:5)
    Marc> axis(1, at = 1, "a")

    Marc> Presuming that you do not modify the 'at' argument in the call to
    Marc> boxplot(), the boxes are by default drawn at integer values on the x
    Marc> axis, which in this case is 1.

yes, or more generally useful approach:

  1. compute and store the boxplot and
  2. then draw it with appropriate specifications e.g.,

  bp <- boxplot(data.frame(a=c(1:5, 20)), plot=FALSE)   bxp(bp, show.names=TRUE)

Martin mailing list PLEASE do read the posting guide! Received on Wed Apr 20 23:21:56 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:17 EST