Search code examples
rboxplot

Multiple boxplots in one in R


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 ??


Solution

  • 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)