1. Bar plots
The next kind of plot you'll learn to make is a bar plot. Bar plots are useful for comparing values across discrete categories, such as continents.
2. Summarizing by continent
In the last chapter, you learned to calculate summarized values within groups. For example, this code finds the average life expectancy within each continent in the year 2007. That creates a table that looks like this, with one observation for each continent.
Instead of just printing the table, you might want to represent the summary visually. For that, you would use a
3. Bar plot
bar plot. This kind of plot represents the data using one bar for each continent, with the height of the bar representing the mean life expectancy.
To create a bar plot, you use geom underscore col, short for "column". There are two aesthetics in a bar plot. X is the categorical variable: in this case, the continent. Y is the variable that determines the height of the bars: the mean life expectancy. This makes it easy to see which continents have higher life expectancy than others.
Notice that unlike scatter plots or line plots, bar plots always start at zero.
4. Let's practice!
In the exercises, you'll summarize other statistics within each continent, and then use bar plots to compare them visually.