- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create side by side barplot in base R?
If we want to create side by side barplot for two vectors or two columns of same or different data frames then we first need to combine those vectors or columns with the help of cbind function as shown below. After that barplot function will be applied to the combined data and beside argument will be set to TRUE.
Check out the below given example to understand how it works.
Example
To create side by side barplot in base R, use the code given below −
x<-rpois(5,5) x
If you execute the above given code, it generates the following output −
[1] 3 2 8 1 2
To create side by side barplot in base R, add the following code to the above snippet −
y<-rpois(5,20) y
If you execute all the above given snippets as a single program, it generates the following output −
[1] 21 21 16 20 17
To create side by side barplot in base R, add the following code to the above snippet −
x<-rpois(5,5) y<-rpois(5,20) Combined_xy<-cbind(x,y) barplot(Combined_xy,beside=TRUE)
Output
If you execute all the above given snippets as a single program, it generates the following output −