Comparing population and GDP per capita
In the video you learned to create a scatter plot with GDP per capita on the x-axis and life expectancy on the y-axis (the code for that graph has been provided in the exercise code). When you're exploring data visually, you'll often need to try different combinations of variables and aesthetics.
This exercise is part of the course
Introduction to the Tidyverse
Exercise instructions
- Change the scatter plot of
gapminder_1952
so that (pop
) is on the x-axis and GDP per capita (gdpPercap
) is 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)
gapminder_1952 <- gapminder %>%
filter(year == 1952)
# Change to put pop on the x-axis and gdpPercap on the y-axis
ggplot(gapminder_1952, aes(x = gdpPercap, y = lifeExp)) +
geom_point()