[R] Label / Tick under single Boxplot

Marc Schwartz MSchwartz at MedAnalytics.com
Wed Apr 20 04:26:47 CEST 2005


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

Werner,

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

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

 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))

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

Thus, you can do the following:

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

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

HTH,

Marc Schwartz




More information about the R-help mailing list