Reputation: 663
I have data from 3 different studies. Study A has 21 samples, StudyB has 9 samples and Study C has 12 samples. Now I want to see the value distribution all samples plotted using Boxplots in R. I used the following command
boxplot(A,add=F,at=1:21)
boxplot(B,add=T,at=22:30)
boxplot(C,add=T,at=31:42)
I can only see the 21 samples from study A while 9 samples from Study B and 12 samples from Study C are not visible and they are not fitting into the frame. I want all 42 samples from all Studies in a single frame.
Upvotes: 1
Views: 17279
Reputation: 44555
Use the formula option in boxplot
:
A <- rnorm(21)
B <- rnorm(9)
C <- rnorm(12)
mydf <- data.frame(y=c(A,B,C),x=c(rep(1,length(A)),rep(2,length(B)),rep(3,length(C))))
with(mydf, boxplot(y~x))
Upvotes: 2
Reputation: 25736
You might have a look at the xlim
argument of boxplot
(otherwise your B
and C
data.frame are outside the plot area):
set.seed(1)
a <- rnorm(100)
b <- rnorm(100)
boxplot(a, at=1, xlim=c(0, 3))
boxplot(b, at=2, add=TRUE)
Upvotes: 4