Creating a Two-Dimensional Bar Chart

In this section, we'll create a two-dimensional bar chart for the total sales of a company in different months.

Let's begin by following these steps:

  1. Load the data. Add the line require (Lock5Data) into your code. You should have installed this package previously.
  2. Review the data with the glimpse(RetailSales) command.
  3. Plot a graph of Sales versus Month.
Here, Month is a categorical variable, while Sales is a continuous variable of the type <dbl>.
  1. Use ggplot + geom_bar(..) to plot this data, as follows:
ggplot(RetailSales,aes(x=Month,y=Sales)) + geom_bar(stat="identity")

A screenshot of the expected outcome is as follows:

Get Applied Data Visualization with R and ggplot2 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.