It would be nice to make a simple bar chart showing the number of people in each age group. We will use the ggplot package to do this. Here's what the code looks like:
ggplot(survey, aes(age)) +
geom_bar() + coord_flip()
If you're not familiar with ggplot, this code probably looks a bit confusing. However, you should trust that it will create a bar chart of our age groups. Here's a quick overview of what each command does:
ggplot() initializes a
ggplot object, such as our bar plot. The arguments are the dataset (
aes(), which tells R what coordinates to plot.
geom_bar() specifies that this object is a bar plot.
coord_flip() creates a horizontal bar chart.
To learn more about creating charts in R with
ggplot, check out our Data Visualization 101 course.