- 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
How to create horizontal histogram in R?
Generally, the histogram is a graph that is displayed in vertical form and it helps us to analyze the distribution of a variable, mainly to understand whether the distribution is normal or not. The horizontal histogram can be also created by using coord_flip function of ggplot2 package. Check out the below example to understand how it works.
Example
Consider the below data frame.
> x<-rnorm(10000,5,0.97) > df<-data.frame(x) > head(df,20)
Output
x 1 3.509446 2 5.075813 3 5.242884 4 5.236765 5 5.775746 6 5.331167 7 5.250956 8 5.925262 9 6.102322 10 4.045241 11 4.117635 12 4.137581 13 4.758140 14 5.311225 15 4.354592 16 4.021351 17 5.330966 18 5.376746 19 6.717059 20 5.206282
Loading ggplot2 package and creating histogram of x:
> library(ggplot2) > ggplot(df,aes(x))+geom_histogram(bins=30)
Output
Creating horizontal histogram of x.
> ggplot(df,aes(x))+geom_histogram(bins=30)+coord_flip()
Output:
- Related Articles
- How to create a horizontal line in a histogram in base R?
- Create histogram with horizontal boxplot on top in base R.
- How to create a histogram using weights in R?
- How to create histogram with relative frequency in R?
- How to create a transparent histogram using ggplot2 in R?
- How to create a step histogram using ggplot2 in R?
- How to create a histogram without bins in base R?
- How to create a histogram for uniform data in R?
- How to create horizontal line in xyplot in R?
- How to create a horizontal boxplot in base R?
- How to create horizontal legend using ggplot2 in R?
- How to create histogram with varying binwidth using ggplot2 in R?
- How to create histogram of all columns in an R data frame?
- How to create histogram for discrete column in an R data frame?
- How to create a horizontal bar graph using ggplot2 in R?

Advertisements