knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(unhcrdatapackage)

Templates are re-built notebook that includes all the plotting functions above and are integrated with report parameters. Templates are available both as html report (that can be converted to PDF) and as PowerPoint presentations, all defined from UNHCR standard brand (cf unhcrdown. The templates are available either for countries or regions.

Template

Country Factsheet

## generate for one country
# template_CtryFactsheet(year = 2022, country_asylum_iso3c = "USA",   folder = "Report")

# ## Generate for a specific region
# region <- "Americas"
# year <- 2022
# library(tidyverse)
# ## get all countries with more than 1000 Reported individuals
# ctr <- dplyr::left_join( x= ForcedDisplacementStat::end_year_population_totals_long,
#                                 y= ForcedDisplacementStat::reference,
#                                 by = c("CountryAsylumCode" = "iso_3")) |>
#         filter(Year == year &
#                 UNHCRBureau == region ) |>
#         group_by( CountryAsylumName, CountryAsylumCode   ) |>
#         summarise(Value = sum(Value) ) |>
#         ungroup() |>
#         filter( Value  > 1000 )
# 
# for ( i in (1:nrow(ctr))) {
#     # i <- 1
#     country_asylum_iso3ci = as.character(ctr[i ,2 ])
#     cat(paste0(country_asylum_iso3ci, "\n"))
#     unhcrdatapackage::template_CtryFactsheet(year = 2022, 
#               country_asylum_iso3c = country_asylum_iso3ci,  
#                folder = "Report")  }

Country Presentation

## generate for one country
# unhcrdatapackage::template_CtryPrez(year = 2022, 
#                             country_asylum_iso3c = "CHL",
#                             folder = "Report")

# ## Generate for a specific region
# region <- "Americas"
# year <- 2022
# library(tidyverse)
# ## get all countries with more than 1000 Reported individuals
# ctr <- dplyr::left_join( x= ForcedDisplacementStat::end_year_population_totals_long,
#                                 y= ForcedDisplacementStat::reference,
#                                 by = c("CountryAsylumCode" = "iso_3")) |>
#         filter(Year == year &
#                 UNHCRBureau == region ) |>
#         group_by( CountryAsylumName, CountryAsylumCode   ) |>
#         summarise(Value = sum(Value) ) |>
#         ungroup() |>
#         filter( Value  > 1000 )
# 
# for ( i in (1:nrow(ctr))) {
#     # i <- 1
#     country_asylum_iso3ci = as.character(ctr[i ,2 ])
#     cat(paste0(country_asylum_iso3ci, "\n"))
#     unhcrdatapackage::template_CtryFactsheet(year = 2022, 
#                                 country_asylum_iso3c = country_asylum_iso3ci,
#                                folder = "Report")  }

Country Slides

## generate for one country
# unhcrdatapackage::template_Ctryslides(year = 2022, 
#                             country_asylum_iso3c = "CHL",
#                             folder = "Report")

# ## Generate for a specific region
# region <- "Americas"
# year <- 2022
# library(tidyverse)
# ## get all countries with more than 1000 Reported individuals
# ctr <- dplyr::left_join( x= ForcedDisplacementStat::end_year_population_totals_long,
#                                 y= ForcedDisplacementStat::reference,
#                                 by = c("CountryAsylumCode" = "iso_3")) |>
#         filter(Year == year &
#                 UNHCRBureau == region ) |>
#         group_by( CountryAsylumName, CountryAsylumCode   ) |>
#         summarise(Value = sum(Value) ) |>
#         ungroup() |>
#         filter( Value  > 1000 )
# 
# for ( i in (1:nrow(ctr))) {
#     # i <- 1
#     country_asylum_iso3ci = as.character(ctr[i ,2 ])
#     cat(paste0(country_asylum_iso3ci, "\n"))
#     unhcrdatapackage::template_CtryFactsheet(year = 2022,
#                                 country_asylum_iso3c = country_asylum_iso3ci,
#                                folder = "docs/factsheet")  }

Regional Factsheet

# template_RegFactsheet(year = 2022, 
#                       region = "Europe", lag = 10,  
#                       folder = "Report")

## We can also generate all factsheets in a loop for 2022

# region <-  ForcedDisplacementStat::reference |>
#   dplyr::distinct(UNHCRBureau) |>
#   dplyr::filter(!(is.na(UNHCRBureau))) |>
#   dplyr::pull()
# 
# for( reg in region) {
#   unhcrdatapackage::template_RegFactsheet(year = 2022, 
#                         region = reg, lag = 10, 
#                         folder = "Report")
# }

Regional Presentation

# template_RegPrez(year = 2022, region = "Americas", lag = 10,   folder = "Report")

# # Generate for a specific region
# region <- "Americas"
# year <- 2022
# library(tidyverse)
# ## get all countries with more than 1000 Reported individuals
# ctr <- dplyr::left_join( x= ForcedDisplacementStat::end_year_population_totals_long,
#                                 y= ForcedDisplacementStat::reference,
#                                 by = c("CountryAsylumCode" = "iso_3")) |>
#         filter(Year == year &
#                 UNHCRBureau == region ) |>
#         group_by( CountryAsylumName, CountryAsylumCode   ) |>
#         summarise(Value = sum(Value) ) |>
#         ungroup() |>
#         filter( Value  > 1000 )
# 
#   for ( i in (1:nrow(ctr))) {
#     # i <- 1
#     country_asylum_iso3c = as.character(ctr[i ,2 ])
#     cat(paste0(country_asylum_iso3c, "\n"))
#     unhcrdatapackage::template_CtryPrez(year = 2022, 
#                                   country_asylum_iso3c = country_asylum_iso3c,  
#                                   folder = "Report")
#   }

Utilities

annotate_gadget

A shinyGadget to add annotation to a ggplot2!..

Based on https://github.com/MattCowgill/ggannotate also inspired from https://community.rstudio.com/t/graph-annotator-shiny-contest-submission/104687

Once the button "Position the annotation on the chart" is launched:

# if (interactive())
# thischart <- plot_ctr_population_type_abs(year = 2020,
#                     country_asylum_iso3c = "USA",
#                     top_n_countries = 4,
#                     pop_type = "REF"
#                     )
# annotate_gadget(chart = thischart, viewer=paneViewer())

Refresh package



Edouard-Legoupil/unhcrdatapackage documentation built on Nov. 6, 2023, 6:10 p.m.