Visualizing median GDP per capita by continent over time
In the last exercise you used a line plot to visualize the increase in median GDP per capita over time. Now you'll examine the change within each continent.
This exercise is part of the course
Introduction to the Tidyverse
Exercise instructions
- Use
group_by()
andsummarize()
to find the median GDP per capita within each year and continent, calling the output columnmedianGdpPercap
. Use the assignment operator<-
to save it to a dataset calledby_year_continent
. - Use the
by_year_continent
dataset to create a line plot showing the change in median GDP per capita over time, with color representing continent. Be sure to useexpand_limits(y = 0)
to include 0 on the y-axis.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
library(gapminder)
library(dplyr)
library(ggplot2)
# Summarize the median gdpPercap by year & continent, save as by_year_continent
# Create a line plot showing the change in medianGdpPercap by continent over time