Skip to content

Potential improvement to boxplot when outline=FALSE is set? (PR#13196)

1 message · racinej at mcmaster.ca

#
Hi.

I have recently noticed that when using boxplot with outline=FALSE, the
default ylim (xlim if horizontal=TRUE) might be improved on. The default
can result in much wasted display and hard to read plots. A simple
snippet of test code is given below that illustrates the issue along
with a suggested improvement.

Thanks ever so much for your wonderful and ongoing contributions to the
open source community.

## Demonstration code to illustrate that when outline=FALSE in
## boxplots, ylim (or xlim when horizontal=TRUE is set) might be
## better set.

set.seed(12345)
x <- rchisq(10000,df=1)
par(mfrow=c(2,1))
## Default wastes much graphics display space...
boxplot(x,outline=FALSE)
## This simple modification can rectify the situation...
ylim=c(max(min(x),quantile(x,.25)-1.5*IQR(x)),
  min(max(x),quantile(x,.75)+1.5*IQR(x)))
boxplot(x,outline=FALSE,ylim=ylim)

## End of demonstration code

Note that when using lists, the one would compute, say,
max(min(x),quantile(x,.25)-1.5*IQR(x)) for each element of the list and
take the minimum over each of these to get the lower bound for ylim
(xlim if horizontal=FALSE).

Thanks for giving this your consideration.

-- Jeff