Skip to contents
library(unhcrdatapackage)
#> Warning: replacing previous import 'shinydashboard::dashboardPage' by
#> 'shinydashboardPlus::dashboardPage' when loading 'unhcrdatapackage'
#> Warning: replacing previous import 'shinydashboard::dashboardSidebar' by
#> 'shinydashboardPlus::dashboardSidebar' when loading 'unhcrdatapackage'
#> Warning: replacing previous import 'shinydashboard::box' by
#> 'shinydashboardPlus::box' when loading 'unhcrdatapackage'
#> Warning: replacing previous import 'shinydashboard::dashboardHeader' by
#> 'shinydashboardPlus::dashboardHeader' when loading 'unhcrdatapackage'
#> Warning: replacing previous import 'shinydashboard::taskItem' by
#> 'shinydashboardPlus::taskItem' when loading 'unhcrdatapackage'
#> Warning: replacing previous import 'shinydashboard::notificationItem' by
#> 'shinydashboardPlus::notificationItem' when loading 'unhcrdatapackage'
#> Warning: replacing previous import 'shinydashboard::messageItem' by
#> 'shinydashboardPlus::messageItem' when loading 'unhcrdatapackage'
#> Registered S3 methods overwritten by 'ggalt':
#>   method                  from   
#>   grid.draw.absoluteGrob  ggplot2
#>   grobHeight.absoluteGrob ggplot2
#>   grobWidth.absoluteGrob  ggplot2
#>   grobX.absoluteGrob      ggplot2
#>   grobY.absoluteGrob      ggplot2
#> Warning: replacing previous import 'shinydashboardPlus::box' by
#> 'shinydashboard::box' when loading '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:

  • a window with the chart -

  • click first time to indicate the top-left point to position the infobox

  • ask if an arrow is required - if no - the windows closed and the annotation is added -

  • if yes - click a second time to add the arrow pointer - then window closed and the annotation is added- - a button is added with the option to remove this annotation -

  • user can click the

# 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