Creating a simple bar chart

ggplot(___) + 
    mapping = aes(x = ___, y = ___, 
                  fill = ___)
View Interactive Version

In ggplot2, bar charts are created using the geom_col() geometric layer. The geom_col() layer requires the x aesthetic mapping which defines the different bars to be plotted. The height of each bar is defined by the variable specified in the y aesthetic mapping. Both mappings, x and y are required for geom_col().

Let’s create our first bar chart with the gapminder_top5 dataset. It contains population (in millions) and life expectancy data for the biggest countries by population in 2007.

ggplot(gapminder_top5) + 
  geom_col(aes(x = country, y = pop))

We see that the resulting bars are sorted by the country names in alphabetical order by default.

Create your first bar chart