library(tidyverse)
library(gapminder)Test
Begin by loading the tidyverse and gapminder packages in the code chunk above and adding your name as the author.
The dplyr Wrangling Penguins tutorial (up through Section 7) and Chapter 5 of Hello Data Science have shown you how to subset your data by rows (filter()) and columns (select()), how to relocate() and rename() columns, and how to redefine or create new columns (mutate()). It’s time to put those tools together to manipulate, and visualize with ggplot, the gapminder data with a series of commands connected with the pipe, |>. Each code chuck below should start with the original gapminder data frame.
Wrangling and Plotting the gapminder Data
Let’s start by making a line plot of lifeExp versus year colored by country for all the countries in Europe. Rename country to europe_country and lifeExp to lifeExp_yrs. Modify this code by filling in the ______ to do so:
gapminder |>
filter(continent == "Europe") |>
rename(
europe_country = country,
lifeExp_yrs = lifeExp
) |>
ggplot(aes(x = year, y = lifeExp_yrs, color = europe_country)) +
geom_line() +
labs(
title = "Life Expectancy by Year in Europe",
x = "Year",
y = "Life Expectancy at Birth (years)",
color = "Country"
)