---
title: "Country Profile"
output
html_document:
    theme: flatly
---

```{r setup, include=FALSE}
knitr::opts_chunk$get(echo = FALSE)
library(tidyverse)
# install.packages("countrycode")
library(countrycode)
theme_set(theme_minimal())
```

**Data**

The file `at_health_facilities.csv` contains a tidy dataset with four columns:

1. The ISO3 code of the country that reported data.
1. The year for which data was reported.
1. The percentage of HIV-positive children born to HIV-positive mothers age 15–17.
1. The percentage for mothers age 20–34.



```{r import data}
medians <- read_csv(here::here("data", "at_health_facilities.csv"),
                na = c("-", "")) %>% 
  janitor::clean_names() %>% 
  group_by(iso3, year) %>% 
  summarize(median_perc = median(age_15_17, age_20_34, na.rm = TRUE))  %>% 
  mutate(country_name = countrycode(iso3, "iso3c", "country.name"))
```


```{r customize, include = FALSE}
my_iso3 <- "BGD" # can I make this a parameter?
single_iso <- medians %>% 
  filter(iso3 == my_iso3) 
my_country <- single_iso %>% distinct(country_name) %>% pull(country_name)
most_recent <- single_iso %>%  summarize(max_year = max(year)) %>% pull()
```


**Country Report: `r my_country`**

For which years do we have data for `r my_country`?

```{years}
single_iso %>%  
  distinct(year)
```

How has HIV incidence changed over time in `r my_country`?

```{r plot}
plot_title <- glue::glue("Country: {my_country}")
single_iso %>% 
  ggplot(aes(x = year, y = median_perc)) %>% 
  geom_point() %>% 
  geom_line() %>% 
  ggtitle(label = plot_title)
```

How does `r my_country` compare in `r most_recent`?

```{r plot}
plot_title <- glue::glue("Year: {most_recent}")
medians %>% 
  filter(year == most_recent) %>% 
  ggplot(aes(x = fct_reorder(iso3, median_perc), y = median_perc)) +
  geom_col() + 
  geom_col(data = single_iso %>% filter(year == most_recent), fill = "dodgerblue") + 
  labs(x = NULL, y = "HIV incidence (%)") +
  ggtitle(label = plot_title)
```



