From marc_schwartz at comcast.net  Mon Oct 15 14:20:16 2007
From: marc_schwartz at comcast.net (marc_schwartz at comcast.net)
Date: Mon, 15 Oct 2007 14:20:16 +0200 (CEST)
Subject: [Rd] boxplot() confuses x- and y-axes (PR#10345)
Message-ID: <20071015122016.CB1E12834613@mail.pubhealth.ku.dk>

On Mon, 2007-10-15 at 10:30 +0200, bob.ohara at helsinki.fi wrote:
> Full_Name: Bob O'Hara
> Version: 2.6.0
> OS: Windows XP
> Submission from: (NULL) (88.112.20.250)
> 
> 
> Using horizontal=TRUE with boxplot() confuses it as to what is an x- or y-axis. 
> At least, xlim= and ylim= are the wrong way round, log="x" (or "y") and xaxt=
> work as expected, I haven't looked at anything else.
> 
> Some code to see if you can reproduce the bug (or discover it's in my head...):
> 
> boxplot(count ~ spray, data = InsectSprays)
> 
> # Try to change x-axis:
> boxplot(count ~ spray, data = InsectSprays, xlim=c(0,50))
> 
> # Plot horizontally:
> boxplot(count ~ spray, data = InsectSprays, horizontal=TRUE)
> 
> # Now try to change x-axis:
> boxplot(count ~ spray, data = InsectSprays, horizontal=TRUE, xlim=c(0,50))
> # Changes y-axis!
> 
> # Now try to change y-axis:
> boxplot(count ~ spray, data = InsectSprays, horizontal=TRUE, ylim=c(0,50))
> # Changes x-axis!
> 
> # Plot x-axis on log scale:
> boxplot(count+1 ~ spray, data = InsectSprays, horizontal=TRUE, log="x")
> # Does indeed change x-axis
> 
> # Don't add ticks on x-axis:
> boxplot(count ~ spray, data = InsectSprays, horizontal=TRUE, xaxt="n")
> # Works as expected.

Hi Bob,

No, it's not in your head. This is documented in ?bxp, which is the
function that actually does the plotting for boxplot(). See the
description of 'pars' in ?bxp:

"Currently, yaxs and ylim are used ???along the boxplot???, i.e.,
vertically, when horizontal is false, and xlim horizontally."

So essentially, the named 'x' and 'y' axes are rotated 90 degrees when
you use 'horizontal = TRUE', rather than the vertical axis always being
'y' and the horizontal axis always being 'x'. This has been discussed on
the lists previously.

Regards,

Marc Schwartz



[Rd] boxplot() confuses x- and y-axes (PR#10345)
marc_schwartz at comcast.net