Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple boxplots in one in R

Tags:

r

boxplot

Hi I need to plot a boxplot in R. I have two matrices a and b. I created a boxplot for a and want to create boxplot for b on the same plot for a. The boxplots of the b matrix should lie on the whiskers of the boxplot for a.

Is there a way I can do it in R ??

like image 479
user1021713 Avatar asked Apr 02 '12 11:04

user1021713


People also ask

How do you make a boxplot with multiple groups in R?

Box plot for multiple groups In order to create a box plot by group in R you can pass a formula of the form y ~ x , being x a numerical variable and y a categoriacal variable to the boxplot function. You can pass the variables accessing the data from the data frame using the dollar sign or subsetting the data frame.


1 Answers

To add a boxplot to an existing plot, just use the argument add=TRUE, viz:

##Some data
a = rnorm(20)
b = rnorm(20, 2, 0.3)

##The plots
boxplot(a)
boxplot(b, add=TRUE, col=2)
like image 195
csgillespie Avatar answered Oct 27 '22 07:10

csgillespie