Skip to content
Snippets Groups Projects
Select Git revision
  • f0596ef62f2b166a5cc05174cd32f740da081e8e
  • main default
  • master
3 results

WDI.Rmd

Blame
  • title: "World data bank indicator"
    author: "Laurent Modolo [laurent.modolo@ens-lyon.fr](mailto:laurent.modolo@ens-lyon.fr)"
    date: "2021"
    output:
      rmdformats::downcute:
        self_contain: false
        use_bookdown: true
        default_style: "dark"
        lightbox: true
        css: "../src/style.css"
    rm(list=ls())
    knitr::opts_chunk$set(echo = TRUE)
    knitr::opts_chunk$set(comment = NA)
    klippy::klippy(
      position = c('top', 'right'),
      color = "white",
      tooltip_message = 'Click to copy',
      tooltip_success = 'Copied !')

    World Bank datasets

    The World Bank makes available a ton of great data from the World Development Indicators through its web API. The WDI package for R makes it easy to search and download data series from the WDI.

    library(tidyverse)
    install.packages("WDI")
    library(WDI)

    Creating a dataset

    You can also embed plots, for example:

    data <- WDI(
      indicator = c(
        "NY.GDP.MKTP.CD", 
        "NY.GDP.MKTP.KD.ZG", 
        "SI.POV.GINI",
        "SP.POP.TOTL",
        "EN.ATM.CO2E.PC",
        "SP.DYN.LE00.IN"
      ),
      country = c('AL', 'AD', 'AM', 'AT', 'BY', 'BE', 'BA', 'BG', 'CH', 'CY', 'CZ', 'DE',
            'DK', 'EE', 'ES', 'FO', 'FI', 'FR', 'GB', 'GE', 'GI', 'GR', 'HU', 'HR',
            'IE', 'IS', 'IT', 'LI', 'LT', 'LU', 'LV', 'MC', 'MK', 'MT', 'NO', 'NL', 'PL',
            'PT', 'RO', 'RS', 'RU', 'SE', 'SI', 'SK', 'SM', 'TR', 'UA', 'VA'),
      start = 1960,
      end = 2021)

    Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

    ggplot(
      data=data,
      mapping=aes(
        x = year,
        y = NY.GDP.MKTP.CD/SP.POP.TOTL,
        color = country
      )) +
      geom_line()

    Plot of fertility rate and life expetency by country through time

    Plot of GPD and child survival by country through time