Did you know the 17 SDGs have over 230 indicators?

Frank Kienle
4 min readJan 22, 2022

--

The Sustainable Development Goals (SDGs) are 17 global goals designed to be a „blueprint for achieving a better and more sustainable future for all”. The goals to be achieved by 2030 are an urgent call for action by all countries — and us all. Did you know the 17 SDGs have over 230 indicators? Let us visualise the SDGs!

Each indicator measures the progress of all countries, sometimes over decades-a lot of data points to analyze. Let’s start to visualise and analyze them! The article is part of a online course ‚ Data Science on Sustainable Development Goals. The course is for free!

The 17 SDGs goals indicator list can be downloaded here as a excel version: https://unstats.un.org/sdgs/indicators/indicators-list/

The excel view of the SDGs Metadata list

The Indicator Frameworks describes always the Goal the target and the indicator. The indicator gives guidance how to measure the progress towards the targets.

The file itself is cumbersome to parse and to read. As a first steep we have to understand our target data structure. One possible visualisation type to drill down into the targets, goals and its indicators.

The tree map view

A treemap chart provides a hierarchical view of your data. We will use two Python libraries to handle and to visualize the indicators: pandas and plotly. Both come with extensive documentation and possibilities.

Lets have first a quick look on a simple example .The example is taken form the tree map documentaion of plotly

import plotly.express as px fig = px.treemap( names = ["Eve","Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"], parents = ["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve"] ) fig.update_traces(root_color="lightgrey") 
fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
fig.show()

The example is very simple. Of interest is the data structure which requires two columns where one colomn is the parent and the other the link to its child.

The SDG indicators have to be mapped to clean two columns. You can access the cleaned file and the final source code as well in the GITHAB repository.

Loading the file is well known by. However, when looking at the file we still have some NaN due an inconsistent grouping of rows in the original file. With the fillna() method this can be easy fixed

my_topics=pd.read_excel('Clean_tree_list_Global Indicator Framework after 2021 refinement_English.xlsx',sheet_name='indicators_flat')# ensure first element to be empty, required in the data structure
my_topics['SDGs'][0]=''

# the file has some NaN and plotly requires these to be filled
my_topics['Goals and Targets']=my_topics['Goals and Targets'].fillna(method='ffill')
my_topics['SDGs']=my_topics['SDGs'].fillna(method='ffill')
my_topics
The data structure for hierarchical plots in plot.ly

With this basic data set we can start use the tree plot command. The result will not be too nice since plot.ly has not a build-in line break for the text elements. For this we have to apply a line wrapping of the text fields first.

def split_every_x_words(value,nr_chars):
''' the function is pushing the textwrap array in a concatenated string.
Each element is separated by a line html line break element'''
my_text=''
#print(value)
text_list=textwrap.wrap(value,nr_chars)
for count,word in enumerate(text_list):
my_text+=(word+'<br>')
return my_text

my_labels=[split_every_x_words(each,20) for each in my_topics['Goals and Targets']]
my_parents=[split_every_x_words(each,20) for each in my_topics['SDGs']]

The function and used library textwrap which allows simple breakdown of a longer string. The line break itself is introduced within a text sting with the html tag ‚<br>’.

Now we are ready for our first drilldown plot.

## ensure theat the first parents element is empty 
my_parents[0]=''
my_labels[0]=my_parents[1]

fig = go.Figure(go.Treemap(
labels=np.array(my_labels),
parents=np.array(my_parents),
hoverinfo= 'text',
maxdepth=3,
))

fig.update_layout(margin = dict(t=0, l=0, r=0, b=0),
uniformtext=dict(minsize=12,
# mode='show',
),
width=1200, height=800
)
fig.show()
fig.write_html("Overview_SDGs_treemap.html")
Tree map view of the 17 Goals and Targets

The tree map gives us possibilities to go with two or more levels. Just try it out.

The Sunburst View

An other possibility to visualise the SDGs meta data structure is the the sunburst chart. A Sunburst Diagram is used to visualize hierarchical data, depicted by concentric circles. The circle in the centre represents the root node, with the hierarchy moving outward from the center.

You can directly use the same construct as seen above since mandatory data structure is identically.

# use a special line split for the sunburst chart
my_labels=[split_every_x_words(each,35) for each in my_topics['Goals and Targets']]
my_parents=[split_every_x_words(each,35) for each in my_topics['SDGs']]
fig =go.Figure(go.Sunburst(
labels=np.array(my_labels),
parents=np.array(my_parents),
insidetextorientation='radial',
hoverinfo= 'text',
maxdepth=6, #visualize the full depth
))fig.update_layout(margin = dict(t=0, l=0, r=0, b=0),
uniformtext=dict(minsize=12, ),#mode='show'
width=1800, height=1200, # very large graphic
hoverlabel = dict(
bgcolor = '#faf8de' )#whatever format you want
)
fig.show()
fig.write_html("Overview_SDGs_sunburst.html")

When analysing the Metadata of the SDGs, I mostly played with the sunburst chart. It is fun to explore the individual indicators and to see the dynamic animation of plot.ly.

Have fun and explore. Fur further python trainings lets explore the course on Covid-19 data. You want to understand the mandatory roles for your data Science career lets have a look on the Analytics Translator course.

Originally published at https://theanalyticstranslator.org on January 22, 2022.

--

--

Frank Kienle
Frank Kienle

Written by Frank Kienle

My mission is to help individuals and organizations improving their analytics capabilities to reach their vision.

No responses yet