Skip to content
Prev 78076 / 398502 Next

boxplot and xlim confusion?

On Thu, 2005-09-29 at 15:28 +0200, Karin Lagesen wrote:
That's because when you use 'horizontal = TRUE' in boxplot(), the x and
y axes are rotated. Thus you need to set 'ylim' and not 'xlim', where
ylim is the range of values in your data irrespective of the axis
orientation.

This is done in bxp(), which is the actual function doing the plotting
for boxplot(). In bxp(), there is the follow code snippet:

        if (horizontal) 
            plot.window(ylim = c(0.5, n + 0.5), xlim = ylim, 
                        log = log)
        else plot.window(xlim = c(0.5, n + 0.5), ylim = ylim, 
                         log = log)

Note in the first case, that the xlim value for plot.window() is set to
the ylim value passed from boxplot() or from bxp(), if called directly.

So, the above examples by Petr should be something like:

boxplot(split(rnorm(30), rep(1:3, each=10)), horizontal = TRUE, 
        names=letters[1:3], ylim = c(-4, 4))

boxplot(split(rnorm(30), rep(1:3, each=10)), horizontal =TRUE, 
        names=c(NA,"b",NA), ylim = c(-4, 4))


HTH,

Marc Schwartz