[Rd] Small inconsistency with boxplot

Mathieu Ribatet mathieu.ribatet at math.univ-montp2.fr
Thu Nov 17 23:39:45 CET 2011


Dear R-core team,

I think I found a small inconsistency in the boxplot function. I don't want to post it as a bug since I'm not sure this might be considered as one according to the FAQ --- and this is not a major problem. Don't hesitate to tell me if I'm wrong.

If you try to do a boxplot on a matrix and set the "at" argument to some vector different from 1:n, n is the number of columns of your matrix, then some boxplots will be hidden since the default "xlim" value will be set to c(0.5, n + 0.5) during the call of the bxp function.

Currently you can easily bypass this problem by setting "xlim" appropriately when calling the boxplot function.

I think it will be better if all boxplots were always shown unless the "xlim" argument is specified. (I realized this behavior when I tried to do boxplots on conditional simulations of a stochastic process ; in which case the suggested behavior might be useful.)

Here's an example

par(mfrow = c(1, 3))
data <- matrix(rnorm(10 * 50), 50)
colnames(data) <- letters[1:10]
x.pos <- seq(-10, 10, length = 10)
boxplot(data, at = x.pos) ## only the last 5 boxplots will appear
boxplot(data, at = 1:10) ## all boxplots will appear
boxplot(data, at = x.pos, xlim = range(x.pos) + c(-0.5, 0.5)) ## all boxplots will be shown

I tried to do a patch if you want to change the current behavior --- note this is my first patch ever so maybe I'm doing it wrong.

*** Downloads/R-2.14.0/src/library/graphics/R/boxplot.R	Mon Oct  3 00:02:21 2011
--- boxplot.R	Thu Nov 17 23:02:45 2011
***************
*** 203,209 ****
      }
  
      if(is.null(pars$xlim))
!         xlim <- c(0.5, n + 0.5)
      else {
  	xlim <- pars$xlim
  	pars$xlim <- NULL
--- 203,209 ----
      }
  
      if(is.null(pars$xlim))
!         xlim <- c(min(at) - 0.5, max(at) + 0.5)
      else {
  	xlim <- pars$xlim
  	pars$xlim <- NULL


----------------------------------------------------------------- 
I3M, UMR CNRS 5149
Universite Montpellier II,
4 place Eugene Bataillon
34095 Montpellier cedex 5   France
http://www.math.univ-montp2.fr/~ribatet
Tel: + 33 (0)4 67 14 41 98



More information about the R-devel mailing list