View Interactive Version
ggplot(___) + geom_col( mapping = aes(x = ___, y = ___, fill = ___) )
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,
y are required for
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.