Plotting multiple countries
Plotting just one country at a time is interesting, but you really want to compare trends between countries. For example, suppose you want to compare voting trends for the United States, the UK, France, and India.
You'll have to filter to include all four of these countries and use another aesthetic (not just x- and y-axes) to distinguish the countries on the resulting visualization. Instead, you'll use the color aesthetic to represent different countries.
This exercise is part of the course
Case Study: Exploratory Data Analysis in R
Exercise instructions
The by_year_country
dataset you created in the last exercise is available in your workspace.
- Create a filtered version of
by_year_country
calledfiltered_4_countries
with just the countries listed in the editor (you may find the%in%
operator useful here). - Show the trend for each of these countries on the same graph, using color to distinguish each country.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Vector of four countries to examine
countries <- c("United States", "United Kingdom",
"France", "India")
# Filter by_year_country: filtered_4_countries
# Line plot of % yes in four countries
___(filtered_4_countries, ___) ___
___