knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(goalie)
To begin, we can use sdg_overview()
to begin to explore all data available in the SDG database
library(goalie) sdg_overview()
If we want the data for SI_POV_DAY1
, we could now just quickly access the data frame using sdg_data()
.
sdg_data("SI_POV_DAY1")
From here, standard methods of data manipulation (e.g. base R, the tidyverse) could be used to select variables, filter rows, and explore the data. However, we can also continue to explore other aspects of the SDG database. For instance, if we wanted to see the dimensions and attributes of SI_POV_DAY1
, we can easily access that.
sdg_dimensions(series = "SI_POV_DAY1")
sdg_attributes(series = "SI_POV_DAY1")
Let's say we want to get data for a specific country, then we could look up the M49 code using the table available through the API.
sdg_geoareas()
We can then even check what data is available for a specific country, say Angola.
sdg_geoarea_data(24)
And we can get data from the SDG for multiple series in one call, with the output data frames already merged together.
sdg_data(c("SI_POV_DAY1", "SI_POV_EMP1", "SI_POV_NAHC"))
Of course, the reality is that it's likely easier for us to work outside the OData filtering framework and directly in R, so here's a final more complex example using dplyr
and stringr
alongside goalie
to automatically download all indicators for Angola with the word "poverty" in the series description (case insensitive), for the years 1990 to 2005.
library(dplyr) library(stringr) sdg_geoarea_data(24) %>% filter(str_detect(str_to_lower(series_description), "poverty")) %>% pull(series) %>% sdg_data(area_codes = 24, 1990, 2005)
And once we have that data, we can then filter, explore, and analyze the data with our standard R workflow, or even export the downloaded data to Excel or other analytical tools for further use.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.