---
title: "Visualise age pyramids"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Visualise age pyramiods}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.height = 10,
  fig.width = 10
)
```

```{r}
library(contactdata)
```

In this vignette, we are going to try to visualise the age pyramid for 
9 Western Europe countries. The list of these countries is:

```{r}
countries <- c("Portugal", "Spain", "Italy", "France", "Ireland", "Belgium", "Luxembourg", "Germany", "Switzerland")
```

We can get the contact data for all these countries in a single function call 
with:

```{r}
age_data <- age_df_countries(countries)
```

For the visualisation itself, we use the graphical package ggplot2, which offers
a large flexibility in terms of customisation:

```{r, eval = requireNamespace("ggplot2", quietly = TRUE)}
library(ggplot2)
ggplot(age_data, aes(x = population, y = age)) + 
  geom_bar(stat = "identity") +
  facet_wrap(~ country, scales = "free")
```
