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 ??
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With