R for data analysis

Beginner course · Master GPE (CERDI / IHEDD)

Six sessions to learn R: import, manipulate, describe, visualise and report development data.

Six sessions to learn R from scratch, for Master GPE students (development economics). No prerequisites: you start by installing R and finish with a reproducible report built on World Bank data.

The six sessions

Where we are going

Common thread: growth, health and inequality, what does the data say about developing countries?

  1. R and RStudio
  2. Import
  3. Manipulate
  4. Describe
  5. Visualise
  6. Report

Import data, manipulate it, describe it, visualise it, then report it: each session adds one link to the chain.

By Session 5 you will produce charts like this one: richer countries live longer, but the gain flattens out (the “Preston curve”). Every point is a country; the area shows its population.

Show the code (you will write this in Session 5)
wdi <- read_csv(here("data", "wdi_panel.csv"), show_col_types = FALSE)
# CAF life expectancy is unreliable in this WDI release (14.7 in 2009, 18.8 in 2022): exclude every year
wdi <- wdi |> mutate(life_exp = if_else(iso3c == "CAF", NA_real_, life_exp))

wdi |>
  filter(year == 2019, !is.na(gdp_pc_ppp), !is.na(life_exp), !is.na(region)) |>
  ggplot(aes(x = gdp_pc_ppp, y = life_exp, size = population, colour = region)) +
  geom_point(alpha = 0.7) +
  scale_x_log10(labels = label_dollar(scale_cut = cut_short_scale())) +
  scale_size_area(max_size = 12, guide = "none") +
  scale_colour_manual(values = pal_regions, labels = label_wrap(25)) +
  guides(colour = guide_legend(nrow = 3, override.aes = list(size = 3))) +
  labs(
    title = "Richer countries live longer, with diminishing returns",
    x = "GDP per capita (constant 2021 PPP $, log scale)",
    y = "Life expectancy at birth (years)",
    colour = NULL,
    caption = "Source: World Bank, World Development Indicators (WDI), 2019. Bubble area = population."
  )

Bubble chart of life expectancy against GDP per capita (log scale) for countries in 2019, coloured by region, bubble area proportional to population. Life expectancy rises with income, with diminishing gains at higher incomes.

Before the first session

ImportantTo do at home
  1. Install R: https://cran.r-project.org/.
  2. Install RStudio Desktop: https://posit.co/download/rstudio-desktop/ (after R).
  3. In RStudio: File > New Project > New Directory and create a project folder named r-course.
  4. Download data.zip and unzip it into the r-course folder, so that data/ and R/theme_cours.R sit next to the .Rproj file (here::here() relies on this).
  5. Install the packages: paste the block below in the RStudio Console and run it once. It takes a few minutes.
install.packages(c("tidyverse", "here", "janitor", "readxl", "writexl",
                   "lubridate", "scales", "WDI", "gt", "fixest",
                   "modelsummary", "ggrepel", "sf", "rnaturalearth",
                   "rnaturalearthdata", "patchwork", "plotly", "crosstalk",
                   "shiny"))

Expected folder tree:

r-course/
├── r-course.Rproj
├── data/
│   ├── wdi_panel.csv
│   ├── ...
│   └── raw/
└── R/
    └── theme_cours.R

How to use this site

  • Every session follows the same plan: objectives, explanations with code, exercises, then “Key takeaways”.
  • Type the code yourself in RStudio rather than copying it: that is how you learn.
  • Solutions are collapsed: try first, then open to compare.
  • An error is not a failure: read the message, it almost always says what is wrong.

AI and code

AI assistants can explain an error message or an unfamiliar function. They must not replace your learning. Always run the suggested code and understand every line before using it: code that runs is not necessarily correct.


Content licensed CC BY-NC-ND 4.0, like pierrebeaucoral.github.io. Last updated: October 2026.

Back to top