How to create a histogram for uniform data in R?


To create a histogram for uniform data in R, we can simply use hist function but the bars size may vary even if the frequency is same. Therefore, for this purpose, we need to define the breaks as shown in the below example.

Example

To create a histogram for uniform data in R, use the code given below −

hist(1:6)

Output

If you execute the above given code, it generates the following output −

To create a histogram for uniform data in R, use the code given below −

hist(1:8)

Output

If you execute the above given code, it generates the following output −

To create a histogram for uniform data in R, use the code given below −

hist(1:6,breaks=0:6)

Output

If you execute the above given code, it generates the following output −

Updated on: 09-Nov-2021

187 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements