R - How to draw 2 box plots on one axis in R?

7.8k Views Asked by At

I have two data sets and for each I am able to produce a box plot separately.

However I need to put both these box plots together on a single axis. How do I do this?

1

There are 1 best solutions below

0
On

This may not be the perfect place to ask this question, but perhaps the the following method will suffice for making a nice-looking pair of boxplots on the same axis.

set.seed(1234)
x1 = rnorm(15, 100, 15);  x2 = rnorm(20, 110, 15)
x = c(x1, x2);  gp = c(rep(1,15), rep(2,20))
boxplot(x ~ gp, col=c("skyblue2","green2"), pch=19)

enter image description here

Or using group names:

gp = c(rep("Blue", 15),rep("Green",20))
boxplot(x ~ gp, col=c("skyblue2","green2"), pch=19, main="Widgets")

enter image description here