1. Learn
  2. /
  3. Courses
  4. /
  5. Reshaping Data with tidyr

Exercise

WHO obesity vs. life expectancy

You've been given a sample of WHO data (who_df) with obesity percentages and life expectancy data per country, year, and sex. You want to visually inspect the correlation between obesity and life expectancy.

However, the data is very messy with four variables hidden in the column names. Each column name is made up of three parts separated by underscores: Values for the year, followed by those for sex, and then values for either pct.obese or life.exp. Since the third part of the column name string holds two variables you'll need to use the special ".value" value in the names_to argument.

You'll pivot the data into a tidy format and create the scatterplot.

The ggplot2 package has been pre-loaded for you.

Instructions 1/2

undefined XP
    1
    2
  • Pivot the data so that each variable (year, sex, pct.obese, life.exp) has a column of the correct data type.