[R] Label / Tick under single Boxplot

Werner Wernersen pensterfuzzer at yahoo.de
Wed Apr 20 09:24:34 CEST 2005


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

That works perfect, thank you, Marc!

I also tried to look into the source code of boxplot()
but when I type "boxplot" 
R returns only

function (x, ...)
UseMethod("boxplot")
<environment: namespace:graphics>

instead of the full source code as other function like
colSums do.
How did you find out about bxp?

Best,
   Werner




More information about the R-help mailing list