- Trending Categories
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
Create histogram with horizontal boxplot on top in base R.
To create a histogram with horizontal boxplot on top in base R, we first need to define the layout of the plotting area with layout function and par function margin (mar) then the boxplot will be created and after that the histogram will be created. While creating the boxplot and histogram we need to make sure that the ylim for boxplot and xlim for histogram are same.
Check out the below Example to understand how it can be done.
Example
To create a histogram with horizontal boxplot on top in base R, use the following snippet −
x<-rnorm(100) layout(mat=matrix(c(1,2),2,1,byrow=TRUE),height=c(2,4)) par(mar=c(4,3,1,2)) boxplot(x,horizontal=TRUE,outline=FALSE,ylim=c(-4,4))
Output
If you execute the above given snippet, it generates the following Output −
To create a histogram with horizontal boxplot on top in base R add the following code to the above snippet −
x<-rnorm(100) layout(mat=matrix(c(1,2),2,1,byrow=TRUE),height=c(2,4)) par(mar=c(4,3,1,2)) hist(x,xlim=c(-4,4))
Output
If you execute all the above given snippets as a single program, it generates the following Output −
- Related Articles
- How to create a horizontal boxplot in base R?
- How to create a horizontal line in a histogram in base R?
- How to create horizontal histogram in R?
- How to create boxplot with horizontal lines on the minimum and maximum in R?
- How to add a horizontal line in a boxplot created in base R?
- How to create boxplot for multiple categories with long names in base R?
- How to create a boxplot with log of the variable in base R?
- How to create a histogram with dots instead of bars in base R?
- How to create side-by-side boxplot in base R?
- How to create boxplot for multiple categories in base R?
- How to create boxplot in base R without axes labels?
- How to create a boxplot without frame in base R?
- How to create a rectangle inside boxplot in base R?
- How to create a histogram without bins in base R?
- How to create boxplot in base R with higher width of the box lines?
