---
title: "Life expectancy in one country"
author: "Your name here"
format: html
bibliography: camp.bib
execute:
  message: false
  warning: false
---

<!-- Save this file at the top level of your camp project (next to the .Rproj
     file), with camp.bib right beside it. Then click Render. -->

```{r}
#| label: setup
#| echo: false

# packages
library(tidyverse)
library(gapminder)

# the one country this report is about: change it and render again
my_country = "Colombia"

# keep that country's rows (one row per year)
country_data = gapminder |>
  filter(country == my_country)

# the first and last year we have for it
first_year = country_data |> filter(year == min(year))
last_year  = country_data |> filter(year == max(year))
```

## The question

How much has life expectancy changed in `r my_country`?

## The data

I use the Gapminder data, which has one row per country per year. Data shaped this way is called *tidy* [@wickham2014]. There are `r nrow(country_data)` rows for `r my_country`, from `r first_year$year` to `r last_year$year`.

## What I found

In `r first_year$year`, life expectancy in `r my_country` was `r round(first_year$lifeExp, 1)` years. By `r last_year$year` it was `r round(last_year$lifeExp, 1)` years: a change of `r round(last_year$lifeExp, 1) - round(first_year$lifeExp, 1)` years.

I did not type any of those numbers. R did.

```{r}
#| label: tbl-life
#| echo: false
#| tbl-cap: "Life expectancy and income, every five years."

country_data |>
  select(year, lifeExp, gdpPercap) |>
  knitr::kable(digits = 1, col.names = c("Year", "Life expectancy", "GDP per capita"))
```

```{r}
#| label: fig-life
#| echo: false
#| fig-cap: "Life expectancy over time."

ggplot(country_data, aes(x = year, y = lifeExp)) +
  geom_line() +
  geom_point() +
  labs(x = NULL, y = "Life expectancy (years)") +
  theme_minimal()
```

## References
