# How to create side by side histograms in base R?

R ProgrammingServer Side ProgrammingProgramming

#### Artificial Intelligence : The Future Of Programming

15 Lectures 54 mins

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### C Programming from scratch- Master C Programming

Best Seller

60 Lectures 8 hours

To create side by side histograms in base R, we first need to create a histogram using hist function by defining a larger limit of X-axis with xlim argument. After that we can create another histogram that has the larger mean and smaller standard deviation so that the bars do not clash with each other and add=T argument must also be added inside the second hist function.

## Example

Live Demo

hist(rnorm(5000,mean=5,sd=2.1),col="green",xlim=c(1,20))

## Example

hist(rnorm(5000,mean=15,sd=1.25),col="red",add=T)

## Output

Updated on 07-Dec-2020 06:17:24