Skip to content

Commit

Permalink
add RBM mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Edouard-Legoupil committed Feb 22, 2024
1 parent 9a43cd9 commit 72fa9b8
Show file tree
Hide file tree
Showing 55 changed files with 2,149 additions and 125 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ export(show_donors)
export(show_earmarking)
export(show_expenditure)
export(show_indicators)
export(show_indicators_time)
export(show_partnership)
export(show_sectors)
export(show_sectors_rbm)
export(show_top_donors)
import(dplyr)
import(ggplot2)
Expand Down
21 changes: 21 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,30 @@
#'}
"dataRelated_activity"

#### Mapping table #########

#' @title mapping_result
#' @description Mapping Results to UNHCR 2022 RBM Framework
#' @format A data frame with 107 rows and 2 variables:
#' \describe{
#' \item{\code{result_title}}{character result_title}
#' \item{\code{sector_rbm}}{character sector_rbm}
#'}
#' @source \url{https://www.unhcr.org/what-we-do/build-better-futures/compass/}
"mapping_result"


#' @title mapping_sector
#' @description Mapping Sector to UNHCR 2022 RBM Framework
#' @format A data frame with 83 rows and 3 variables:
#' \describe{
#' \item{\code{sector_desc}}{character COLUMN_DESCRIPTION}
#' \item{\code{sector_vocabulary_name}}{character COLUMN_DESCRIPTION}
#' \item{\code{sector_rbm}}{character COLUMN_DESCRIPTION}
#'}
#' @source \url{https://www.unhcr.org/what-we-do/build-better-futures/compass}
"mapping_sector"

#### All code list doc ############


Expand Down
4 changes: 3 additions & 1 deletion R/globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ globalVariables(unique(c(
# show_partnership:
"Accountable",
# show_top_donors:
"transaction_provider_org"
"transaction_provider_org",
# show_sectors_rbm:
"sector_rbm", "sector_vocabulary_name", "year2"
)))
71 changes: 68 additions & 3 deletions R/show_budget_gap.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

