R for Humanitarian Reporting

Cédric Vidonne

Feb 7, 2025

Agenda

  1. Why R?
  2. Data Ingestion & Wrangling
  3. Data Visualization
  4. Reporting
  5. Q&A

Why R?

Product creation workflow

What is R & Its Ecosystem

  • Statistical programming language designed for data analysis
  • Free and open-source software
  • Extensible: 20,000+ packages for specialized tasks
  • tidyverse: Modern data wrangling & visualization
  • RMarkdown/Quarto: Dynamic report generation
  • Active community: Extensive resources and support
  • Humanitarian specific packages: rhdx, racled, etc.

Workflow with R

Data Ingestion & Wrangling

Getting data into R

Where Does Our Data Come From?

  • Local data (spreadsheets, databases)
  • External data (APIs, HDX, ACLED)
  • Geospatial data (shapefiles, GeoJSON)
  • R packages: refugees, rnaturalearth, …

Data Wrangling

Think of it as “Excel with superpowers”

  • Data Selection and Filtering
  • Data Transformation
  • Grouping and Summarization
  • Reproducibility—write once, update forever
  • Performance

Example

Data Visualization

ggplot2

  • Grammar of Graphics by Leland Irving → Build plots layer by layer
  • Consistent & flexible
  • Can also be extended with packages

unhcrthemes

  1. Branded ggplot2 theme

  2. A series of color palette for:

    • A categorical palette for UNHCR main data visualization colors

    • A categorical palette for people of concern to UNHCR categories

    • A categorical palette for geographical regional divisions of UNHCR

    • Six sequential color palettes for all the main data visualization colors

    • Two recommended diverging color palette

  3. Available on CRAN

Example

Reporting

RMarkdown

  • A single document combining text, code, and visuals
  • Update data → Report updates automatically
  • Export to Word, PDF, HTML, and more.

unhcrdown

  • A collection of professional templates following UNHCR brand guidelines
  • Ready-to-use formats for reports, presentations, and websites
  • Easy-to-use functions that work seamlessly with R Markdown
  • Consistent styling across all document types

Example

UNHCR Tools

Questions