Bar charts

Bar charts can be used to compare data across a given x axis. Often the x axis could represent a temporal value such as time, date, and so on. It is useful as a visualization to see how quantities changed along a certain timeline or with respect to the variable in the x axis.

Although they may appear similar to histograms, the main difference in this case is that bar plots can be, and often are, used to represent data beyond simply count information. For instance, if we had to plot the number of convicts per year from the Hartnagel dataset, plotting with a histogram on year will simply yield a count of rows by year. Instead, we can use a bar chart as follows.

The example here uses ggplot2 to display the bar chart:

ggplot(Hartnagel, ...

Get Hands-On Data Science with R now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.