I have two groups of data (x1 and x2 versus y1 and y2), which I would like to display as two groups of boxplots.
I tried the following, but it displays the wrong data because the vectors x1 and x2 (and y1 and y2) are not of the same lengths:
x1 <- c(2,3,4)
x2 <- c(0,1,2,3,4,5)
y1 <- c(3,4,5)
y2 <- c(1,2,3,4,5,6)
d0 <- matrix(c(x1, x2), ncol=2)
d1 <- matrix(c(y1, y2), ncol=2)
lmts <- range(d0,d1)
par(mfrow = c(1, 2))
boxplot(d0, ylim=lmts, xlab="x")
boxplot(d1, ylim=lmts, xlab="y")
This is what it shows (of course, I wanted the whiskers of the first boxplot to go from 2 to 4 instead, according to the range of x1, etc.):
Yup, or you could have used.
On a complete side not based on the comments...
Another options is to use the ggplot2 package. You need a bit more work to put your data into one data.frame. But then it is very easy.