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.
This exercise is part of the course
Reshaping Data with tidyr
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
who_df %>%
# Put each variable in its own column
___(
___,
names_to = ___,
names_sep = "_",
names_transform = ___(___ = ___)
)