#' show_budget_gap
#'
#' UNHCR budgets are needs-based: it represents the total amount
#' of money that would be required were UNHCR to meet all of the needs that it is seeking to address.
#'
#' @param year A numeric value corresponding to the first year of focus until the most recent year within the dataset.
#' @param programme_lab A character vector corresponding to the name of the programme.
#' @param iati_identifier_ops A character vector corresponding to the name of the operation.
#' @param ctr_name A character vector corresponding to the name of the country.
#' @param weight_by list of population group to weight the budget -
#' "refugees", "asylum_seekers",
#' "returned_refugees" "idps",
#' "returned_idps", "stateless",
#' "ooc", "oip"
#' default is null.
#'
#' @import ggplot2
#' @import dplyr
Expand All @@ -18,10 +27,17 @@
#' @examples
#' show_budget_gap(year = 2018,
#' ctr_name = "Brazil")
#'
#'
#'
#' show_budget_gap(year = 2018,
#' ctr_name = "Brazil",
#' weight_by = c("refugees", "oip"))
show_budget_gap <- function(year,
programme_lab = NULL,
iati_identifier_ops = NULL,
ctr_name = NULL ) {
ctr_name = NULL ,
weight_by = NULL ) {


# Check if only one argument is passed
Expand Down Expand Up @@ -72,6 +88,55 @@ show_budget_gap <- function(year,
dplyr::mutate(budget_gap = (budget_value - transaction_value) / budget_value *100)



if ( !is.null(weight_by) && !all(weight_by %in% c("refugees", "asylum_seekers",
"returned_refugees", "idps",
"returned_idps", "stateless",
"ooc", "oip" )) ) {
stop("weight_by is used but the population filter is not correctly set up...\n
it should be among: refugees, asylum_seekers, returned_refugees, idps,
returned_idps, stateless, ooc, oip")
}

## Calculate weight
if (!is.null(weight_by) && !is.null(ctr_name) ) {
ctrstat <- refugees::population |>
dplyr::filter( year>= thisyear &
coa_name == thisctr_name) |>
dplyr::group_by(year, coa_name) |>
dplyr::summarise(refugees = sum(refugees, na.rm = TRUE),
asylum_seekers = sum(asylum_seekers, na.rm = TRUE),
returned_refugees = sum(returned_refugees, na.rm = TRUE),
idps = sum(idps, na.rm = TRUE),
returned_idps = sum(returned_idps , na.rm = TRUE),
stateless = sum(stateless, na.rm = TRUE),
ooc = sum( ooc, na.rm = TRUE),
oip = sum(oip, na.rm = TRUE)) |>
dplyr::select(year, coa_name, all_of(weight_by) ) |>
dplyr::mutate(year = as.factor(year) ) |>
dplyr::mutate( weight = rowSums(
dplyr::across(tidyselect::where(is.numeric))))

df2 <- df2 |>
dplyr::left_join(ctrstat |>
dplyr::select(year, weight) , by = c("year")) |>
dplyr::mutate(budget_value = round(budget_value / weight,1),
transaction_value = round(transaction_value / weight,1))|>
dplyr::mutate(budget_gap = (budget_value - transaction_value) / budget_value *100)

}

subtitt <- if( is.null(weight_by)) {
paste0("In ", programme_lab, ctr_name,iati_identifier_ops, " recorded since ", year,"")
} else {
paste0("Weighted by total number of individual ",
paste(weight_by, collapse = ', '),
" in ",
programme_lab, ctr_name,iati_identifier_ops, " as recorded since ", year,"")
}




p <- df2 |>
# dplyr::filter(transaction_value_USD <= 1000000 & transaction_value_USD > 1000) |>
Expand All @@ -90,10 +155,10 @@ show_budget_gap <- function(year,
legend = FALSE)+
ggplot2::labs(
title = paste0( "Budget Gap (in %)"),
subtitle = paste0("In ", programme_lab, ctr_name,iati_identifier_ops, " recorded since ", year,""),
subtitle = subtitt ,
x = "",
y = "",
caption = "Data Source: UNHCR IATI (International Aid Transparency Initiative)" )
caption = "Data Source: UNHCR IATI (International Aid Transparency Initiative). UNHCR budget is needs-based. It represents the total amount of money that would be required were UNHCR to meet all of the needs that it is seeking to address." )

return(p)

Expand Down
15 changes: 14 additions & 1 deletion R/show_earmarking.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@

#' Title
#'
#' @description What’s the breakdown of Earmarking Type (Un-earmarked, Tightly earmarked, etc.) from Donor Funds by Year?
#' @description What’s the breakdown of Earmarking Type (Un-earmarked, Tightly earmarked, etc.) \
#' from Donor Funds by Year?
#' Where possible, UNHCR prefers to receive unearmarked funds, as this allows the agency
#' greater flexibility in allocating its resources as new needs emerge during the course of the year.
#' Should that not be possible, funds can also be softly earmarked. This could mean funds that
#' can be spent anywhere within a region or for a particular situation (for example, funds that have
#' to be spent to assist refugees from Syria, but which can be spent in any country hosting such
#' refugees). Earmarked funds would be a contribution that corresponds to a specific country but
#' can be spent on anything within that operation’s programme. Finally, tightly earmarked funds
#' are those that specify an activity or a population within a country’s programme.
#'
#' UNHCR charges an ISC - Indirect Support Costs - rate of 6.5% on all of its earmarked contributions.
#' This covers management and administration costs at HQ and programme support costs
#' incurred at HQ and Regional Bureaux.
#'
#' @param year A numeric value corresponding to the first year of focus until the most recent year within the dataset.
#' @param programme_lab A character vector corresponding to the name of the programme.
Expand Down
2 changes: 1 addition & 1 deletion R/show_expenditure.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ show_expenditure <- function(year,
subtitle = subtitt,
x = "",
y = "",
caption = "Data Source: UNHCR IATI (International Aid Transparency Initiative)" )
caption = "Data Source: UNHCR IATI (International Aid Transparency Initiative). UNHCR budget is needs-based. It represents the total amount of money that would be required were UNHCR to meet all of the needs that it is seeking to address." )

return(p)
}
Loading

0 comments on commit 72fa9b8

Please sign in to comment.