Project Part One

Preparing the Life expectancy data for plotting

  1. I downloaded the Life Expectancy Data from Our World in Data I selected this data because I am interested in life expectancy to see how long I am going to live.

  2. This is the Link to the Data.

  3. The following code chunk loads the package I will use to read in and prepare the data for analysis.

  1. Read the Data in.
life_expectancy_by_country <- read_csv(here::here("_posts/2022-05-09-project-part-one/life-expectancy.csv"))
  1. Use glimpse to see the names and types of columns
glimpse(life_expectancy_by_country)
Rows: 19,028
Columns: 4
$ Entity            <chr> "Afghanistan", "Afghanistan", "Afghanistan…
$ Code              <chr> "AFG", "AFG", "AFG", "AFG", "AFG", "AFG", …
$ Year              <dbl> 1950, 1951, 1952, 1953, 1954, 1955, 1956, …
$ `Life expectancy` <dbl> 27.638, 27.878, 28.361, 28.852, 29.350, 29…
  1. Use output from glimpse (and View) to prepare the data for analysis
regions  <- c("Oceania",
               "International transport",
               "Oceania",
               "Asia (excl. China & India)",
               "China",
               "India",
               "Africa",
               "South America",
               "North America (excl. USA)",
               "United States",
               "Europe (excl. EU-27)",
               "EU-27" )

regional_life_expectancy  <- life_expectancy_by_country  %>% 
  rename(Region = 1, Life_Expectancy = 4)  %>% 
  filter(Year >= 1900, Region %in%  regions)  %>% 
  select(Region, Year, Life_Expectancy)  %>% 
  mutate(Life_Expectancy = Life_Expectancy * 1e-9)

Check that the total for 2019 equals the total in the graph

life_expectancy_by_country  %>% filter(Year == 2019)  %>% 
  summarise(total_emm = sum(`Life expectancy`))
# A tibble: 1 × 1
  total_emm
      <dbl>
1    17941.

Add a Picture

See hoe to chanche the width in the R Markdown Cookbook

Life Expectancy

Write the data to file the project directory

write_csv(life_expectancy_by_country, file="life_expectancy.csv")