Here is a basic run-through of the {SDGsR} workflow. The package interfaces with UN SDGs API (see https://unstats.un.org/SDGAPI/swagger/) and allows the user to get the text of the 17 Goals, each associated Target and Indicators. This post: https://rpubs.com/angelamhkim/sdgapi was the inspiration for this package. Using the SDGsR::get_indicator() function one can get the indicator data for a specific country and indicator.

What are the SDGs?

For a comprehensive explanation of what the SDGs are and how they were developed please see https://www.undp.org/content/undp/en/home/sustainable-development-goals.html

Using the {SDGsR} package

Currently, there are five functions in the package which facilitate interaction with the SDGs API.

To get the text of the Goals we can use the SDGsR::get_SDGs_goals() function. This gathers together all the Goals in to a single dataframe.

library(SDGsR)
Goals<-get_SDGs_goals()
Goals %>% select(goal, code, description ) %>% 
  sample_n(.,3) %>% #randomly select three rows to display
  kableExtra::kable()
goal code description
6 6.6 By 2020, protect and restore water-related ecosystems, including mountains, forests, wetlands, rivers, aquifers and lakes
16 16.7 Ensure responsive, inclusive, participatory and representative decision-making at all levels
11 11.1 By 2030, ensure access for all to adequate, safe and affordable housing and basic services and upgrade slums

The most useful function is the SDGsR::get_indicator() function that allows the user to query the data for a specific indicator in a specific country. First we need to make sure we know which is the correct code for the country and for the indicator as the API uses these to distinguish which data to export. There is an country list in the package that you can use to find the name of the country you are looking for.

head(get_country_list())
#> [1] "Afghanistan"    "Åland Islands"  "Albania"        "Algeria"       
#> [5] "American Samoa" "Andorra"

To find a specific indicator we need to know the right code to use. We can get a list of all the indicators by using SDGsR::get_indicator_list. I am interested in the indicators that are in Goal 15 Life on Land.

ind_lst<-get_indicator_list()

ind_lst %>% 
  filter(goal=="15") %>% 
  select(target, code, description) %>% 
  kableExtra::kable()
target code description
15.1 15.1.1 Forest area as a proportion of total land area
15.1 15.1.2 Proportion of important sites for terrestrial and freshwater biodiversity that are covered by protected areas, by ecosystem type
15.2 15.2.1 Progress towards sustainable forest management
15.3 15.3.1 Proportion of land that is degraded over total land area
15.4 15.4.1 Coverage by protected areas of important sites for mountain biodiversity
15.4 15.4.2
  1. Mountain Green Cover Index and (b) proportion of degraded mountain land
15.5 15.5.1 Red List Index
15.6 15.6.1 Number of countries that have adopted legislative, administrative and policy frameworks to ensure fair and equitable sharing of benefits
15.7 15.7.1 Proportion of traded wildlife that was poached or illicitly trafficked
15.8 15.8.1 Proportion of countries adopting relevant national legislation and adequately resourcing the prevention or control of invasive alien species
15.9 15.9.1
  1. Number of countries that have established national targets in accordance with or similar to Aichi Biodiversity Target 2 of the Strategic Plan for Biodiversity 2011–2020 in their national biodiversity strategy and action plans and the progress reported towards these targets; and (b) integration of biodiversity into national accounting and reporting systems, defined as implementation of the System of Environmental-Economic Accounting
15.a 15.a.1
  1. Official development assistance on conservation and sustainable use of biodiversity; and (b) revenue generated and finance mobilized from biodiversity-relevant economic instruments
15.b 15.b.1
  1. Official development assistance on conservation and sustainable use of biodiversity; and (b) revenue generated and finance mobilized from biodiversity-relevant economic instruments
15.c 15.c.1 Proportion of traded wildlife that was poached or illicitly trafficked

Let’s look at the indicator for Target 15.4, “15.4.1: Coverage by protected areas of important sites for mountain biodiversity” and we will specify Norway as our country of interest. We know that Norway is named Norway on our country list (which is obvious but some countries are named in different ways to how we might commonly expect, e.g. Vietnam is specified as “Viet Nam”, Venezuela is specified as “Venezuela (Bolivarian Republic of)”).

Norway_code<-lookup_country(code="M49", country = "Norway")
Norway_code
#> [1] 578
Norway<-get_indicator(Country = Norway_code, indicator = "15.4.1")

We can then make a plot of this data using the SDGsR::SDGs_colours() function.


p1<-Norway %>% 
  select(timePeriodStart,value,seriesDescription) %>% 
  ggplot(aes(timePeriodStart, as.numeric(value)))+
  geom_point(colour=SDGs_cols("Goal15"))+
  labs(x="Year", y="% Mountain Area Protected")+
  ggtitle(label=paste0(Norway$seriesDescription[1])) +
  ggpubr::theme_pubclean()+
  theme(plot.title = element_text(size = 12))
p1