### Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

## Histograms

A histogram divides the range of numeric values into bins and displays the number of data values falling within each bin. The width of a bin influences the level of detail:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

# Using the hist function to show Old Faithful's eruption times

hist(faithful$eruptions,

breaks = 20,

xlab = "eruption times (min)",

ylab = "count",

main = "Using hist")

# Old Faithful's waiting time to the next eruption using qplot

qplot(x = waiting,

data = faithful,

binwidth = 3,

main = "Using qplot - Waiting Time to Next Eruption (min)")

# The same histogram but using ggplot this time

ggplot(faithful, aes(x = waiting)) + geom_histogram(binwidth = 1) +

ggtitle("Using ggplot - Waiting Time to Next Eruption (min)")

# Histograms can show density where the height of each bin times its width

# equals the count of samples falling in the bin divided by the total count

ggplot(faithful, aes(x = waiting, y = ..density..)) +

geom_histogram(binwidth = 4) +

ggtitle("Using ggplot to Show Density")

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Suggested playgrounds

Open Source Your Knowledge: become a Contributor and help others learn. Create New Content