[R] Label / Tick under single Boxplot

Martin Maechler maechler at stat.math.ethz.ch
Wed Apr 20 14:55:22 CEST 2005


>>>>> "Marc" == Marc Schwartz <MSchwartz at medanalytics.com>
>>>>>     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> do.call("axis", c(list(side = 1 + horizontal, at = at, 
    Marc> labels = z$names), ax.pars))

    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




More information about the R-help mailing list