knitr::opts_chunk$set(fig.width=8, fig.height=8, collapse = TRUE, comment = "#>" )
Here is a basic runthrough of the {SDGsR} workflow. The package interfaces with UN SDGs API (see https://unstats.un.org/sdgs/UNSDGAPIV5/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.
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
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()
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.
head(get_country_list())
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()
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
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.