Faceting by year
All of the graphs in this chapter have been visualizing statistics within one year. Now that you're able to use faceting, however, you can create a graph showing all the country-level data from 1952 to 2007, to understand how global statistics have changed over time.
This exercise is part of the course
Introduction to the Tidyverse
Exercise instructions
- Create a scatter plot of the
gapminder
data: - Put GDP per capita (
gdpPercap
) on the x-axis and life expectancy (lifeExp
) on the y-axis, with continent (continent
) represented by color and population (pop
) represented by size. - Put the x-axis on a log scale
- Facet by the
year
variable
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
library(gapminder)
library(dplyr)
library(ggplot2)
# Scatter plot comparing gdpPercap and lifeExp, with color representing continent
# and size representing population, faceted by year