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

library(ggplot2)
ggplot(df,aes(x))+stat_bin(geom="step",bins=30)

Output

Updated on: 2026-03-11T23:22:53+05:30

414 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements