## @knitr carica-librerie
# package utilizzati ------------------------------------------------------
library(gapminder)
library(tidyverse)
library(janitor)
library(gt)
library(DT)

## @knitr indicatori-pagina-uno
indicatori_pag1 <- gapminder |> 
  filter(year == 2007) |> 
  group_by(continent) |> 
  summarise(life_exp = mean(lifeExp))

## @knitr tabella-lifeExp
scheda_lifeExp <- gapminder |> 
  group_by(continent, year) |> 
  summarise(life_exp = mean(lifeExp)) |> 
  pivot_wider(id_cols = year, names_from = continent, values_from = life_exp)

## @knitr tabella-GDP
scheda_GDP <- gapminder |> 
  group_by(continent, year) |> 
  summarise(gdpPercap = mean(gdpPercap)) |> 
  pivot_wider(id_cols = year, names_from = continent, values_from = gdpPercap)
gt(scheda_GDP)

## @knitr tabella-pop
scheda_pop <- gapminder |> 
  group_by(continent, year) |> 
  summarise(pop = mean(pop)) |> 
  pivot_wider(id_cols = year, names_from = continent, values_from = pop)
gt(scheda_pop)

## @knitr grafico-lifeExp
gg_lifeExp <- gapminder |> 
  group_by(continent, year) |> 
  summarise(life_exp = mean(lifeExp)) |> 
  ggplot() +
    aes(x = year, y = life_exp) +
    geom_line(aes(color = continent)) +
    theme(legend.position = "top")
gg_lifeExp