-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26b0917
commit 9a43cd9
Showing
106 changed files
with
2,675 additions
and
710 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export("%>%") | ||
export(show_budget_gap) | ||
export(show_contributions) | ||
export(show_donors) | ||
export(show_earmarking) | ||
export(show_expenditure) | ||
export(show_indicators) | ||
export(show_partnership) | ||
export(show_sectors) | ||
export(show_top_donors) | ||
import(dplyr) | ||
import(ggplot2) | ||
import(refugees) | ||
import(scales) | ||
import(tidyselect) | ||
import(unhcrthemes) | ||
importFrom(magrittr,"%>%") | ||
importFrom(stats,reorder) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# WARNING - Generated by {fusen} from dev/dev_unhcr_programme.Rmd: do not edit by hand | ||
|
||
#' show_budget_gap | ||
#' | ||
#' @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. | ||
#' | ||
#' @import ggplot2 | ||
#' @import dplyr | ||
#' @import tidyselect | ||
#' @import scales | ||
#' @import unhcrthemes | ||
#' | ||
#' @export | ||
#' @return a graph | ||
#' @examples | ||
#' show_budget_gap(year = 2018, | ||
#' ctr_name = "Brazil") | ||
show_budget_gap <- function(year, | ||
programme_lab = NULL, | ||
iati_identifier_ops = NULL, | ||
ctr_name = NULL ) { | ||
|
||
|
||
# Check if only one argument is passed | ||
if (!is.null(programme_lab) && !is.null(iati_identifier_ops)) { | ||
stop("Please pass only one of the arguments programme_lab or iati_identifier_ops.") | ||
} else if (!is.null(programme_lab) && !is.null(ctr_name)) { | ||
stop("Please pass only one of the arguments programme_lab or ctr_name.") | ||
} else if (!is.null(iati_identifier_ops) && !is.null(ctr_name)) { | ||
stop("Please pass only one of the arguments iati_identifier_ops or ctr_name.") | ||
} | ||
|
||
df <- iati::dataTransaction |> | ||
dplyr::left_join(iati::dataActivity, by= c("iati_identifier")) | ||
|
||
if (!is.null(programme_lab)) { | ||
thisprogramme_lab <- programme_lab | ||
thisyear <- year | ||
df <- df |> | ||
# levels(as.factor(df$programmme_lab)) | ||
dplyr::filter( programmme_lab == thisprogramme_lab & | ||
year >= thisyear & | ||
transaction_type_name == "Expenditure") | ||
} else if (!is.null(iati_identifier_ops)) { | ||
thisiati_identifier_ops <- iati_identifier_ops | ||
thisyear <- year | ||
df <- df |> | ||
dplyr::filter(iati_identifier_ops == thisiati_identifier_ops & | ||
year >= thisyear & | ||
transaction_type_name == "Expenditure") | ||
} else if (!is.null(ctr_name)) { | ||
thisctr_name <- ctr_name | ||
thisyear <- year | ||
df <- df |> | ||
dplyr::filter( ctr_name == thisctr_name & | ||
year >= thisyear & | ||
transaction_type_name == "Expenditure") | ||
} | ||
|
||
df2 <- df |> | ||
dplyr::group_by(iati_identifier, year) |> | ||
dplyr::summarise(transaction_value= sum(transaction_value, na.rm = TRUE)) |> | ||
dplyr::left_join(iati::dataBudget |> | ||
dplyr::mutate(budget_value= as.numeric(budget_value)) |> | ||
dplyr::group_by(iati_identifier) |> | ||
dplyr::summarise(budget_value= sum(budget_value, na.rm = TRUE)) | ||
, by= c("iati_identifier")) |> | ||
dplyr::select(iati_identifier, year,budget_value, transaction_value ) |> | ||
dplyr::mutate(budget_gap = (budget_value - transaction_value) / budget_value *100) | ||
|
||
|
||
|
||
p <- df2 |> | ||
# dplyr::filter(transaction_value_USD <= 1000000 & transaction_value_USD > 1000) |> | ||
ggplot2::ggplot(ggplot2::aes(x = year, group = 1)) + | ||
ggplot2::geom_line(ggplot2::aes(y = budget_gap, | ||
color = "Budget"), | ||
linewidth = 1.5, | ||
color = "#F592A0") + | ||
ggplot2::scale_y_continuous( | ||
expand = ggplot2::expansion(mult = c(0, .1)), | ||
labels = scales::label_number(scale_cut = scales::cut_short_scale()) ) + | ||
# scale_x_continuous(labels = scales::label_number(scale_cut = cut_short_scale())) + | ||
# ggplot2::facet_wrap(~ trans_year) + | ||
unhcrthemes::theme_unhcr(grid = "Y", axis = "X", | ||
axis_title = "X", font_size = 18, | ||
legend = FALSE)+ | ||
ggplot2::labs( | ||
title = paste0( "Budget Gap (in %)"), | ||
subtitle = paste0("In ", programme_lab, ctr_name,iati_identifier_ops, " recorded since ", year,""), | ||
x = "", | ||
y = "", | ||
caption = "Data Source: UNHCR IATI (International Aid Transparency Initiative)" ) | ||
|
||
return(p) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# WARNING - Generated by {fusen} from dev/dev_unhcr_programme.Rmd: do not edit by hand | ||
|
||
#' Title | ||
#' | ||
#' @description What’s the breakdown by contribution Type (Un-earmarked, Tightly earmarked, etc.) from Donor Funds by Year? | ||
#' | ||
#' @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. | ||
#' | ||
#' @import ggplot2 | ||
#' @import dplyr | ||
#' @import scales | ||
#' @import unhcrthemes | ||
#' | ||
#' @export | ||
#' @return a graph | ||
#' @examples | ||
#' knitr::kable(iati::dataTransaction |> | ||
#' dplyr::select(aid_type1_name, aid_type1_description) |> | ||
#' dplyr::distinct() |> | ||
#' dplyr::filter(!(is.na(aid_type1_name)))) | ||
#' show_contributions(year = 2018, | ||
#' ctr_name = "Brazil") | ||
#' show_contributions(year = 2018, | ||
#' programme_lab = "The Americas") | ||
show_contributions <- function(year, | ||
programme_lab = NULL, | ||
iati_identifier_ops = NULL, | ||
ctr_name = NULL ) { | ||
|
||
|
||
# Check if only one argument is passed | ||
if (!is.null(programme_lab) && !is.null(iati_identifier_ops)) { | ||
stop("Please pass only one of the arguments programme_lab or iati_identifier_ops.") | ||
} else if (!is.null(programme_lab) && !is.null(ctr_name)) { | ||
stop("Please pass only one of the arguments programme_lab or ctr_name.") | ||
} else if (!is.null(iati_identifier_ops) && !is.null(ctr_name)) { | ||
stop("Please pass only one of the arguments iati_identifier_ops or ctr_name.") | ||
} | ||
|
||
df <- iati::dataTransaction |> | ||
dplyr::left_join(iati::dataActivity, by= c("iati_identifier")) | ||
|
||
if (!is.null(programme_lab)) { | ||
thisprogramme_lab <- programme_lab | ||
thisyear <- year | ||
df <- df |> | ||
# levels(as.factor(df$programmme_lab)) | ||
dplyr::filter( programmme_lab == thisprogramme_lab & | ||
year >= thisyear & | ||
transaction_type_name == "Incoming Commitment") | ||
} else if (!is.null(iati_identifier_ops)) { | ||
thisiati_identifier_ops <- iati_identifier_ops | ||
thisyear <- year | ||
df <- df |> | ||
dplyr::filter(iati_identifier_ops == thisiati_identifier_ops & | ||
year >= thisyear & | ||
transaction_type_name == "Incoming Commitment") | ||
} else if (!is.null(ctr_name)) { | ||
thisctr_name <- ctr_name | ||
thisyear <- year | ||
df <- df |> | ||
dplyr::filter( ctr_name == thisctr_name & | ||
year >= thisyear & | ||
transaction_type_name == "Incoming Commitment") | ||
} | ||
|
||
df2 <- df |> | ||
dplyr::group_by(year, aid_type1_name) |> | ||
dplyr::summarise( transaction_value_USD = sum(transaction_value_USD , na.rm = TRUE)) |> | ||
dplyr::mutate(aid_type1_name = as.character(aid_type1_name) ) |> | ||
dplyr::mutate(aid_type1_name = as.factor(aid_type1_name) ) | ||
|
||
p <- df2 |> | ||
# dplyr::filter(transaction_value_USD <= 1000000 & transaction_value_USD > 1000) |> | ||
ggplot2::ggplot(ggplot2::aes(y = transaction_value_USD , | ||
x = year, | ||
fill = aid_type1_name)) + | ||
ggplot2::geom_bar(alpha = 0.9, stat = "identity") + | ||
ggplot2::scale_fill_viridis_d(option = "inferno", na.value = "grey50") + | ||
ggplot2::scale_y_continuous( | ||
expand = ggplot2::expansion(mult = c(0, .1)), | ||
labels = scales::label_number(scale_cut = scales::cut_short_scale()) ) + | ||
# scale_x_continuous(labels = scales::label_number(scale_cut = cut_short_scale())) + | ||
# ggplot2::facet_wrap(~ trans_year) + | ||
unhcrthemes::theme_unhcr(grid = "Y", axis = "X", axis_title = "X", font_size = 18)+ | ||
ggplot2::labs( | ||
title = paste0("Commitment vs Contribution type (in USD)"), | ||
subtitle = paste0("Recorded in ", programme_lab, ctr_name,iati_identifier_ops, " since ", year,""), | ||
x = "", | ||
y = "", | ||
caption = "Data Source: UNHCR IATI (International Aid Transparency Initiative)" ) | ||
|
||
return(p) | ||
} |
Oops, something went wrong.