CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Case Study: Exploratory Data Analysis in R

Afficher le cours

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 called filtered_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.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de 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, ___) ___
  ___
Modifier et exécuter le code