- 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 a step histogram using ggplot2 in R?
To create a step histogram using ggplot2, we can use geom="step" argument inside stat_bin function. For example, if we have a data frame that contains a single column then the step histogram can be created using the command − ggplot(df,aes(x))+stat_bin(geom="step",bins=30)
Example
Consider the below data frame −
set.seed(14) x<−rnorm(20) df<−data.frame(x) df
Output
x 1 −0.66184983 2 1.71895416 3 2.12166699 4 1.49715368 5 −0.03614058 6 1.23194518 7 −0.06488077 8 1.06899373 9 −0.37696531 10 1.04318309 11 −0.38282188 12 0.29942160 13 0.67423976 14 −0.29281632 15 0.48805336 16 0.88280182 17 1.86274898 18 1.61172529 19 0.13547954 20 1.08808601
Loading ggplot2 package and creating the step histogram −
Example
library(ggplot2) ggplot(df,aes(x))+stat_bin(geom="step",bins=30)
Output
- Related Articles
- How to create a transparent histogram using ggplot2 in R?
- How to create histogram with varying binwidth using ggplot2 in R?
- How to create a histogram with Y-axis values as count using ggplot2 in R?
- How to display mean in a histogram using ggplot2 in R?
- How to create a histogram using weights in R?
- How to define the breaks for a histogram using ggplot2 in R?
- How to display the curve on the histogram using ggplot2 in R?
- How to fill histogram bars using ggplot2 in R with different colors?
- How to create a dot plot using ggplot2 in R?
- How to create a transparent polygon using ggplot2 in R?
- How to create horizontal legend using ggplot2 in R?
- How to create facetted histograms using ggplot2 in R?
- How to create horizontal histogram in R?
- How to create a horizontal bar graph using ggplot2 in R?
- How to create a dotchart using ggplot2 without gridlines in R?

Advertisements