i

R Programming Complete Tutorial

ggplot2 Histogram

A Histogram represents the frequencies of values of a variable bucketed into ranges. Each Bar in the Histogram represents the height of the number of values present in that range. We can create a Histogram using geom_histogram function.

We are going to create a Histogram using engine displacement. It will display the number of cars with the same displacement.

Suppose we have more than 20 cars with displacement 2. We have filled the graph by class. So, of that 21 cars, 7 are subcompact, 1 is midsize, and others are compact.

Example of Histogram:

Graph Output: