diff --git a/DESCRIPTION b/DESCRIPTION index f49e51a..55d15fa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,6 +25,7 @@ Imports: grid, here, knitr, + lubridate, magrittr, patchwork, purrr, diff --git a/NAMESPACE b/NAMESPACE index a9a6b40..21f7d12 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -17,6 +17,7 @@ export(show_sectors) export(show_sectors_rbm) export(show_top_donors) export(show_transaction_flow) +export(template_compare) export(template_prez) import(cowplot) import(dplyr) diff --git a/R/compare_resource_result.R b/R/compare_resource_result.R index e0f5653..c357f84 100644 --- a/R/compare_resource_result.R +++ b/R/compare_resource_result.R @@ -2,9 +2,23 @@ #' compare_resource_result #' -#' @param year A numeric value or a vector of numeric value to filter on year. Note that data pre-2022 are using a different set of indicators +#' @param year A numeric value or a vector of numeric value to filter on year. +#' Note that data pre-2022 are using a different set of indicators #' @param ctr_name A character vector corresponding to the name of the country. #' @param indicator one specific indicators - label +#' +#' @param show_baseline TRUE / FALSE boolean to indicate whether to filter and +#' display records that have a baseline value. +#' This will likely impact the number of clean records +#' that can be plotted... +#' @param show_target TRUE / FALSE boolean to indicate whether to filter and +#' display records that have a target value +#' This will likely impact the number of clean records +#' that can be plotted... +#' +#' @param pop_type default is null - but can be used to filter on population type: +#' "Refugees and Asylum-seekers","IDPs" ,"Stateless Persons" +#' "Others of Concern" ,"Returnees" , "Host Community" #' @param outcome any of: #' "OA1: Access to Territory, Reg. and Documentation", #' "OA2: Status Determination", @@ -39,21 +53,36 @@ #' @return a graph #' @examples #' # See a list of indicators per area of work -#' knitr::kable(iati::mapping_indicator |> -#' janitor::clean_names() |> -#' dplyr::filter( results_level =="Outcome") |> -#' dplyr::select(area_of_work, indicator) ) +#' list_indic <- iati::mapping_indicator |> +#' janitor::clean_names() |> +#' dplyr::filter( results_level =="Outcome") |> +#' dplyr::left_join(iati::mapping_result |> +#' dplyr::select(sector_rbm, area_id) |> +#' dplyr::distinct(), by = c("area_id")) |> +#' dplyr::select(area_id, sector_rbm, indicator) +#' knitr::kable(list_indic) +#' +#' compare_resource_result(year = 2022, +#' show_baseline = TRUE, +#' show_target = TRUE, +#' indicator = "13.2. Proportion of PoC who self-report positive changes in their income compared to previous year.", +#' outcome = "OA8: Well-Being and Basic Needs") #' #' compare_resource_result(year = 2022, -#' indicator = "13.2. Proportion of PoC who self-report positive changes in their income compared to previous year.", -#' outcome = "OA8: Well-Being and Basic Needs") +#' ctr_name = "Costa Rica", +#' indicator = "13.2. Proportion of PoC who self-report positive changes in their income compared to previous year.", +#' outcome = "OA8: Well-Being and Basic Needs") +#' #' #' compare_resource_result(year = 2022, -#' ctr_name = "Costa Rica", -#' indicator = "13.2. Proportion of PoC who self-report positive changes in their income compared to previous year.", -#' outcome = "OA8: Well-Being and Basic Needs") +#' pop_type = "Refugees and Asylum-seekers", +#' indicator = "13.2. Proportion of PoC who self-report positive changes in their income compared to previous year.", +#' outcome = "OA8: Well-Being and Basic Needs") compare_resource_result <- function(year = 2022, ctr_name = NULL, + pop_type = NULL, + show_baseline = FALSE, + show_target = FALSE, indicator, outcome) { @@ -64,7 +93,7 @@ compare_resource_result <- function(year = 2022, thisyear <- year thisoutcome <- outcome thisindicator <- indicator - df <- df |> + df <- df |> # levels(as.factor(df$result_type_name )) dplyr::filter( year %in% thisyear ) |> dplyr::left_join(iati::mapping_result, by= c("result_title")) |> @@ -81,18 +110,16 @@ compare_resource_result <- function(year = 2022, #table(df$result_indicator_ascending, useNA = "ifany") df1 <- df |> - dplyr::select(ctr_name, result_type_name , result_title, sector_rbm, + dplyr::select(unhcr_region, iso3c, ctr_name, + result_type_name , result_title, sector_rbm, indicator_measure_name, result_indicator_title, year, - result_indicator_baseline_value, result_indicator_actual_value, result_indicator_target_value, result_indicator_actual_value_1, - result_indicator_actual_location_ref, result_indicator_actual_dimension_1, - result_indicator_actual_dimension_2, result_indicator_actual_value_2, result_indicator_ascending, @@ -141,21 +168,21 @@ compare_resource_result <- function(year = 2022, progress_baseline < -15 ~ "red", TRUE ~ ""), - gap_green = round( ( threshold_green - actual ) / + gap_green = round( ( actual - threshold_green ) / dplyr::if_else(threshold_green == 0, 1, threshold_green) * dplyr::if_else(threshold_green == 0, 1, 100) ,2 ), gap_green = dplyr::if_else(result_indicator_ascending == 0, gap_green * -1, gap_green), - gap_orange = round( ( threshold_orange - actual ) / + gap_orange = round( ( actual - threshold_orange ) / dplyr::if_else(threshold_orange == 0, 1, threshold_orange) * dplyr::if_else(threshold_orange == 0, 1, 100) ,2 ), gap_orange = dplyr::if_else(result_indicator_ascending == 0, gap_orange * -1, gap_orange), - gap_red = round( ( threshold_red - actual ) / + gap_red = round( ( actual - threshold_red ) / dplyr::if_else(threshold_red == 0, 1, threshold_red) * dplyr::if_else(threshold_red == 0, 1, 100) ,2 ), gap_red = dplyr::if_else(result_indicator_ascending == 0, @@ -172,9 +199,10 @@ compare_resource_result <- function(year = 2022, dplyr::filter(year %in% thisyear & sector_vocabulary_name == "Reporting Organisation 2") |> dplyr::left_join(iati::mapping_sector, by= c("sector_desc")) |> - dplyr::group_by(unhcr_region, iso3c, ctr_name, sector_desc, sector_rbm, year) |> + dplyr::select(ctr_name, sector_code, sector_desc, sector_rbm, year, sector_pct ) |> + dplyr::group_by( ctr_name, sector_desc, sector_rbm, year) |> dplyr::summarise(sector_pct = mean( as.numeric(sector_pct)) ) |> - dplyr::group_by(unhcr_region, iso3c, ctr_name, sector_rbm, year) |> + dplyr::group_by( ctr_name, sector_rbm, year) |> dplyr::summarise(sector_pct = sum(sector_pct, rm.na = TRUE)) |> # dplyr::summarise(sector_pct = sum(sector_pct, na.rm = TRUE)/sum(df$sector_pct, na.rm = TRUE)*100) |> # top_n(5, wt = sector_pct) |> @@ -183,13 +211,28 @@ compare_resource_result <- function(year = 2022, ## Results vs Resource ##### - dfall <- df1 |> + dfall1 <- df1 |> ## Filter out - when no data... dplyr::filter (! (is.na(actual))) |> - dplyr::filter (! (is.na(baseline))) |> - dplyr::filter (! (is.na(target))) |> - dplyr::left_join(dfRes, by = c("ctr_name")) |> - dplyr::filter (! (is.na(sector_pct))) + dplyr::left_join(dfRes, by = c("ctr_name")) + + ## Filters.... + if (! (is.null(pop_type)) ){ + dfall1 <- dfall1 |> + dplyr::filter (result_indicator_actual_value_1 %in% c(pop_type)) } + + if( show_baseline == TRUE){ + dfall1 <- dfall1 |> + dplyr::filter (! (is.na(baseline))) } + + if( show_target == TRUE){ + dfall1 <- dfall1 |> + dplyr::filter (! (is.na(target))) } + + ## Treat case when no corresponding resource allocation + dfall <- dfall1 |> + dplyr::filter (! (is.na(sector_pct))) + ## case there's no data at all if( nrow(dfall) == 0) { @@ -214,9 +257,9 @@ compare_resource_result <- function(year = 2022, if( unique(dfall$result_indicator_ascending) == "0") { threshold = data.frame( indlevel = c("crtical","notcool", "Acceptable"), - #xmin = c(0, 0, 0 ), + xmin = c(0, 0, 0 ), # xmax = c(100, 100, 100 ), - xmin = c(min(dfall$sector_pct)-5, min(dfall$sector_pct)-5, min(dfall$sector_pct)-5 ), + # xmin = c(min(dfall$sector_pct), min(dfall$sector_pct), min(dfall$sector_pct) ), xmax = c(max(dfall$sector_pct)+5, max(dfall$sector_pct)+5, max(dfall$sector_pct)+5 ), ymin = c( 0, maxgreen , maxorange ), # ymax = c( maxgreen , maxorange, maxred ) # @@ -225,7 +268,8 @@ compare_resource_result <- function(year = 2022, } else if ( unique(dfall$result_indicator_ascending) == "1") { threshold = data.frame( indlevel = c("crtical","notcool", "Acceptable"), - xmin = c(min(dfall$sector_pct)-5, min(dfall$sector_pct)-5, min(dfall$sector_pct)-5 ), + xmin = c(0, 0, 0 ), + # xmin = c(min(dfall$sector_pct), min(dfall$sector_pct), min(dfall$sector_pct) ), xmax = c(max(dfall$sector_pct)+5, max(dfall$sector_pct)+5, max(dfall$sector_pct)+5 ), ymin = c( 0, maxred, maxorange ), ymax = c( maxred, maxorange, maxgreen ) @@ -234,6 +278,16 @@ compare_resource_result <- function(year = 2022, ## now do some check in case, we need to focus on a specific country if (is.null(ctr_name) ){ + # https://dataviz.unhcr.org/assets/download/UNHCR_Data_Visualization_Guidelines.pdf + palette_unhcr_region <- c( "Asia and the Pacific"= "#00B398", + "East and Horn of Africa" = "#0072BC", + "Europe"="#E1CC0D", + "Middle East and North Africa"="#EF4A60", + "Southern Africa" = "#589BE5" , + "The Americas" = "#18375F", + "West and Central Africa"="#8EBEFF" ) + + interpretation <- "Indicator Value Interpretation: circle=Actual Reported Value, color=Standard Acceptability Threshold" ## and now the plot without country focus p <- ggplot2::ggplot( dfall, ggplot2::aes( x = sector_pct)) + @@ -249,25 +303,48 @@ compare_resource_result <- function(year = 2022, limits = force, na.value = "grey50") + ggplot2::facet_wrap( ggplot2::vars(result_indicator_actual_value_1), - labeller = ggplot2::labeller(result_indicator_actual_value_1 = ggplot2::label_wrap_gen(20))) + + labeller = ggplot2::labeller(result_indicator_actual_value_1 = ggplot2::label_wrap_gen(20))) + # ggplot2::geom_smooth(ggplot2::aes(y = actual), method = "loess", span = 0.05, alpha =0.25) + + #ggplot2::geom_smooth(method="auto", se=TRUE, fullrange=FALSE, level=0.95) + + + if( show_target == TRUE & show_baseline == TRUE){ + p <- p + ggplot2::geom_segment(ggplot2::aes(x = sector_pct, y = baseline, xend = sector_pct, yend = target), - color = "black") + - # ggplot2::geom_smooth(ggplot2::aes(y = actual), method = "loess", span = 0.05, alpha =0.25) + - #ggplot2::geom_smooth(method="auto", se=TRUE, fullrange=FALSE, level=0.95) + - ggplot2::geom_point( ggplot2::aes(y = baseline), size = 1.5, shape = 22, fill = "black") + - ggplot2::geom_point( ggplot2::aes(y = actual), - size = 3.5, shape = 21, fill = "blue", alpha =0.5) + - ggplot2::geom_point( ggplot2::aes(y = target), size = 1.5 , shape = 24, fill = "black") + + color = "black") + interpretation <- "Indicator Value Interpretation: circle=Actual Reported Value, square=baseline, triangle=Target, color=Standard Acceptability Threshold" + } + + if( show_baseline == TRUE){ + p <- p + + ggplot2::geom_point( ggplot2::aes(y = baseline), size = 1.5, shape = 22, fill = "black") + interpretation <- "Indicator Value Interpretation: circle=Actual Reported Value, square=baseline, color=Standard Acceptability Threshold" + } + if( show_target == TRUE){ + p <- p + + ggplot2::geom_point( ggplot2::aes(y = target), size = 1.5 , shape = 24, fill = "black") + interpretation <- "Indicator Value Interpretation: circle=Actual Reported Value,triangle=Target, color=Standard Acceptability Threshold"} + + + + p <- p + + ggplot2::geom_point( ggplot2::aes(y = actual ), + size = 3.5, shape = 21, fill = "blue", alpha =0.7) + + # ggplot2::geom_point( ggplot2::aes(y = actual, color = unhcr_region), + # size = 3.5, shape = 21, alpha =0.5) + ggrepel::geom_label_repel(ggplot2::aes(y = actual, - label = iso3c), + label = iso3c, + color = unhcr_region), size = 3 ) + - ggplot2::guides(color = "none") + + ggplot2::scale_color_manual(values = palette_unhcr_region, + drop = TRUE, + limits = force, + na.value = "grey50") + + ggplot2::guides(color = "none", fill = "none") + ggplot2::scale_x_continuous( label = scales::label_number(accuracy = 1, - scale_cut = scales::cut_short_scale(), - suffix = "%") ) + + scale_cut = scales::cut_short_scale()) ) + ggplot2::scale_y_continuous( label = scales::label_number(accuracy = 1, scale_cut = scales::cut_short_scale())) + unhcrthemes::theme_unhcr(font_size = 14, @@ -277,15 +354,29 @@ compare_resource_result <- function(year = 2022, ggplot2::theme( legend.direction = "horizontal", legend.box = "horizontal", legend.position = "bottom") + - ggplot2::labs( y = "Value: square=baseline, circle=Actual, triangle=Target, color=Standard Acceptability Threshold ", + ## Add correlation + # ggplot2::annotate("text", + # x = max(dfall$sector_pct), + # y = max(dfall$actual), + # label = paste("Correlation [-1, 1] = ", + # round(cor(dfall$sector_pct, dfall$actual, method = "pearson"),2)), + # color = "gray95", + # hjust = 0, + # vjust = 1) + + ggplot2::labs( y = "Indicator Value ", x = "% of resource allocation (expenditure) spent on this outcome" , - title = "Results by Indicator vs Resources by Outcome", + title = paste0("Results by Indicator vs Resources by Outcome |", year) , subtitle = stringr::str_wrap( paste0( "\n Indicators: ", indicator, - "-/- Outcome: ", outcome ) , + " -/- Outcome: ", outcome, + " ---> Correlation [-1, 1] = ", + round(cor(dfall$sector_pct, dfall$actual, method = "pearson"),2) + ) , 100) , - caption = stringr::str_wrap( + caption = stringr::str_wrap( paste0( "Source: Data published by UNHCR as part of the International Aid Transparency Initiative (IATI))" , + ". ---> ", + interpretation), 110) ) } else { ## Treat the case where we would light to highlight a specific country... @@ -351,7 +442,7 @@ compare_resource_result <- function(year = 2022, legend.position = "bottom") + ggplot2::labs( y = "Value: square=baseline, circle=Actual, triangle=Target, color=Standard Acceptability Threshold ", x = "% of resource allocation (expenditure) spent on this outcome" , - title = "Results by Indicator vs Resources by Outcome", + title = paste0("Results by Indicator vs Resources by Outcome |", year) , subtitle = stringr::str_wrap( paste0( "\n Indicators: ", indicator, "-/- Outcome: ", outcome ) , diff --git a/R/globals.R b/R/globals.R index 4257aea..e844dc2 100644 --- a/R/globals.R +++ b/R/globals.R @@ -44,5 +44,14 @@ globalVariables(unique(c( # show_expenditure: "commitment", "expenditure", # show_outcome_result: - "transaction_value2" -))) \ No newline at end of file + "transaction_value2",# compare_resource_result: + "indlevel", "iso3c", "result_indicator_actual_dimension_1", "result_indicator_actual_dimension_2", "result_indicator_actual_location_ref", "result_indicator_actual_value_1", "result_indicator_actual_value_2", "sector_code", "unhcr_region", "xmax", "xmin", "ymax", "ymin", + # show_indicators: + "result_indicator_actual_dimension_1", "result_indicator_actual_dimension_2", "result_indicator_actual_location_ref", "result_indicator_actual_value_1", "result_indicator_actual_value_2", + # show_indicators_time: + "result_indicator_actual_dimension_1", "result_indicator_actual_dimension_2", "result_indicator_actual_location_ref", "result_indicator_actual_value_1", "result_indicator_actual_value_2", + # show_outcome_result: + "result_indicator_actual_dimension_1", "result_indicator_actual_dimension_2", "result_indicator_actual_location_ref", "result_indicator_actual_value_1", "result_indicator_actual_value_2", + # show_transaction_flow: + "Earmarking", "Provider", "Type", "value", "Year" +))) \ No newline at end of file diff --git a/R/show_expenditure.R b/R/show_expenditure.R index 242fb06..a3ecdd6 100644 --- a/R/show_expenditure.R +++ b/R/show_expenditure.R @@ -57,7 +57,9 @@ show_expenditure <- function(year, dplyr::left_join(iati::dataActivity, by= c("iati_identifier")) dfB <- iati::dataBudget |> - dplyr::left_join(iati::dataActivity, by= c("iati_identifier")) + dplyr::left_join(iati::dataActivity, by= c("iati_identifier")) |> + dplyr::rename("year_iati" = "year")|> + dplyr::mutate(year = lubridate::year(lubridate::as_date(budget_period_start))) if (!is.null(programme_lab)) { thisprogramme_lab <- programme_lab @@ -129,7 +131,7 @@ show_expenditure <- function(year, df2 <- df1 |> dplyr::left_join(df |> dplyr::select(- year), by = c("iati_identifier")) |> dplyr::left_join( dfB , by= c("iati_identifier")) |> - dplyr::select(iati_identifier, year, budget_value, expenditure, commitment ) + dplyr::select(iati_identifier, year, budget_value, expenditure, commitment ) # Error catching -- Check if we weight #weight_by <- c("refugees", "oip") diff --git a/R/show_indicators.R b/R/show_indicators.R index 2e6bcaa..1a5d3cf 100644 --- a/R/show_indicators.R +++ b/R/show_indicators.R @@ -198,21 +198,21 @@ show_indicators <- function(year, progress_baseline < -15 ~ "red", TRUE ~ ""), - gap_green = round( ( threshold_green - actual ) / + gap_green = round( ( actual - threshold_green ) / dplyr::if_else(threshold_green == 0, 1, threshold_green) * dplyr::if_else(threshold_green == 0, 1, 100) ,2 ), gap_green = dplyr::if_else(result_indicator_ascending == 0, gap_green * -1, gap_green), - gap_orange = round( ( threshold_orange - actual ) / + gap_orange = round( ( actual - threshold_orange ) / dplyr::if_else(threshold_orange == 0, 1, threshold_orange) * dplyr::if_else(threshold_orange == 0, 1, 100) ,2 ), gap_orange = dplyr::if_else(result_indicator_ascending == 0, gap_orange * -1, gap_orange), - gap_red = round( ( threshold_red - actual ) / + gap_red = round( ( actual - threshold_red ) / dplyr::if_else(threshold_red == 0, 1, threshold_red) * dplyr::if_else(threshold_red == 0, 1, 100) ,2 ), gap_red = dplyr::if_else(result_indicator_ascending == 0, diff --git a/R/show_indicators_time.R b/R/show_indicators_time.R index db4f057..3ae1546 100644 --- a/R/show_indicators_time.R +++ b/R/show_indicators_time.R @@ -203,21 +203,21 @@ show_indicators_time <- function(year, progress_baseline < -15 ~ "red", TRUE ~ ""), - gap_green = round( ( threshold_green - actual ) / + gap_green = round( ( actual - threshold_green ) / dplyr::if_else(threshold_green == 0, 1, threshold_green) * dplyr::if_else(threshold_green == 0, 1, 100) ,2 ), gap_green = dplyr::if_else(result_indicator_ascending == 0, gap_green * -1, gap_green), - gap_orange = round( ( threshold_orange - actual ) / + gap_orange = round( ( actual - threshold_orange ) / dplyr::if_else(threshold_orange == 0, 1, threshold_orange) * dplyr::if_else(threshold_orange == 0, 1, 100) ,2 ), gap_orange = dplyr::if_else(result_indicator_ascending == 0, gap_orange * -1, gap_orange), - gap_red = round( ( threshold_red - actual ) / + gap_red = round( ( actual - threshold_red ) / dplyr::if_else(threshold_red == 0, 1, threshold_red) * dplyr::if_else(threshold_red == 0, 1, 100) ,2 ), gap_red = dplyr::if_else(result_indicator_ascending == 0, diff --git a/R/show_outcome_result.R b/R/show_outcome_result.R index a2805d7..e92e436 100644 --- a/R/show_outcome_result.R +++ b/R/show_outcome_result.R @@ -180,21 +180,21 @@ show_outcome_result <- function(year, progress_baseline < -15 ~ "red", TRUE ~ ""), - gap_green = round( ( threshold_green - actual ) / + gap_green = round( ( actual - threshold_green ) / dplyr::if_else(threshold_green == 0, 1, threshold_green) * dplyr::if_else(threshold_green == 0, 1, 100) ,2 ), gap_green = dplyr::if_else(result_indicator_ascending == 0, gap_green * -1, gap_green), - gap_orange = round( ( threshold_orange - actual ) / + gap_orange = round( ( actual - threshold_orange ) / dplyr::if_else(threshold_orange == 0, 1, threshold_orange) * dplyr::if_else(threshold_orange == 0, 1, 100) ,2 ), gap_orange = dplyr::if_else(result_indicator_ascending == 0, gap_orange * -1, gap_orange), - gap_red = round( ( threshold_red - actual ) / + gap_red = round( ( actual - threshold_red ) / dplyr::if_else(threshold_red == 0, 1, threshold_red) * dplyr::if_else(threshold_red == 0, 1, 100) ,2 ), gap_red = dplyr::if_else(result_indicator_ascending == 0, diff --git a/R/template_compare.R b/R/template_compare.R new file mode 100644 index 0000000..50e80cf --- /dev/null +++ b/R/template_compare.R @@ -0,0 +1,44 @@ +# WARNING - Generated by {fusen} from dev/dev_unhcr_programme.Rmd: do not edit by hand + + +# usethis::use_rmarkdown_template( +# template_name = "iati_compare", +# template_dir = NULL, +# template_description = "Compare", +# template_create_dir = TRUE +# ) + + +#' Generate a summary powerpoint +#' +#' @param year A numeric value or a vector of numeric value to filter on year. Note that data pre-2022 are using a different set of indicators +#' @param ctr_name A character vector corresponding to the name of the country. +#' @param folder folder within your project where to put the generated report. +#' Folder will be created if it does not exist +#' +#' @importFrom unhcrdown pptx_slides +#' @importFrom dplyr filter select pull +#' @importFrom rmarkdown render +#' @importFrom here here +#' @importFrom countrycode countrycode +#' @importFrom stringr str_replace_all +#' +#' @return nothing the file for the report is generated +#' +#' @export +#' +#' @examples +#' # iati::template_compare(year = 2022, folder = "dev/Result") +template_compare <- function(year = 2022, + folder = "Compare") { + + ## Create the outfolder if it does not exist + output_dir <- paste0(getwd(),"/",folder) + if (!dir.exists(output_dir)) {dir.create(output_dir)} + + rmarkdown::render( + system.file("rmarkdown/templates/iati_compare/skeleton/skeleton.Rmd", package = "iati"), + output_file = here::here(folder, paste0('Result_Resource', + '-', year, '.pptx') ), + params = list(year = year) ) +} diff --git a/R/template_prez.R b/R/template_prez.R index 1f7594d..18d08fc 100644 --- a/R/template_prez.R +++ b/R/template_prez.R @@ -35,19 +35,31 @@ #' # folder = "dev/Prez") #' #' # ## Generate for all operation specific region -#' # region <- "The Americas" +#' # reg <- iati::dataActivity |> +#' # dplyr::select( unhcr_region) |> +#' # dplyr::filter(! is.na(unhcr_region)) |> +#' # dplyr::distinct() |> +#' # dplyr::pull() #' # -#' # countries <- iati::dataActivity |> -#' # dplyr::filter( unhcr_region == region) |> -#' # dplyr::select(ctr_name) |> -#' # dplyr::distinct() |> -#' # dplyr::pull() +#' # thisfolder <- "dev/SMR" #' # -#' # for ( ctr in countries) { -#' # cat(paste0(ctr, "\n")) -#' # iati::template_prez(year = 2022, -#' # ctr_name = ctr, -#' # folder = "dev/Prez") } +#' # for (region in reg) { +#' # cat(paste0( region, "\n")) +#' # +#' # # region <- "The Americas" +#' # countries <- iati::dataActivity |> +#' # dplyr::filter( unhcr_region == region) |> +#' # dplyr::select(ctr_name) |> +#' # dplyr::distinct() |> +#' # dplyr::pull() +#' # +#' # for ( ctr in countries) { +#' # cat(paste0("Generating for ", ctr, "\n")) +#' # iati::template_prez(year = 2022, +#' # ctr_name = ctr, +#' # folder = thisfolder) +#' # } +#' # } template_prez <- function(year = 2022, ctr_name, folder = "Prez") { diff --git a/data-raw/build.R b/data-raw/build.R index 80b2645..dda9ffd 100644 --- a/data-raw/build.R +++ b/data-raw/build.R @@ -509,6 +509,47 @@ save(dataTransaction, file = "data/dataTransaction.RData") #by using R CMD build --resave-data tools::resaveRdaFiles(here::here("data","dataTransaction.RData"),compress="xz") + + +### Mapping #### +# mapping_result <- readxl::read_excel("data-raw/mapping/mapping.xlsx", +# sheet = "result_list") |> +# dplyr::mutate( sector_rbm = result_map2) |> +# dplyr::select( result_title, sector_rbm, area_id ) +# +# sinew::makeOxygen(mapping_result, add_fields = "source") +# +# save(mapping_result, file = "data/mapping_result.RData") +# dput(names(mapping_result)) +# +# +# +# mapping_sector <- readxl::read_excel("data-raw/mapping/mapping.xlsx", +# sheet = "result_sector") |> +# dplyr::mutate( sector_rbm = result_map2...7, +# sector_vocabulary_name = sector_vocabulary_name...2) |> +# dplyr::select( sector_desc,sector_vocabulary_name, sector_rbm, area_id ) +# +# sinew::makeOxygen(mapping_sector , add_fields = "source") +# +# save(mapping_sector , file = "data/mapping_sector.RData") +# dput(names(mapping_result)) +# +# dput(names(mapping_sector)) +# +# mapping_sdg <- readxl::read_excel("data-raw/mapping/mapping.xlsx", +# sheet = "area_sdg") +# sinew::makeOxygen(mapping_sdg , add_fields = "source") +# +# save(mapping_sdg , file = "data/mapping_sdg.RData") +# +# +# mapping_indicator <- readxl::read_excel("data-raw/mapping/mapping.xlsx", +# sheet = "mapping_indicator") +# sinew::makeOxygen(mapping_indicator, add_fields = "source") +# +# save(mapping_indicator , file = "data/mapping_indicator.RData") + ## code table need to change name... # diff --git a/data/mapping_sector.RData b/data/mapping_sector.RData index f2a0c1a..68ef9e9 100644 Binary files a/data/mapping_sector.RData and b/data/mapping_sector.RData differ diff --git a/dev/dev_unhcr_programme.Rmd b/dev/dev_unhcr_programme.Rmd index 2c776d3..da22f88 100644 --- a/dev/dev_unhcr_programme.Rmd +++ b/dev/dev_unhcr_programme.Rmd @@ -183,21 +183,21 @@ show_indicators <- function(year, progress_baseline < -15 ~ "red", TRUE ~ ""), - gap_green = round( ( threshold_green - actual ) / + gap_green = round( ( actual - threshold_green ) / dplyr::if_else(threshold_green == 0, 1, threshold_green) * dplyr::if_else(threshold_green == 0, 1, 100) ,2 ), gap_green = dplyr::if_else(result_indicator_ascending == 0, gap_green * -1, gap_green), - gap_orange = round( ( threshold_orange - actual ) / + gap_orange = round( ( actual - threshold_orange ) / dplyr::if_else(threshold_orange == 0, 1, threshold_orange) * dplyr::if_else(threshold_orange == 0, 1, 100) ,2 ), gap_orange = dplyr::if_else(result_indicator_ascending == 0, gap_orange * -1, gap_orange), - gap_red = round( ( threshold_red - actual ) / + gap_red = round( ( actual - threshold_red ) / dplyr::if_else(threshold_red == 0, 1, threshold_red) * dplyr::if_else(threshold_red == 0, 1, 100) ,2 ), gap_red = dplyr::if_else(result_indicator_ascending == 0, @@ -698,21 +698,21 @@ show_indicators_time <- function(year, progress_baseline < -15 ~ "red", TRUE ~ ""), - gap_green = round( ( threshold_green - actual ) / + gap_green = round( ( actual - threshold_green ) / dplyr::if_else(threshold_green == 0, 1, threshold_green) * dplyr::if_else(threshold_green == 0, 1, 100) ,2 ), gap_green = dplyr::if_else(result_indicator_ascending == 0, gap_green * -1, gap_green), - gap_orange = round( ( threshold_orange - actual ) / + gap_orange = round( ( actual - threshold_orange ) / dplyr::if_else(threshold_orange == 0, 1, threshold_orange) * dplyr::if_else(threshold_orange == 0, 1, 100) ,2 ), gap_orange = dplyr::if_else(result_indicator_ascending == 0, gap_orange * -1, gap_orange), - gap_red = round( ( threshold_red - actual ) / + gap_red = round( ( actual - threshold_red ) / dplyr::if_else(threshold_red == 0, 1, threshold_red) * dplyr::if_else(threshold_red == 0, 1, 100) ,2 ), gap_red = dplyr::if_else(result_indicator_ascending == 0, @@ -1726,21 +1726,21 @@ show_outcome_result <- function(year, progress_baseline < -15 ~ "red", TRUE ~ ""), - gap_green = round( ( threshold_green - actual ) / + gap_green = round( ( actual - threshold_green ) / dplyr::if_else(threshold_green == 0, 1, threshold_green) * dplyr::if_else(threshold_green == 0, 1, 100) ,2 ), gap_green = dplyr::if_else(result_indicator_ascending == 0, gap_green * -1, gap_green), - gap_orange = round( ( threshold_orange - actual ) / + gap_orange = round( ( actual - threshold_orange ) / dplyr::if_else(threshold_orange == 0, 1, threshold_orange) * dplyr::if_else(threshold_orange == 0, 1, 100) ,2 ), gap_orange = dplyr::if_else(result_indicator_ascending == 0, gap_orange * -1, gap_orange), - gap_red = round( ( threshold_red - actual ) / + gap_red = round( ( actual - threshold_red ) / dplyr::if_else(threshold_red == 0, 1, threshold_red) * dplyr::if_else(threshold_red == 0, 1, 100) ,2 ), gap_red = dplyr::if_else(result_indicator_ascending == 0, @@ -2178,9 +2178,23 @@ test_that("show_outcome_result works", { ```{r function-compare_resource_result} #' compare_resource_result #' -#' @param year A numeric value or a vector of numeric value to filter on year. Note that data pre-2022 are using a different set of indicators +#' @param year A numeric value or a vector of numeric value to filter on year. +#' Note that data pre-2022 are using a different set of indicators #' @param ctr_name A character vector corresponding to the name of the country. #' @param indicator one specific indicators - label +#' +#' @param show_baseline TRUE / FALSE boolean to indicate whether to filter and +#' display records that have a baseline value. +#' This will likely impact the number of clean records +#' that can be plotted... +#' @param show_target TRUE / FALSE boolean to indicate whether to filter and +#' display records that have a target value +#' This will likely impact the number of clean records +#' that can be plotted... +#' +#' @param pop_type default is null - but can be used to filter on population type: +#' "Refugees and Asylum-seekers","IDPs" ,"Stateless Persons" +#' "Others of Concern" ,"Returnees" , "Host Community" #' @param outcome any of: #' "OA1: Access to Territory, Reg. and Documentation", #' "OA2: Status Determination", @@ -2215,6 +2229,9 @@ test_that("show_outcome_result works", { #' @return a graph compare_resource_result <- function(year = 2022, ctr_name = NULL, + pop_type = NULL, + show_baseline = FALSE, + show_target = FALSE, indicator, outcome) { @@ -2225,7 +2242,7 @@ compare_resource_result <- function(year = 2022, thisyear <- year thisoutcome <- outcome thisindicator <- indicator - df <- df |> + df <- df |> # levels(as.factor(df$result_type_name )) dplyr::filter( year %in% thisyear ) |> dplyr::left_join(iati::mapping_result, by= c("result_title")) |> @@ -2242,18 +2259,16 @@ compare_resource_result <- function(year = 2022, #table(df$result_indicator_ascending, useNA = "ifany") df1 <- df |> - dplyr::select(ctr_name, result_type_name , result_title, sector_rbm, + dplyr::select(unhcr_region, iso3c, ctr_name, + result_type_name , result_title, sector_rbm, indicator_measure_name, result_indicator_title, year, - result_indicator_baseline_value, result_indicator_actual_value, result_indicator_target_value, result_indicator_actual_value_1, - result_indicator_actual_location_ref, result_indicator_actual_dimension_1, - result_indicator_actual_dimension_2, result_indicator_actual_value_2, result_indicator_ascending, @@ -2302,21 +2317,21 @@ compare_resource_result <- function(year = 2022, progress_baseline < -15 ~ "red", TRUE ~ ""), - gap_green = round( ( threshold_green - actual ) / + gap_green = round( ( actual - threshold_green ) / dplyr::if_else(threshold_green == 0, 1, threshold_green) * dplyr::if_else(threshold_green == 0, 1, 100) ,2 ), gap_green = dplyr::if_else(result_indicator_ascending == 0, gap_green * -1, gap_green), - gap_orange = round( ( threshold_orange - actual ) / + gap_orange = round( ( actual - threshold_orange ) / dplyr::if_else(threshold_orange == 0, 1, threshold_orange) * dplyr::if_else(threshold_orange == 0, 1, 100) ,2 ), gap_orange = dplyr::if_else(result_indicator_ascending == 0, gap_orange * -1, gap_orange), - gap_red = round( ( threshold_red - actual ) / + gap_red = round( ( actual - threshold_red ) / dplyr::if_else(threshold_red == 0, 1, threshold_red) * dplyr::if_else(threshold_red == 0, 1, 100) ,2 ), gap_red = dplyr::if_else(result_indicator_ascending == 0, @@ -2333,9 +2348,10 @@ compare_resource_result <- function(year = 2022, dplyr::filter(year %in% thisyear & sector_vocabulary_name == "Reporting Organisation 2") |> dplyr::left_join(iati::mapping_sector, by= c("sector_desc")) |> - dplyr::group_by(unhcr_region, iso3c, ctr_name, sector_desc, sector_rbm, year) |> + dplyr::select(ctr_name, sector_code, sector_desc, sector_rbm, year, sector_pct ) |> + dplyr::group_by( ctr_name, sector_desc, sector_rbm, year) |> dplyr::summarise(sector_pct = mean( as.numeric(sector_pct)) ) |> - dplyr::group_by(unhcr_region, iso3c, ctr_name, sector_rbm, year) |> + dplyr::group_by( ctr_name, sector_rbm, year) |> dplyr::summarise(sector_pct = sum(sector_pct, rm.na = TRUE)) |> # dplyr::summarise(sector_pct = sum(sector_pct, na.rm = TRUE)/sum(df$sector_pct, na.rm = TRUE)*100) |> # top_n(5, wt = sector_pct) |> @@ -2344,13 +2360,28 @@ compare_resource_result <- function(year = 2022, ## Results vs Resource ##### - dfall <- df1 |> + dfall1 <- df1 |> ## Filter out - when no data... dplyr::filter (! (is.na(actual))) |> - dplyr::filter (! (is.na(baseline))) |> - dplyr::filter (! (is.na(target))) |> - dplyr::left_join(dfRes, by = c("ctr_name")) |> - dplyr::filter (! (is.na(sector_pct))) + dplyr::left_join(dfRes, by = c("ctr_name")) + + ## Filters.... + if (! (is.null(pop_type)) ){ + dfall1 <- dfall1 |> + dplyr::filter (result_indicator_actual_value_1 %in% c(pop_type)) } + + if( show_baseline == TRUE){ + dfall1 <- dfall1 |> + dplyr::filter (! (is.na(baseline))) } + + if( show_target == TRUE){ + dfall1 <- dfall1 |> + dplyr::filter (! (is.na(target))) } + + ## Treat case when no corresponding resource allocation + dfall <- dfall1 |> + dplyr::filter (! (is.na(sector_pct))) + ## case there's no data at all if( nrow(dfall) == 0) { @@ -2375,9 +2406,9 @@ compare_resource_result <- function(year = 2022, if( unique(dfall$result_indicator_ascending) == "0") { threshold = data.frame( indlevel = c("crtical","notcool", "Acceptable"), - #xmin = c(0, 0, 0 ), + xmin = c(0, 0, 0 ), # xmax = c(100, 100, 100 ), - xmin = c(min(dfall$sector_pct)-5, min(dfall$sector_pct)-5, min(dfall$sector_pct)-5 ), + # xmin = c(min(dfall$sector_pct), min(dfall$sector_pct), min(dfall$sector_pct) ), xmax = c(max(dfall$sector_pct)+5, max(dfall$sector_pct)+5, max(dfall$sector_pct)+5 ), ymin = c( 0, maxgreen , maxorange ), # ymax = c( maxgreen , maxorange, maxred ) # @@ -2386,7 +2417,8 @@ compare_resource_result <- function(year = 2022, } else if ( unique(dfall$result_indicator_ascending) == "1") { threshold = data.frame( indlevel = c("crtical","notcool", "Acceptable"), - xmin = c(min(dfall$sector_pct)-5, min(dfall$sector_pct)-5, min(dfall$sector_pct)-5 ), + xmin = c(0, 0, 0 ), + # xmin = c(min(dfall$sector_pct), min(dfall$sector_pct), min(dfall$sector_pct) ), xmax = c(max(dfall$sector_pct)+5, max(dfall$sector_pct)+5, max(dfall$sector_pct)+5 ), ymin = c( 0, maxred, maxorange ), ymax = c( maxred, maxorange, maxgreen ) @@ -2395,6 +2427,16 @@ compare_resource_result <- function(year = 2022, ## now do some check in case, we need to focus on a specific country if (is.null(ctr_name) ){ + # https://dataviz.unhcr.org/assets/download/UNHCR_Data_Visualization_Guidelines.pdf + palette_unhcr_region <- c( "Asia and the Pacific"= "#00B398", + "East and Horn of Africa" = "#0072BC", + "Europe"="#E1CC0D", + "Middle East and North Africa"="#EF4A60", + "Southern Africa" = "#589BE5" , + "The Americas" = "#18375F", + "West and Central Africa"="#8EBEFF" ) + + interpretation <- "Indicator Value Interpretation: circle=Actual Reported Value, color=Standard Acceptability Threshold" ## and now the plot without country focus p <- ggplot2::ggplot( dfall, ggplot2::aes( x = sector_pct)) + @@ -2410,25 +2452,48 @@ compare_resource_result <- function(year = 2022, limits = force, na.value = "grey50") + ggplot2::facet_wrap( ggplot2::vars(result_indicator_actual_value_1), - labeller = ggplot2::labeller(result_indicator_actual_value_1 = ggplot2::label_wrap_gen(20))) + + labeller = ggplot2::labeller(result_indicator_actual_value_1 = ggplot2::label_wrap_gen(20))) + # ggplot2::geom_smooth(ggplot2::aes(y = actual), method = "loess", span = 0.05, alpha =0.25) + + #ggplot2::geom_smooth(method="auto", se=TRUE, fullrange=FALSE, level=0.95) + + + if( show_target == TRUE & show_baseline == TRUE){ + p <- p + ggplot2::geom_segment(ggplot2::aes(x = sector_pct, y = baseline, xend = sector_pct, yend = target), - color = "black") + - # ggplot2::geom_smooth(ggplot2::aes(y = actual), method = "loess", span = 0.05, alpha =0.25) + - #ggplot2::geom_smooth(method="auto", se=TRUE, fullrange=FALSE, level=0.95) + - ggplot2::geom_point( ggplot2::aes(y = baseline), size = 1.5, shape = 22, fill = "black") + - ggplot2::geom_point( ggplot2::aes(y = actual), - size = 3.5, shape = 21, fill = "blue", alpha =0.5) + - ggplot2::geom_point( ggplot2::aes(y = target), size = 1.5 , shape = 24, fill = "black") + + color = "black") + interpretation <- "Indicator Value Interpretation: circle=Actual Reported Value, square=baseline, triangle=Target, color=Standard Acceptability Threshold" + } + + if( show_baseline == TRUE){ + p <- p + + ggplot2::geom_point( ggplot2::aes(y = baseline), size = 1.5, shape = 22, fill = "black") + interpretation <- "Indicator Value Interpretation: circle=Actual Reported Value, square=baseline, color=Standard Acceptability Threshold" + } + if( show_target == TRUE){ + p <- p + + ggplot2::geom_point( ggplot2::aes(y = target), size = 1.5 , shape = 24, fill = "black") + interpretation <- "Indicator Value Interpretation: circle=Actual Reported Value,triangle=Target, color=Standard Acceptability Threshold"} + + + + p <- p + + ggplot2::geom_point( ggplot2::aes(y = actual ), + size = 3.5, shape = 21, fill = "blue", alpha =0.7) + + # ggplot2::geom_point( ggplot2::aes(y = actual, color = unhcr_region), + # size = 3.5, shape = 21, alpha =0.5) + ggrepel::geom_label_repel(ggplot2::aes(y = actual, - label = iso3c), + label = iso3c, + color = unhcr_region), size = 3 ) + - ggplot2::guides(color = "none") + + ggplot2::scale_color_manual(values = palette_unhcr_region, + drop = TRUE, + limits = force, + na.value = "grey50") + + ggplot2::guides(color = "none", fill = "none") + ggplot2::scale_x_continuous( label = scales::label_number(accuracy = 1, - scale_cut = scales::cut_short_scale(), - suffix = "%") ) + + scale_cut = scales::cut_short_scale()) ) + ggplot2::scale_y_continuous( label = scales::label_number(accuracy = 1, scale_cut = scales::cut_short_scale())) + unhcrthemes::theme_unhcr(font_size = 14, @@ -2438,15 +2503,29 @@ compare_resource_result <- function(year = 2022, ggplot2::theme( legend.direction = "horizontal", legend.box = "horizontal", legend.position = "bottom") + - ggplot2::labs( y = "Value: square=baseline, circle=Actual, triangle=Target, color=Standard Acceptability Threshold ", + ## Add correlation + # ggplot2::annotate("text", + # x = max(dfall$sector_pct), + # y = max(dfall$actual), + # label = paste("Correlation [-1, 1] = ", + # round(cor(dfall$sector_pct, dfall$actual, method = "pearson"),2)), + # color = "gray95", + # hjust = 0, + # vjust = 1) + + ggplot2::labs( y = "Indicator Value ", x = "% of resource allocation (expenditure) spent on this outcome" , - title = "Results by Indicator vs Resources by Outcome", + title = paste0("Results by Indicator vs Resources by Outcome |", year) , subtitle = stringr::str_wrap( paste0( "\n Indicators: ", indicator, - "-/- Outcome: ", outcome ) , + " -/- Outcome: ", outcome, + " ---> Correlation [-1, 1] = ", + round(cor(dfall$sector_pct, dfall$actual, method = "pearson"),2) + ) , 100) , - caption = stringr::str_wrap( + caption = stringr::str_wrap( paste0( "Source: Data published by UNHCR as part of the International Aid Transparency Initiative (IATI))" , + ". ---> ", + interpretation), 110) ) } else { ## Treat the case where we would light to highlight a specific country... @@ -2512,7 +2591,7 @@ compare_resource_result <- function(year = 2022, legend.position = "bottom") + ggplot2::labs( y = "Value: square=baseline, circle=Actual, triangle=Target, color=Standard Acceptability Threshold ", x = "% of resource allocation (expenditure) spent on this outcome" , - title = "Results by Indicator vs Resources by Outcome", + title = paste0("Results by Indicator vs Resources by Outcome |", year) , subtitle = stringr::str_wrap( paste0( "\n Indicators: ", indicator, "-/- Outcome: ", outcome ) , @@ -2548,19 +2627,31 @@ compare_resource_result <- function(year = 2022, ```{r example-compare_resource_result, message=FALSE, warning=FALSE, fig.retina = 2, fig.width = 12, fig.asp = 0.618, fig.align = "center", out.width = "90%"} # See a list of indicators per area of work -knitr::kable(iati::mapping_indicator |> - janitor::clean_names() |> - dplyr::filter( results_level =="Outcome") |> - dplyr::select(area_of_work, indicator) ) +list_indic <- iati::mapping_indicator |> + janitor::clean_names() |> + dplyr::filter( results_level =="Outcome") |> + dplyr::left_join(iati::mapping_result |> + dplyr::select(sector_rbm, area_id) |> + dplyr::distinct(), by = c("area_id")) |> + dplyr::select(area_id, sector_rbm, indicator) +knitr::kable(list_indic) compare_resource_result(year = 2022, - indicator = "13.2. Proportion of PoC who self-report positive changes in their income compared to previous year.", - outcome = "OA8: Well-Being and Basic Needs") + show_baseline = TRUE, + show_target = TRUE, + indicator = "13.2. Proportion of PoC who self-report positive changes in their income compared to previous year.", + outcome = "OA8: Well-Being and Basic Needs") compare_resource_result(year = 2022, - ctr_name = "Costa Rica", - indicator = "13.2. Proportion of PoC who self-report positive changes in their income compared to previous year.", - outcome = "OA8: Well-Being and Basic Needs") + ctr_name = "Costa Rica", + indicator = "13.2. Proportion of PoC who self-report positive changes in their income compared to previous year.", + outcome = "OA8: Well-Being and Basic Needs") + + +compare_resource_result(year = 2022, + pop_type = "Refugees and Asylum-seekers", + indicator = "13.2. Proportion of PoC who self-report positive changes in their income compared to previous year.", + outcome = "OA8: Well-Being and Basic Needs") ``` ```{r tests-compare_resource_result} @@ -2621,7 +2712,9 @@ show_expenditure <- function(year, dplyr::left_join(iati::dataActivity, by= c("iati_identifier")) dfB <- iati::dataBudget |> - dplyr::left_join(iati::dataActivity, by= c("iati_identifier")) + dplyr::left_join(iati::dataActivity, by= c("iati_identifier")) |> + dplyr::rename("year_iati" = "year")|> + dplyr::mutate(year = lubridate::year(lubridate::as_date(budget_period_start))) if (!is.null(programme_lab)) { thisprogramme_lab <- programme_lab @@ -2693,7 +2786,7 @@ show_expenditure <- function(year, df2 <- df1 |> dplyr::left_join(df |> dplyr::select(- year), by = c("iati_identifier")) |> dplyr::left_join( dfB , by= c("iati_identifier")) |> - dplyr::select(iati_identifier, year, budget_value, expenditure, commitment ) + dplyr::select(iati_identifier, year, budget_value, expenditure, commitment ) # Error catching -- Check if we weight #weight_by <- c("refugees", "oip") @@ -3882,19 +3975,31 @@ template_prez <- function(year = 2022, # folder = "dev/Prez") # ## Generate for all operation specific region -# region <- "The Americas" +# reg <- iati::dataActivity |> +# dplyr::select( unhcr_region) |> +# dplyr::filter(! is.na(unhcr_region)) |> +# dplyr::distinct() |> +# dplyr::pull() # -# countries <- iati::dataActivity |> -# dplyr::filter( unhcr_region == region) |> -# dplyr::select(ctr_name) |> -# dplyr::distinct() |> -# dplyr::pull() +# thisfolder <- "dev/SMR" # -# for ( ctr in countries) { -# cat(paste0(ctr, "\n")) -# iati::template_prez(year = 2022, -# ctr_name = ctr, -# folder = "dev/Prez") } +# for (region in reg) { +# cat(paste0( region, "\n")) +# +# # region <- "The Americas" +# countries <- iati::dataActivity |> +# dplyr::filter( unhcr_region == region) |> +# dplyr::select(ctr_name) |> +# dplyr::distinct() |> +# dplyr::pull() +# +# for ( ctr in countries) { +# cat(paste0("Generating for ", ctr, "\n")) +# iati::template_prez(year = 2022, +# ctr_name = ctr, +# folder = thisfolder) +# } +# } ``` ```{r tests-template_prez} @@ -3902,7 +4007,62 @@ test_that("template_prez works", { expect_true(inherits(template_prez, "function")) }) ``` + +## template_compare + +```{r function-template_compare} + +# usethis::use_rmarkdown_template( +# template_name = "iati_compare", +# template_dir = NULL, +# template_description = "Compare", +# template_create_dir = TRUE +# ) + + +#' Generate a summary powerpoint +#' +#' @param year A numeric value or a vector of numeric value to filter on year. Note that data pre-2022 are using a different set of indicators +#' @param ctr_name A character vector corresponding to the name of the country. +#' @param folder folder within your project where to put the generated report. +#' Folder will be created if it does not exist +#' +#' @importFrom unhcrdown pptx_slides +#' @importFrom dplyr filter select pull +#' @importFrom rmarkdown render +#' @importFrom here here +#' @importFrom countrycode countrycode +#' @importFrom stringr str_replace_all +#' +#' @return nothing the file for the report is generated +#' +#' @export +#' +template_compare <- function(year = 2022, + folder = "Compare") { + + ## Create the outfolder if it does not exist + output_dir <- paste0(getwd(),"/",folder) + if (!dir.exists(output_dir)) {dir.create(output_dir)} + + rmarkdown::render( + system.file("rmarkdown/templates/iati_compare/skeleton/skeleton.Rmd", package = "iati"), + output_file = here::here(folder, paste0('Result_Resource', + '-', year, '.pptx') ), + params = list(year = year) ) +} +``` + +```{r example-template_compare} +# iati::template_compare(year = 2022, folder = "dev/Result") +``` +```{r tests-template_compare} +test_that("template_compare works", { + expect_true(inherits(template_compare, "function")) +}) +``` + ```{r development-inflate, eval=FALSE} diff --git a/docs/articles/get-started.html b/docs/articles/get-started.html deleted file mode 100644 index bac8bdb..0000000 --- a/docs/articles/get-started.html +++ /dev/null @@ -1,198 +0,0 @@ - - - - - - - - -Get started • iati - - - - - - - - - - Skip to contents - - -
- - - - -
-
- - - - - - - - -
-

Show donors - show_donors -

- - -
-show_donors(year = 2020,
-            geo = "The Americas",
-            transtype = "11" )
-

-
-# ,  ## "3"  "4"  "11"           metric = "USD"
- -
-
-

Show implementers - show_implementers -

-
-show_implementers(year = 2020,
-            geo = "The Americas",
-            transtype = "11" ) 
-

- -
-
-
- - - - -
- - - - - - - diff --git a/docs/articles/get-started_files/figure-html/examples-show_donors-1.png b/docs/articles/get-started_files/figure-html/examples-show_donors-1.png deleted file mode 100644 index 7f98adb..0000000 Binary files a/docs/articles/get-started_files/figure-html/examples-show_donors-1.png and /dev/null differ diff --git a/docs/articles/get-started_files/figure-html/examples-show_implementers-1.png b/docs/articles/get-started_files/figure-html/examples-show_implementers-1.png deleted file mode 100644 index 135c487..0000000 Binary files a/docs/articles/get-started_files/figure-html/examples-show_implementers-1.png and /dev/null differ diff --git a/docs/articles/unhcr-programme.html b/docs/articles/unhcr-programme.html index 5f303d4..855be68 100644 --- a/docs/articles/unhcr-programme.html +++ b/docs/articles/unhcr-programme.html @@ -335,181 +335,223 @@

compare_resource_result
 # See a list of indicators per area of work
-knitr::kable(iati::mapping_indicator |> 
-               janitor::clean_names() |>
-               dplyr::filter( results_level =="Outcome") |>
-               dplyr::select(area_of_work,  indicator) )
+list_indic <- iati::mapping_indicator |> + janitor::clean_names() |> + dplyr::filter( results_level =="Outcome") |> + dplyr::left_join(iati::mapping_result |> + dplyr::select(sector_rbm, area_id) |> + dplyr::distinct(), by = c("area_id")) |> + dplyr::select(area_id, sector_rbm, indicator) +knitr::kable(list_indic) --+++ - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + @@ -518,16 +560,26 @@

compare_resource_result
 
 compare_resource_result(year =   2022, 
-                    indicator = "13.2. Proportion of PoC who self-report positive changes in their income compared to previous year.",
-                    outcome = "OA8: Well-Being and Basic Needs")
+ show_baseline = TRUE, + show_target = TRUE, + indicator = "13.2. Proportion of PoC who self-report positive changes in their income compared to previous year.", + outcome = "OA8: Well-Being and Basic Needs")

 
 compare_resource_result(year =   2022, 
-                        ctr_name = "Costa Rica",
-                    indicator = "13.2. Proportion of PoC who self-report positive changes in their income compared to previous year.",
-                    outcome = "OA8: Well-Being and Basic Needs")
+ ctr_name = "Costa Rica", + indicator = "13.2. Proportion of PoC who self-report positive changes in their income compared to previous year.", + outcome = "OA8: Well-Being and Basic Needs")

+
+
+
+compare_resource_result(year =   2022, 
+       pop_type = "Refugees and Asylum-seekers",
+       indicator = "13.2. Proportion of PoC who self-report positive changes in their income compared to previous year.",
+       outcome = "OA8: Well-Being and Basic Needs")
+

@@ -540,17 +592,17 @@

show_expenditureHow much expenditures compare to the initial budget (potentially weighted by # )? -
+
 show_expenditure(year = c(2018, 2019,2020, 2021, 2022, 2023), 
              ctr_name = "Brazil")

-
+
 
 show_expenditure(year = c(2018, 2019,2020, 2021, 2022, 2023), 
              ctr_name = "Brazil",
              weight_by = c("refugees", "oip"))

-
+
 
 
 show_expenditure(year = c(2018, 2019,2020, 2021, 2022, 2023),
@@ -561,11 +613,11 @@ 

show_expenditure

show_budget_gap

-
+
 show_budget_gap(year = c(2018, 2019,2020, 2021, 2022, 2023), 
              ctr_name = "Brazil")

-
+
 show_budget_gap(year = c(2018, 2019,2020, 2021, 2022, 2023), 
              ctr_name = "Brazil",
              weight_by = c("refugees", "oip"))
@@ -582,7 +634,7 @@

Show donors
+
 knitr::kable(iati::dataTransaction |>
                 dplyr::select( transaction_type_name, transaction_type_description) |>
                 dplyr::distinct() )
@@ -615,22 +667,22 @@

Show donors
+
 show_donors(year = 2022,
            programme_lab = "The Americas",
            transaction_type_name = "Incoming Commitment" )

-
+
 show_donors(year = c(2018, 2019,2020, 2021, 2022, 2023),
            ctr_name = "Brazil",
            transaction_type_name = "Incoming Commitment" )

-
+
 show_donors(year = c(2018, 2019,2020, 2021, 2022, 2023),
            programme_lab = "Brazil",
            transaction_type_name = "Disbursement" )

-
+
 show_donors(year = c(2018, 2019,2020, 2021, 2022, 2023),
            programme_lab = "Brazil",
            transaction_type_name = "Expenditure" )
@@ -639,12 +691,12 @@

Show donors

show_top_donors

-
+
 show_top_donors(year = 2022,
            ctr_name = "Brazil", 
            top_n = 5)

-
+
 show_top_donors(year = 2020,
            ctr_name = "Brazil", 
            top_n = 10)
@@ -657,7 +709,7 @@

show_earmarkingWhat’s the breakdown of Earmarking Type (Un-earmarked, Tightly earmarked, etc.) from Donor Funds by Year? -
+
 knitr::kable(iati::dataTransaction |>
                 dplyr::select(earmarking_name, earmarking_description)  |>
                 dplyr::distinct() |>
@@ -694,7 +746,7 @@ 

show_earmarking

area_of_workarea_idsector_rbm indicator
RegistrationOA1OA1: Access to Territory, Reg. and Documentation 1.1 Proportion of refugees and asylum seekers registered on an individual basis.
StatelessnessOA1OA1: Access to Territory, Reg. and Documentation 1.2 Proportion of children under 5 years of age whose births have been registered with a civil authority. [SDG 16.9.1 - Tier 1]
DocumentationOA1OA1: Access to Territory, Reg. and Documentation 1.3 Proportion of PoC with legally recognized identity documents or credentials [GCR 4.2.2].
Refugee Status DeterminationOA2OA2: Status Determination 2.1 Average processing time (in days) from registration to first instance asylum decision (disaggregated by individual and group procedures).
Refugee Status DeterminationOA2OA2: Status Determination 2.2 Proportion of individuals undergoing asylum procedures who have access to legal advice or representation.
Refugee Status DeterminationOA2OA2: Status Determination 2.3 Proportion of individuals undergoing asylum procedures who have access to an effective appeal mechanism after first instance rejection of their claim.
Law & PolicyOA3OA3: Protection Policy and Law 3.1 Extent national legal framework is in line with the 1951 Convention and/or its 1967 Protocol.
StatelessnessOA3OA3: Protection Policy and Law 3.2 Extent national legal framework is in line with the 1961 Convention on the Reduction of Statelessness.
Gender-Based ViolenceOA4OA4: Sexual and Gender-based Violence 4.1 Proportion of PoC who know where to access available GBV services
Gender-Based ViolenceOA4OA4: Sexual and Gender-based Violence 4.2 Proportion of POCs who do not accept violence against women.
Gender-Based ViolenceOA4OA4: Sexual and Gender-based Violence 4.3 Proportion of survivors who are satisfied with SGBV case management services.
Child ProtectionOA5OA5: Child Protection 5.1 Proportion of children at heightened risk who are supported by a Best Interests Procedure.
Child Protection, Community-Based ProtectionOA5OA5: Child Protection 5.2 Proportion of children who participate in community-based child protection programmes
Child ProtectionOA5OA5: Child Protection 5.3 Proportion of unaccompanied and separated children who are in an appropriate alternative care arrangement
Freedom of MovementOA6OA6: Safety and Access to Justice 6.1 Number of PoC arrested or detained related to immigration control or legal status
Accountability to Affected PopulationsOA7OA7: Community Engagement and Women’s Empowerment 7.1 Proportion of PoC who participate meaningfully across all phases of the OMC.
Accountability to Affected PopulationsOA7OA7: Community Engagement and Women’s Empowerment 7.2 Proportion of PoC who have access to effective feedback and response mechanisms.
Community StructuresOA7OA7: Community Engagement and Women’s Empowerment 7.3 Proportion (and number) of active female participants on leadership/management structures.
Basic NeedsOA8OA8: Well-Being and Basic Needs 8.1 Proportion of PoC in need that receive cash transfers or in-kind assistance.
EnergyOA8OA8: Well-Being and Basic Needs 8.2 Proportion of PoC with primary reliance on clean (cooking) fuels and technology [SDG 7.1.2 Tier 1]
ShelterOA9OA9: Sustainable Housing and Settlements 9.1 Proportion of PoCs living in habitable and affordable housing.
EnergyOA9OA9: Sustainable Housing and Settlements 9.2 Proportion of PoC that have energy to ensure lighting (close to Sphere).
HealthOA10OA10: Healthy Lives 10.1 Proportion of children aged 9 months to five years who have received measles vaccination.
HealthOA10OA10: Healthy Lives 10.2. Proportion of births attended by skilled health personnel. [SDG 3.1.2 Tier 1]
EducationOA11OA11: Education 11.1 Proportion of PoC enrolled in tertiary and higher education.
EducationOA11OA11: Education 11.2 Proportion of PoC enrolled in the national education system. [GCR 2.2.1]
Water, Sanitation & HygieneOA12OA12: Clean Water, Sanitation and Hygiene 12.1 Proportion of PoC using at least basic drinking water services [linked to SDG 6.1.1].
Water, Sanitation & HygieneOA12OA12: Clean Water, Sanitation and Hygiene 12.2 Proportion of PoC with access to a safe household toilet [linked to SDG 6.2.1].
Livelihoods & Economic InclusionOA13OA13: Self Reliance, Economic Inclusion and +Livelihoods 13.1. Proportion of PoC with an account at a bank or other financial institution or with a mobile-money-service provider [SDG 8.10.2 Tier 1].
Livelihoods & Economic InclusionOA13OA13: Self Reliance, Economic Inclusion and +Livelihoods 13.2. Proportion of PoC who self-report positive changes in their income compared to previous year.
Livelihoods & Economic InclusionOA13OA13: Self Reliance, Economic Inclusion and +Livelihoods 13.3 Proportion of PoC (working age) who are unemployed.
Voluntary RepatriationOA14OA14: Voluntary Repatriation and Sustainable +Reintegration 14.1 Proportion of returnees with legally recognized identity documents or credentials [GCR 4.2.2].
-
+
 show_earmarking(year = c(2018, 2019,2020, 2021, 2022, 2023),  
              ctr_name = "Brazil")

@@ -702,7 +754,7 @@

show_earmarking

show_contributions

-
+
 knitr::kable(iati::dataTransaction |>
                 dplyr::select(aid_type1_name, aid_type1_description)  |>
                 dplyr::distinct() |>
@@ -764,11 +816,11 @@ 

show_contributions
+
 show_contributions(year = c(2018, 2019,2020, 2021, 2022, 2023), 
                    ctr_name = "Brazil") 

-
+
 show_contributions(year = c(2018, 2019,2020, 2021, 2022, 2023), 
                    programme_lab = "The Americas") 

@@ -776,11 +828,11 @@

show_contributions

show_transaction_flow

-
+
 show_transaction_flow(year = c(2020, 2021, 2022, 2023), 
                    ctr_name = "Brazil")

-
+
 
 show_transaction_flow(year = 2023, 
                    ctr_name = "Brazil")
@@ -796,7 +848,7 @@

Show partnership
  • How organisations partner together?
  • -
    +
     show_partnership(year = 2022,
                ctr_name = "Brazil" ) 
    @@ -873,7 +925,7 @@

    Template

    template_prez

    - + +
    +

    template_compare +

    +
    +# iati::template_compare(year = 2022, folder = "dev/Result")