# [R] Setting axis scale for a boxplot

Jim Lemon jim at bitwrit.com.au
Mon Nov 18 20:26:56 CET 2013

```On 11/19/2013 05:57 AM, David Arnold wrote:
> Hi,
>
> I have this code:
>
> par(mfrow=c(3,1))
>
> x1=rnorm(10,60,1)
> x2=rnorm(10,65,1)
> x3=rnorm(10,70,1)
> boxplot(x1,x2,x3,horizontal=TRUE,main="Example 1")
>
> x1=rnorm(10,60,4)
> x2=rnorm(10,65,4)
> x3=rnorm(10,70,4)
> boxplot(x1,x2,x3,horizontal=TRUE,main="Example 2")
>
> x1=rnorm(10,60,9)
> x2=rnorm(10,65,9)
> x3=rnorm(10,70,9)
> boxplot(x1,x2,x3,horizontal=TRUE,main="Example 3")
>
> par(mfrow=c(1,1))
>
> How can I set the horizontal axis limits on all three images to be the same
> for sake of comparison?
>
Hi David,
In addition to Bill's answer where you specify limits at the beginning,
if you want to do it "on the fly" and you are not reusing x1, x2 and x3:

x1a=rnorm(10,60,1)
x2a=rnorm(10,65,1)
x3a=rnorm(10,70,1)
x1b=rnorm(10,60,4)
x2b=rnorm(10,65,4)
x3b=rnorm(10,70,4)
x1c=rnorm(10,60,9)
x2c=rnorm(10,65,9)
x3c=rnorm(10,70,9)
ylim<-range(c(x1a,x2a,x3a,x1b,x2b,x3b,x1c,x2c,x3c))
boxplot(x1a,x2a,x3a,ylim=ylim,horizontal=TRUE,main="Example 1")
boxplot(x1b,x2b,x3b,ylim=ylim,horizontal=TRUE,main="Example 2")
boxplot(x1c,x2c,x3c,ylim=ylim,horizontal=TRUE,main="Example 3")

Jim

```