Assigment 7

Author

Christian Tabuku

Load your dataset

# Load libraries and import the dataset
library(ggplot2)
library(readr)
library(tidyr)
library(dplyr)

Attachement du package : 'dplyr'
Les objets suivants sont masqués depuis 'package:stats':

    filter, lag
Les objets suivants sont masqués depuis 'package:base':

    intersect, setdiff, setequal, union
data <- read_csv("life_expectancy.csv")
Rows: 266 Columns: 68
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr  (4): Country Name, Country Code, Indicator Name, Indicator Code
dbl (62): 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, ...
lgl  (2): 2022, 2023

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

You can add options to executable code like this

# Convert the data from wide format to long format
data_long <- pivot_longer(
  data,
  cols = `1960`:`2020`,
  names_to = "Year",
  values_to = "LifeExpectancy"
)
# Select five countries for a clearer comparison
data_subset <- data_long %>%
  filter(`Country Name` %in% c("United States", "China", "India", "France", "Brazil"))
ggplot(data_subset, aes(x = as.numeric(Year), y = LifeExpectancy, color = `Country Name`)) +
  geom_line(linewidth = 1) +
  labs(
    title = "Life Expectancy Over Time",
    subtitle = "Comparison of Selected Countries",
    x = "Year",
    y = "Life Expectancy",
    caption = "Source: DS Labs / World Bank"
  ) +
  theme_minimal()

I used the life expectancy dataset to analyze how life expectancy has changed over time in different countries. I selected five countries: the United States, China, India, France, and Brazil. I created a line graph with year on the x-axis and life expectancy on the y-axis, and used color to distinguish between countries. The graph shows that life expectancy has generally increased over time in all countries, but at different rates. Developed countries like France and the United States started with higher life expectancy, while countries like India and China showed significant improvement over time.