Paul Burns
Paul Burns

Reputation: 1

I want to put 3 boxplots from 3 different datasets into one graph in R

I have 3 different datasets od scores, named aerobic1, aerobic2 and aerobic3. There is only one column of scores in each dataset but I have them in different datasets because aerobic1 has 42 measurements, aerobic2 has 20 and aerobic3 has 19.

I would like to show these 3 datasets as boxplots on the one graph with titles for each boxplot. Can anyone help?? Sorry, I'm just a beginner with R

I tried this code below from a previous post but the problem is, the 3rd boxplot is half off the screen and the scale on Y is -2 to +2 whereas my data ranges from scores of 45 to 180. any help much appreciated

set.seed(1)
aerobic1 <- rnorm(100)
aerobic2 <- rnorm(100)
aerobic3 <- rnorm(100)

boxplot(aerobic1, at=1, xlim=c(0, 3))
boxplot(aerobic2, at=2, add=TRUE)
boxplot(aerobic3, at=3, add=TRUE)

Upvotes: 0

Views: 3476

Answers (1)

Sven Hohenstein
Sven Hohenstein

Reputation: 81703

You can combine the data with c and find out the range to set the limits of the y axis with ylim.

boxplot(aerobic1, at = 1, xlim = c(0.5, 3.5), 
  ylim = range(c(aerobic1, aerobic2, aerobic3)))
boxplot(aerobic2, at = 2, add = TRUE)
boxplot(aerobic3, at = 3, add = TRUE)

enter image description here

Upvotes: 4

Related Questions