Comparing median life expectancy and median GDP per continent in 2007
In these exercises you've generally created plots that show change over time. But as another way of exploring your data visually, you can also use ggplot2 to plot summarized data to compare continents within a single year.
This exercise is part of the course
Introduction to the Tidyverse
Exercise instructions
- Filter the gapminder dataset for the year 2007, then summarize the median GDP per capita and the median life expectancy within each continent, into columns called
medianLifeExp
andmedianGdpPercap
. Save this asby_continent_2007
. - Use the
by_continent_2007
data to create a scatterplot comparing these summary statistics for continents in 2007, putting the median GDP per capita on the x-axis to the median life expectancy on the y-axis. Color the scatter plot bycontinent
. You don't need to addexpand_limits(y = 0)
for this plot.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
library(gapminder)
library(dplyr)
library(ggplot2)
# Summarize the median GDP and median life expectancy per continent in 2007
# Use a scatter plot to compare the median GDP and median life expectancy