Sustainable Development Goals

This website was designed to provide insights on the 17 Sustainable Development Goals (SDG) defined by United Nations. The Sustainable Development Goals (SDGs) are a universal call to action to end poverty, protect the planet and improve the lives and prospects of everyone, everywhere. The 17 Goals were adopted by all UN Member States in 2015, as part of the 2030 Agenda for Sustainable Development.

Rankings

World Index Score

import pandas as pd
import altair as alt

source = pd.read_csv('rankings/average.csv')

alt.Chart(source).mark_line(point=True).encode(
   alt.X('Year', scale=alt.Scale(zero=False)),
   alt.Y('Average', scale=alt.Scale(zero=False)),
   order='Year',
   tooltip=['Average']
)

Index Score versus Spillover Score

Overall performance

All 193 UN Member States are ranked by their overall score. The overall score measures a country’s total progress towards achieving all 17 SDGs. The score can be interpreted as a percentage of SDG achievement. A score of 100 indicates that all SDGs have been achieved.

All regions

Rank

Flag

Country

Score

1

flags/tn_fi-flag.gif

Finland

85.90

2

flags/tn_se-flag.gif

Sweden

85.61

3

flags/tn_dk-flag.gif

Denmark

84.86

4

flags/tn_de-flag.gif

Germany

82.48

5

flags/tn_be-flag.gif

Belgium

82.19

6

flags/tn_at-flag.gif

Austria

82.08

7

flags/tn_no-flag.gif

Norway

81.98

8

flags/tn_fr-flag.gif

France

81.67

9

flags/tn_si-flag.gif

Slovenia

81.60

10

flags/tn_ee-flag.gif

Estonia

81.58

11

flags/tn_nl-flag.gif

Netherlands

81.56

12

flags/tn_cz-flag.gif

Czech Republic

81.39

13

flags/tn_ie-flag.gif

Ireland

80.96

14

flags/tn_hr-flag.gif

Croatia

80.38

15

flags/tn_pl-flag.gif

Poland

80.22

16

flags/tn_ch-flag.gif

Switzerland

80.10

17

flags/tn_gb-flag.gif

United Kingdom

79.97

18

flags/tn_jp-flag.gif

Japan

79.85

19

flags/tn_sk-flag.gif

Slovak Republic

79.57

20

flags/tn_es-flag.gif

Spain

79.46

21

flags/tn_ca-flag.gif

Canada

79.16

22

flags/tn_lv-flag.gif

Latvia

79.15

23

flags/tn_nz-flag.gif

New Zealand

79.13

24

flags/tn_by-flag.gif

Belarus

78.82

25

flags/tn_hu-flag.gif

Hungary

78.78

26

flags/tn_it-flag.gif

Italy

78.76

27

flags/tn_pt-flag.gif

Portugal

78.64

28

flags/tn_kr-flag.gif

Korea, Rep.

78.59

29

flags/tn_is-flag.gif

Iceland

78.17

30

flags/tn_cl-flag.gif

Chile

77.13

31

flags/tn_lt-flag.gif

Lithuania

76.70

32

flags/tn_us-flag.gif

United States

76.01

33

flags/tn_mt-flag.gif

Malta

75.75

34

flags/tn_rs-flag.gif

Serbia

75.59

35

flags/tn_au-flag.gif

Australia

75.58

36

flags/tn_ua-flag.gif

Ukraine

75.51

37

flags/tn_gr-flag.gif

Greece

75.41

38

flags/tn_il-flag.gif

Israel

75.04

39

flags/tn_ro-flag.gif

Romania

74.97

40

flags/tn_cy-flag.gif

Cyprus

74.87

41

flags/tn_uy-flag.gif

Uruguay

74.55

42

flags/tn_lu-flag.gif

Luxembourg

74.21

43

flags/tn_th-flag.gif

Thailand

74.19

44

flags/tn_kg-flag.gif

Kyrgyz Republic

74.00

45

flags/tn_bg-flag.gif

Bulgaria

73.81

46

flags/tn_ru-flag.gif

Russian Federation

73.75

47

flags/tn_ba-flag.gif

Bosnia and Herzegovina

73.70

48

flags/tn_md-flag.gif

Moldova

73.68

49

flags/tn_cu-flag.gif

Cuba

73.65

50

flags/tn_cr-flag.gif

Costa Rica

73.55

51

flags/tn_vn-flag.gif

Vietnam

72.85

52

flags/tn_ar-flag.gif

Argentina

72.80

53

flags/tn_ec-flag.gif

Ecuador

72.54

54

flags/tn_mk-flag.gif

North Macedonia

72.53

55

flags/tn_az-flag.gif

Azerbaijan

72.41

56

flags/tn_ge-flag.gif

Georgia

72.23

57

flags/tn_cn-flag.gif

China

72.06

58

flags/tn_am-flag.gif

Armenia

71.79

59

flags/tn_kz-flag.gif

Kazakhstan

71.64

60

flags/tn_tn-flag.gif

Tunisia

71.44

61

flags/tn_br-flag.gif

Brazil

71.34

62

flags/tn_fj-flag.gif

Fiji

71.24

63

flags/tn_pe-flag.gif

Peru

71.09

64

flags/tn_al-flag.gif

Albania

71.02

65

flags/tn_my-flag.gif

Malaysia

70.88

66

flags/tn_dz-flag.gif

Algeria

70.86

67

flags/tn_do-flag.gif

Dominican Republic

70.76

68

flags/tn_co-flag.gif

Colombia

70.56

69

flags/tn_ma-flag.gif

Morocco

70.53

70

flags/tn_tr-flag.gif

Turkey

70.38

71

flags/tn_ae-flag.gif

United Arab Emirates

70.17

72

flags/tn_jo-flag.gif

Jordan

70.14

73

flags/tn_om-flag.gif

Oman

70.13

74

flags/tn_ir-flag.gif

Iran, Islamic Rep.

70.01

75

flags/tn_bt-flag.gif

Bhutan

69.98

76

flags/tn_sg-flag.gif

Singapore

69.89

77

flags/tn_uz-flag.gif

Uzbekistan

69.84

78

flags/tn_tj-flag.gif

Tajikistan

69.76

79

flags/tn_mv-flag.gif

Maldives

69.27

80

flags/tn_mx-flag.gif

Mexico

69.13

81

flags/tn_jm-flag.gif

Jamaica

68.97

82

flags/tn_eg-flag.gif

Egypt, Arab Rep.

68.65

83

flags/tn_bb-flag.gif

Barbados

68.45

84

flags/tn_bn-flag.gif

Brunei Darussalam

68.27

85

flags/tn_me-flag.gif

Montenegro

68.21

86

flags/tn_cv-flag.gif

Cabo Verde

68.14

87

flags/tn_lk-flag.gif

Sri Lanka

68.10

88

flags/tn_pa-flag.gif

Panama

67.98

89

flags/tn_sv-flag.gif

El Salvador

67.93

90

flags/tn_bo-flag.gif

Bolivia

67.60

91

flags/tn_sr-flag.gif

Suriname

66.98

92

flags/tn_py-flag.gif

Paraguay

66.94

93

flags/tn_lb-flag.gif

Lebanon

66.84

94

flags/tn_qa-flag.gif

Qatar

66.73

95

flags/tn_mu-flag.gif

Mauritius

66.71

96

flags/tn_np-flag.gif

Nepal

66.52

97

flags/tn_id-flag.gif

Indonesia

66.34

98

flags/tn_sa-flag.gif

Saudi Arabia

66.30

99

flags/tn_ni-flag.gif

Nicaragua

66.29

100

flags/tn_bh-flag.gif

Bahrain

66.06

101

flags/tn_mm-flag.gif

Myanmar

64.95

102

flags/tn_kh-flag.gif

Cambodia

64.54

103

flags/tn_ph-flag.gif

Philippines

64.51

104

flags/tn_bz-flag.gif

Belize

64.43

105

flags/tn_iq-flag.gif

Iraq

63.82

106

flags/tn_mn-flag.gif

Mongolia

63.79

107

flags/tn_za-flag.gif

South Africa

63.74

108

flags/tn_tt-flag.gif

Trinidad and Tobago

63.50

109

flags/tn_bd-flag.gif

Bangladesh

63.45

110

flags/tn_la-flag.gif

Lao PDR

63.01

111

flags/tn_ga-flag.gif

Gabon

62.82

112

flags/tn_hn-flag.gif

Honduras

62.77

113

flags/tn_kw-flag.gif

Kuwait

62.54

114

flags/tn_gh-flag.gif

Ghana

62.49

115

flags/tn_bw-flag.gif

Botswana

61.92

116

flags/tn_na-flag.gif

Namibia

61.77

117

flags/tn_tm-flag.gif

Turkmenistan

61.14

118

flags/tn_ke-flag.gif

Kenya

60.60

119

flags/tn_vu-flag.gif

Vanuatu

60.52

120

flags/tn_in-flag.gif

India

60.07

121

flags/tn_gt-flag.gif

Guatemala

59.91

122

flags/tn_ve-flag.gif

Venezuela, RB

59.32

123

flags/tn_gm-flag.gif

Gambia, The

59.26

124

flags/tn_st-flag.gif

Sao Tome and Principe

58.79

125

flags/tn_zw-flag.gif

Zimbabwe

58.66

126

flags/tn_sn-flag.gif

Senegal

58.43

127

flags/tn_sy-flag.gif

Syrian Arab Republic

58.01

128

flags/tn_gy-flag.gif

Guyana

57.89

129

flags/tn_pk-flag.gif

Pakistan

57.72

130

flags/tn_rw-flag.gif

Rwanda

57.58

131

flags/tn_ci-flag.gif

Cote d’Ivoire

57.56

132

flags/tn_tz-flag.gif

Tanzania

56.43

133

flags/tn_mr-flag.gif

Mauritania

55.51

134

flags/tn_cm-flag.gif

Cameroon

55.26

135

flags/tn_ls-flag.gif

Lesotho

54.59

136

flags/tn_et-flag.gif

Ethiopia

54.52

137

flags/tn_af-flag.gif

Afghanistan

53.93

138

flags/tn_dj-flag.gif

Djibouti

53.76

139

flags/tn_bf-flag.gif

Burkina Faso

53.51

140

flags/tn_ug-flag.gif

Uganda

53.46

141

flags/tn_zm-flag.gif

Zambia

53.39

142

flags/tn_sz-flag.gif

Eswatini

53.33

143

flags/tn_tg-flag.gif

Togo

53.23

144

flags/tn_cg-flag.gif

Congo, Rep.

52.95

145

flags/tn_ye-flag.gif

Yemen, Rep.

52.86

146

flags/tn_ml-flag.gif

Mali

52.16

147

flags/tn_bi-flag.gif

Burundi

51.80

148

flags/tn_sl-flag.gif

Sierra Leone

51.69

149

flags/tn_mw-flag.gif

Malawi

51.37

150

flags/tn_ht-flag.gif

Haiti

51.35

151

flags/tn_pg-flag.gif

Papua New Guinea

51.33

152

flags/tn_mz-flag.gif

Mozambique

51.05

153

flags/tn_gn-flag.gif

Guinea

50.96

154

flags/tn_ao-flag.gif

Angola

50.30

155

flags/tn_bj-flag.gif

Benin

49.87

156

flags/tn_ne-flag.gif

Niger

49.53

157

flags/tn_sd-flag.gif

Sudan

49.48

158

flags/tn_cd-flag.gif

Congo, Dem. Rep.

49.30

159

flags/tn_mg-flag.gif

Madagascar

49.01

160

flags/tn_ng-flag.gif

Nigeria

48.93

161

flags/tn_lr-flag.gif

Liberia

48.65

162

flags/tn_so-flag.gif

Somalia

45.61

163

flags/tn_td-flag.gif

Chad

40.90

164

flags/tn_ss-flag.gif

South Sudan

38.90

165

flags/tn_cf-flag.gif

Central African Republic

38.27

nan

flags/tn_ad-flag.gif

Andorra

nan

nan

flags/tn_ag-flag.gif

Antigua and Barbuda

nan

nan

flags/tn_bs-flag.gif

Bahamas, The

nan

nan

flags/tn_km-flag.gif

Comoros

nan

nan

flags/tn_dm-flag.gif

Dominica

nan

nan

flags/tn_er-flag.gif

Eritrea

nan

nan

flags/tn_fm-flag.gif

Micronesia, Fed. Sts.

nan

nan

flags/tn_gw-flag.gif

Guinea-Bissau

nan

nan

flags/tn_gq-flag.gif

Equatorial Guinea

nan

nan

flags/tn_gd-flag.gif

Grenada

nan

nan

flags/tn_ki-flag.gif

Kiribati

nan

nan

flags/tn_kn-flag.gif

St. Kitts and Nevis

nan

nan

flags/tn_ly-flag.gif

Libya

nan

nan

flags/tn_lc-flag.gif

St. Lucia

nan

nan

flags/tn_li-flag.gif

Liechtenstein

nan

nan

flags/tn_mc-flag.gif

Monaco

nan

nan

flags/tn_mh-flag.gif

Marshall Islands

nan

nan

flags/tn_nr-flag.gif

Nauru

nan

nan

flags/tn_pw-flag.gif

Palau

nan

nan

flags/tn_kp-flag.gif

Korea, Dem. Rep.

nan

nan

flags/tn_sb-flag.gif

Solomon Islands

nan

nan

flags/tn_sm-flag.gif

San Marino

nan

nan

flags/tn_sc-flag.gif

Seychelles

nan

nan

flags/tn_tl-flag.gif

Timor-Leste

nan

nan

flags/tn_to-flag.gif

Tonga

nan

nan

flags/tn_tv-flag.gif

Tuvalu

nan

nan

flags/tn_vc-flag.gif

St. Vincent and the Grenadines

nan

nan

flags/tn_ws-flag.gif

Samoa

nan

Spillover performance

Countries are ranked by their spillover score. Each country’s actions can have positive or negative effects on other countries’ abilities to achieve the SDGs. The Spillover Index assesses such spillovers along three dimensions: environmental & social impacts embodied into trade, economy & finance, and security. A higher score means that a country causes more positive and fewer negative spillover effects.

All regions

Rank

Flag

Country

Score

1

flags/tn_mm-flag.gif

Myanmar

99.99

2

flags/tn_sd-flag.gif

Sudan

99.99

3

flags/tn_so-flag.gif

Somalia

99.96

4

flags/tn_ss-flag.gif

South Sudan

99.94

5

flags/tn_td-flag.gif

Chad

99.82

6

flags/tn_bi-flag.gif

Burundi

99.77

7

flags/tn_md-flag.gif

Moldova

99.74

8

flags/tn_et-flag.gif

Ethiopia

99.72

9

flags/tn_pk-flag.gif

Pakistan

99.68

10

flags/tn_cf-flag.gif

Central African Republic

99.65

11

flags/tn_ht-flag.gif

Haiti

99.63

12

flags/tn_ml-flag.gif

Mali

99.57

13

flags/tn_cm-flag.gif

Cameroon

99.56

14

flags/tn_mz-flag.gif

Mozambique

99.54

15

flags/tn_sl-flag.gif

Sierra Leone

99.54

16

flags/tn_gn-flag.gif

Guinea

99.53

17

flags/tn_mg-flag.gif

Madagascar

99.52

18

flags/tn_ci-flag.gif

Cote d’Ivoire

99.49

19

flags/tn_cd-flag.gif

Congo, Dem. Rep.

99.40

20

flags/tn_bf-flag.gif

Burkina Faso

99.37

21

flags/tn_af-flag.gif

Afghanistan

99.34

22

flags/tn_bd-flag.gif

Bangladesh

99.33

23

flags/tn_ne-flag.gif

Niger

99.30

24

flags/tn_la-flag.gif

Lao PDR

99.22

25

flags/tn_ug-flag.gif

Uganda

99.21

26

flags/tn_np-flag.gif

Nepal

99.15

27

flags/tn_sn-flag.gif

Senegal

99.15

28

flags/tn_tg-flag.gif

Togo

99.14

29

flags/tn_mw-flag.gif

Malawi

99.08

30

flags/tn_ye-flag.gif

Yemen, Rep.

99.02

31

flags/tn_ng-flag.gif

Nigeria

98.93

32

flags/tn_in-flag.gif

India

98.90

33

flags/tn_rw-flag.gif

Rwanda

98.87

34

flags/tn_kh-flag.gif

Cambodia

98.85

35

flags/tn_bj-flag.gif

Benin

98.82

36

flags/tn_eg-flag.gif

Egypt, Arab Rep.

98.72

37

flags/tn_tz-flag.gif

Tanzania

98.50

38

flags/tn_iq-flag.gif

Iraq

98.35

39

flags/tn_zm-flag.gif

Zambia

98.33

40

flags/tn_sy-flag.gif

Syrian Arab Republic

98.33

41

flags/tn_ma-flag.gif

Morocco

98.26

42

flags/tn_dj-flag.gif

Djibouti

98.24

43

flags/tn_pg-flag.gif

Papua New Guinea

98.19

44

flags/tn_uz-flag.gif

Uzbekistan

98.09

45

flags/tn_zw-flag.gif

Zimbabwe

98.08

46

flags/tn_ni-flag.gif

Nicaragua

98.05

47

flags/tn_lr-flag.gif

Liberia

98.05

48

flags/tn_mr-flag.gif

Mauritania

97.95

49

flags/tn_ph-flag.gif

Philippines

97.92

50

flags/tn_gm-flag.gif

Gambia, The

97.90

51

flags/tn_bo-flag.gif

Bolivia

97.89

52

flags/tn_cg-flag.gif

Congo, Rep.

97.74

53

flags/tn_az-flag.gif

Azerbaijan

97.64

54

flags/tn_br-flag.gif

Brazil

97.57

55

flags/tn_tj-flag.gif

Tajikistan

97.50

56

flags/tn_dz-flag.gif

Algeria

97.49

57

flags/tn_gh-flag.gif

Ghana

97.45

58

flags/tn_ec-flag.gif

Ecuador

97.14

59

flags/tn_cu-flag.gif

Cuba

97.10

60

flags/tn_ao-flag.gif

Angola

97.02

61

flags/tn_pe-flag.gif

Peru

96.88

62

flags/tn_id-flag.gif

Indonesia

96.87

63

flags/tn_am-flag.gif

Armenia

96.68

64

flags/tn_by-flag.gif

Belarus

96.66

65

flags/tn_ve-flag.gif

Venezuela, RB

96.45

66

flags/tn_lk-flag.gif

Sri Lanka

96.37

67

flags/tn_vn-flag.gif

Vietnam

96.37

68

flags/tn_kg-flag.gif

Kyrgyz Republic

96.03

69

flags/tn_ir-flag.gif

Iran, Islamic Rep.

95.93

70

flags/tn_ba-flag.gif

Bosnia and Herzegovina

95.84

71

flags/tn_do-flag.gif

Dominican Republic

95.59

72

flags/tn_st-flag.gif

Sao Tome and Principe

95.57

73

flags/tn_mx-flag.gif

Mexico

95.46

74

flags/tn_cv-flag.gif

Cabo Verde

95.43

75

flags/tn_co-flag.gif

Colombia

95.19

76

flags/tn_ls-flag.gif

Lesotho

95.18

77

flags/tn_mn-flag.gif

Mongolia

94.89

78

flags/tn_ke-flag.gif

Kenya

94.89

79

flags/tn_hn-flag.gif

Honduras

94.82

80

flags/tn_kz-flag.gif

Kazakhstan

94.65

81

flags/tn_cn-flag.gif

China

94.62

82

flags/tn_ar-flag.gif

Argentina

94.54

83

flags/tn_vu-flag.gif

Vanuatu

94.49

84

flags/tn_al-flag.gif

Albania

94.34

85

flags/tn_tn-flag.gif

Tunisia

94.24

86

flags/tn_ua-flag.gif

Ukraine

93.98

87

flags/tn_bt-flag.gif

Bhutan

93.90

88

flags/tn_mk-flag.gif

North Macedonia

93.87

89

flags/tn_tr-flag.gif

Turkey

93.70

90

flags/tn_py-flag.gif

Paraguay

93.69

91

flags/tn_jm-flag.gif

Jamaica

93.64

92

flags/tn_bz-flag.gif

Belize

93.55

93

flags/tn_cl-flag.gif

Chile

93.24

94

flags/tn_fj-flag.gif

Fiji

93.19

95

flags/tn_ga-flag.gif

Gabon

93.04

96

flags/tn_uy-flag.gif

Uruguay

90.95

97

flags/tn_sv-flag.gif

El Salvador

90.82

98

flags/tn_ge-flag.gif

Georgia

90.73

99

flags/tn_sr-flag.gif

Suriname

90.59

100

flags/tn_tm-flag.gif

Turkmenistan

90.47

101

flags/tn_jo-flag.gif

Jordan

90.39

102

flags/tn_th-flag.gif

Thailand

88.68

103

flags/tn_za-flag.gif

South Africa

88.56

104

flags/tn_mv-flag.gif

Maldives

88.26

105

flags/tn_tt-flag.gif

Trinidad and Tobago

88.12

106

flags/tn_na-flag.gif

Namibia

87.54

107

flags/tn_gt-flag.gif

Guatemala

87.28

108

flags/tn_bg-flag.gif

Bulgaria

86.87

109

flags/tn_hr-flag.gif

Croatia

84.83

110

flags/tn_sz-flag.gif

Eswatini

84.81

111

flags/tn_ro-flag.gif

Romania

83.99

112

flags/tn_bh-flag.gif

Bahrain

83.92

113

flags/tn_pl-flag.gif

Poland

83.56

114

flags/tn_cr-flag.gif

Costa Rica

83.34

115

flags/tn_rs-flag.gif

Serbia

82.57

116

flags/tn_om-flag.gif

Oman

81.85

117

flags/tn_lb-flag.gif

Lebanon

81.16

118

flags/tn_bw-flag.gif

Botswana

80.63

119

flags/tn_ru-flag.gif

Russian Federation

80.51

120

flags/tn_hu-flag.gif

Hungary

80.03

121

flags/tn_bb-flag.gif

Barbados

78.83

122

flags/tn_my-flag.gif

Malaysia

77.77

123

flags/tn_pa-flag.gif

Panama

76.34

124

flags/tn_sk-flag.gif

Slovak Republic

75.04

125

flags/tn_qa-flag.gif

Qatar

73.00

126

flags/tn_gr-flag.gif

Greece

72.27

127

flags/tn_ee-flag.gif

Estonia

72.08

128

flags/tn_lv-flag.gif

Latvia

72.06

129

flags/tn_kr-flag.gif

Korea, Rep.

71.63

130

flags/tn_it-flag.gif

Italy

71.19

131

flags/tn_sa-flag.gif

Saudi Arabia

71.09

132

flags/tn_bn-flag.gif

Brunei Darussalam

70.94

133

flags/tn_nz-flag.gif

New Zealand

70.82

134

flags/tn_pt-flag.gif

Portugal

69.92

135

flags/tn_fi-flag.gif

Finland

69.84

136

flags/tn_il-flag.gif

Israel

69.63

137

flags/tn_me-flag.gif

Montenegro

69.31

138

flags/tn_jp-flag.gif

Japan

68.78

139

flags/tn_lt-flag.gif

Lithuania

68.38

140

flags/tn_cz-flag.gif

Czech Republic

67.80

141

flags/tn_se-flag.gif

Sweden

67.09

142

flags/tn_es-flag.gif

Spain

64.75

143

flags/tn_ca-flag.gif

Canada

64.07

144

flags/tn_au-flag.gif

Australia

63.92

145

flags/tn_cy-flag.gif

Cyprus

63.84

146

flags/tn_us-flag.gif

United States

62.14

147

flags/tn_be-flag.gif

Belgium

61.97

148

flags/tn_mt-flag.gif

Malta

61.38

149

flags/tn_si-flag.gif

Slovenia

60.76

150

flags/tn_dk-flag.gif

Denmark

60.51

151

flags/tn_de-flag.gif

Germany

60.37

152

flags/tn_is-flag.gif

Iceland

60.27

153

flags/tn_ie-flag.gif

Ireland

60.04

154

flags/tn_at-flag.gif

Austria

59.52

155

flags/tn_no-flag.gif

Norway

58.71

156

flags/tn_fr-flag.gif

France

55.89

157

flags/tn_gb-flag.gif

United Kingdom

54.12

158

flags/tn_mu-flag.gif

Mauritius

48.37

159

flags/tn_nl-flag.gif

Netherlands

47.02

160

flags/tn_kw-flag.gif

Kuwait

43.26

161

flags/tn_ch-flag.gif

Switzerland

41.66

162

flags/tn_ae-flag.gif

United Arab Emirates

38.82

163

flags/tn_lu-flag.gif

Luxembourg

31.03

164

flags/tn_gy-flag.gif

Guyana

30.00

165

flags/tn_sg-flag.gif

Singapore

20.55

166

flags/tn_ad-flag.gif

Andorra

nan

167

flags/tn_ag-flag.gif

Antigua and Barbuda

nan

168

flags/tn_bs-flag.gif

Bahamas, The

nan

169

flags/tn_km-flag.gif

Comoros

nan

170

flags/tn_dm-flag.gif

Dominica

nan

171

flags/tn_er-flag.gif

Eritrea

nan

172

flags/tn_fm-flag.gif

Micronesia, Fed. Sts.

nan

173

flags/tn_gw-flag.gif

Guinea-Bissau

nan

174

flags/tn_gq-flag.gif

Equatorial Guinea

nan

175

flags/tn_gd-flag.gif

Grenada

nan

176

flags/tn_ki-flag.gif

Kiribati

nan

177

flags/tn_kn-flag.gif

St. Kitts and Nevis

nan

178

flags/tn_ly-flag.gif

Libya

nan

179

flags/tn_lc-flag.gif

St. Lucia

nan

180

flags/tn_li-flag.gif

Liechtenstein

nan

181

flags/tn_mc-flag.gif

Monaco

nan

182

flags/tn_mh-flag.gif

Marshall Islands

nan

183

flags/tn_nr-flag.gif

Nauru

nan

184

flags/tn_pw-flag.gif

Palau

nan

185

flags/tn_kp-flag.gif

Korea, Dem. Rep.

nan

186

flags/tn_sb-flag.gif

Solomon Islands

nan

187

flags/tn_sm-flag.gif

San Marino

nan

188

flags/tn_sc-flag.gif

Seychelles

nan

189

flags/tn_tl-flag.gif

Timor-Leste

nan

190

flags/tn_to-flag.gif

Tonga

nan

191

flags/tn_tv-flag.gif

Tuvalu

nan

192

flags/tn_vc-flag.gif

St. Vincent and the Grenadines

nan

193

flags/tn_ws-flag.gif

Samoa

nan

Interactive map

Basic Statistical Visualization

(This tutorial is adapted from Vega-Lite’s documentation)

This tutorial will guide you through the basic process of creating visualizations in Altair. First, you will need to make sure you have the Altair package and its dependencies installed (see installation) and make sure you understand how altair plots are displayed (see displaying-charts). This tutorial will assume you are working within a Jupyter notebook user interface, so that plots are automatically rendered.

Here is the outline of this basic tutorial:

The Data

Data in Altair is built around the Pandas Dataframe. One of the defining characteristics of statistical visualization is that it begins with tidy Dataframes. For the purposes of this tutorial, we’ll start by importing Pandas and creating a simple DataFrame to visualize, with a categorical variable in column a and a numerical variable in column b:

import pandas as pd
data = pd.DataFrame({'a': list('CCCDDDEEE'),
                     'b': [2, 7, 4, 1, 2, 6, 8, 4, 7]})

When using Altair, datasets are most commonly provided as a Dataframe. As we will see, the labeled columns of the dataframe are an essential piece of plotting with Altair.

The Chart Object

The fundamental object in Altair is the Chart, which takes a dataframe as a single argument:

import altair as alt
chart = alt.Chart(data)

So far, we have defined the Chart object, but we have not yet told the chart to do anything with the data. That will come next.

Encodings and Marks

With this chart object in hand, we can now specify how we would like the data to be visualized. This is done via the mark attribute of the chart object, which is most conveniently accessed via the Chart.mark_* methods. For example, we can show the data as a point using mark_point():

alt.Chart(data).mark_point()

Here the rendering consists of one point per row in the dataset, all plotted on top of each other, since we have not yet specified positions for these points.

To visually separate the points, we can map various encoding channels, or channels for short, to columns in the dataset. For example, we could encode the variable a of the data with the x channel, which represents the x-axis position of the points. This can be done straightforwardly via the Chart.encode() method:

alt.Chart(data).mark_point().encode(
    x='a',
)

The encode() method builds a key-value mapping between encoding channels (such as x, y, color, shape, size, etc.) to columns in the dataset, accessed by column name.

For pandas dataframes, Altair automatically determines the appropriate data type for the mapped column, which in this case is a nominal value, or an unordered categorical.

Though we’ve now separated the data by one attribute, we still have multiple points overlapping within each category. Let’s further separate these by adding a y encoding channel, mapped to the "b" column:

alt.Chart(data).mark_point().encode(
    x='a',
    y='b'
)

The type of the data in the "b" column is again automatically-inferred by Altair, and this time is treated as a quantitative type (i.e. real-valued). Additionally, we see that grid lines and appropriate axis titles are automatically added as well.

Data Transformation: Aggregation

To allow for more flexibility in how data are visualized, Altair has a built-in syntax for aggregation of data. For example, we can compute the average of all values by specifying this aggregate within the column identifier:

alt.Chart(data).mark_point().encode(
    x='a',
    y='average(b)'
)

Now within each x-axis category, we see a single point reflecting the average of the values within that category.

Typically, aggregated values are not represented by point markings, but by bar markings. We can do this by replacing mark_point() with mark_bar():

alt.Chart(data).mark_bar().encode(
    x='a',
    y='average(b)'
)

Because the categorical feature is mapped to the x-axis, the result is a vertical bar chart. To get a horizontal bar chart, all we need is to swap the x and y keywords:

alt.Chart(data).mark_bar().encode(
    y='a',
    x='average(b)'
)

Aside: Examining the JSON Output

Recall that Altair’s main purpose is to convert plot specifications to a JSON string that conforms to the Vega-Lite schema. It is instructive here to use the to_json() method to inspect the JSON specification that Altair is exporting and sending as JSON to Vega-Lite:

chart = alt.Chart(data).mark_bar().encode(
    x='a',
    y='average(b)',
)
print(chart.to_json())
{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.17.0.json",
  "config": {
    "view": {
      "continuousHeight": 300,
      "continuousWidth": 400
    }
  },
  "data": {
    "name": "data-347f1284ea3247c0f55cb966abbdd2d8"
  },
  "datasets": {
    "data-347f1284ea3247c0f55cb966abbdd2d8": [
      {
        "a": "C",
        "b": 2
      },
      {
        "a": "C",
        "b": 7
      },
      {
        "a": "C",
        "b": 4
      },
      {
        "a": "D",
        "b": 1
      },
      {
        "a": "D",
        "b": 2
      },
      {
        "a": "D",
        "b": 6
      },
      {
        "a": "E",
        "b": 8
      },
      {
        "a": "E",
        "b": 4
      },
      {
        "a": "E",
        "b": 7
      }
    ]
  },
  "encoding": {
    "x": {
      "field": "a",
      "type": "nominal"
    },
    "y": {
      "aggregate": "average",
      "field": "b",
      "type": "quantitative"
    }
  },
  "mark": "bar"
}

Notice here that encode(x='a') has been expanded to a JSON structure with a field name, and a type for the data. The encode(y='b') has been expanded similarly and includes an aggregate field.

Altair’s full shorthand syntax includes a way to specify the type of the column as well:

y = alt.Y('average(b):Q')
print(y.to_json())
{
  "aggregate": "average",
  "field": "b",
  "type": "quantitative"
}

This short-hand is equivalent to spelling-out the attributes by name:

y = alt.Y(field='b', type='quantitative', aggregate='average')
print(y.to_json())

This more verbose means of specifying channels can be used directly in Altair chart specifications, a fact that becomes useful when using some of the more advanced field configurations:

alt.Chart(data).mark_bar().encode(
    alt.Y('a', type='nominal'),
    alt.X('b', type='quantitative', aggregate='average')
)

Customizing your Visualization

By default, Altair via Vega-Lite makes some choices about default properties of the visualization. Altair also provides an API to customize the look of the visualization. For example, we can specify the axis titles using the axis attribute of channel classes, and we can specify the color of the marking by setting the color keyword of the Chart.mark_* methods to any valid HTML color string:

alt.Chart(data).mark_bar(color='firebrick').encode(
    alt.Y('a', title='category'),
    alt.X('average(b)', title='avg(b) by category')
)

Publishing your Visualization

Once you have visualized your data, perhaps you would like to publish it somewhere on the web. This can be done straightforwardly using the Vega-Embed Javascript package. A simple example of a stand-alone HTML document can be generated for any chart using the Chart.save() method:

chart = alt.Chart(data).mark_bar().encode(
    x='a',
    y='average(b)',
)
chart.save('chart.html')

The basic HTML template produces output that looks like this, where the JSON specification for your plot produced by Chart.to_json() should be stored in the spec Javascript variable:

<!DOCTYPE html>
<html>
  <head>
    <script src="https://cdn.jsdelivr.net/npm/vega@3"></script>
    <script src="https://cdn.jsdelivr.net/npm/vega-lite@2"></script>
    <script src="https://cdn.jsdelivr.net/npm/vega-embed@3"></script>
  </head>
  <body>
    <div id="vis"></div>
    <script type="text/javascript">
      var spec = {};  /* JSON dump of your chart's spec */
      var opt = {"renderer": "canvas", "actions": false};  /* Options for the embedding */
      vegaEmbed("#vis", spec, opt);
    </script>
  </body>
</html>

The save() method provides a convenient way to save such HTML output to file. For more information on embedding Altair/Vega-Lite, see the documentation of the Vega-Embed project.

Basic Statistical Visualization

(This tutorial is adapted from Vega-Lite’s documentation)

This tutorial will guide you through the basic process of creating visualizations in Altair. First, you will need to make sure you have the Altair package and its dependencies installed (see installation) and make sure you understand how altair plots are displayed (see displaying-charts). This tutorial will assume you are working within a Jupyter notebook user interface, so that plots are automatically rendered.

Here is the outline of this basic tutorial:

The Data

Data in Altair is built around the Pandas Dataframe. One of the defining characteristics of statistical visualization is that it begins with tidy Dataframes. For the purposes of this tutorial, we’ll start by importing Pandas and creating a simple DataFrame to visualize, with a categorical variable in column a and a numerical variable in column b:

import pandas as pd
data = pd.DataFrame({'a': list('CCCDDDEEE'),
                     'b': [2, 7, 4, 1, 2, 6, 8, 4, 7]})

When using Altair, datasets are most commonly provided as a Dataframe. As we will see, the labeled columns of the dataframe are an essential piece of plotting with Altair.

The Chart Object

The fundamental object in Altair is the Chart, which takes a dataframe as a single argument:

import altair as alt
chart = alt.Chart(data)

So far, we have defined the Chart object, but we have not yet told the chart to do anything with the data. That will come next.

Encodings and Marks

With this chart object in hand, we can now specify how we would like the data to be visualized. This is done via the mark attribute of the chart object, which is most conveniently accessed via the Chart.mark_* methods. For example, we can show the data as a point using mark_point():

alt.Chart(data).mark_point()

Here the rendering consists of one point per row in the dataset, all plotted on top of each other, since we have not yet specified positions for these points.

To visually separate the points, we can map various encoding channels, or channels for short, to columns in the dataset. For example, we could encode the variable a of the data with the x channel, which represents the x-axis position of the points. This can be done straightforwardly via the Chart.encode() method:

alt.Chart(data).mark_point().encode(
    x='a',
)

The encode() method builds a key-value mapping between encoding channels (such as x, y, color, shape, size, etc.) to columns in the dataset, accessed by column name.

For pandas dataframes, Altair automatically determines the appropriate data type for the mapped column, which in this case is a nominal value, or an unordered categorical.

Though we’ve now separated the data by one attribute, we still have multiple points overlapping within each category. Let’s further separate these by adding a y encoding channel, mapped to the "b" column:

alt.Chart(data).mark_point().encode(
    x='a',
    y='b'
)

The type of the data in the "b" column is again automatically-inferred by Altair, and this time is treated as a quantitative type (i.e. real-valued). Additionally, we see that grid lines and appropriate axis titles are automatically added as well.

Data Transformation: Aggregation

To allow for more flexibility in how data are visualized, Altair has a built-in syntax for aggregation of data. For example, we can compute the average of all values by specifying this aggregate within the column identifier:

alt.Chart(data).mark_point().encode(
    x='a',
    y='average(b)'
)

Now within each x-axis category, we see a single point reflecting the average of the values within that category.

Typically, aggregated values are not represented by point markings, but by bar markings. We can do this by replacing mark_point() with mark_bar():

alt.Chart(data).mark_bar().encode(
    x='a',
    y='average(b)'
)

Because the categorical feature is mapped to the x-axis, the result is a vertical bar chart. To get a horizontal bar chart, all we need is to swap the x and y keywords:

alt.Chart(data).mark_bar().encode(
    y='a',
    x='average(b)'
)

Aside: Examining the JSON Output

Recall that Altair’s main purpose is to convert plot specifications to a JSON string that conforms to the Vega-Lite schema. It is instructive here to use the to_json() method to inspect the JSON specification that Altair is exporting and sending as JSON to Vega-Lite:

chart = alt.Chart(data).mark_bar().encode(
    x='a',
    y='average(b)',
)
print(chart.to_json())
{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.17.0.json",
  "config": {
    "view": {
      "continuousHeight": 300,
      "continuousWidth": 400
    }
  },
  "data": {
    "name": "data-347f1284ea3247c0f55cb966abbdd2d8"
  },
  "datasets": {
    "data-347f1284ea3247c0f55cb966abbdd2d8": [
      {
        "a": "C",
        "b": 2
      },
      {
        "a": "C",
        "b": 7
      },
      {
        "a": "C",
        "b": 4
      },
      {
        "a": "D",
        "b": 1
      },
      {
        "a": "D",
        "b": 2
      },
      {
        "a": "D",
        "b": 6
      },
      {
        "a": "E",
        "b": 8
      },
      {
        "a": "E",
        "b": 4
      },
      {
        "a": "E",
        "b": 7
      }
    ]
  },
  "encoding": {
    "x": {
      "field": "a",
      "type": "nominal"
    },
    "y": {
      "aggregate": "average",
      "field": "b",
      "type": "quantitative"
    }
  },
  "mark": "bar"
}

Notice here that encode(x='a') has been expanded to a JSON structure with a field name, and a type for the data. The encode(y='b') has been expanded similarly and includes an aggregate field.

Altair’s full shorthand syntax includes a way to specify the type of the column as well:

y = alt.Y('average(b):Q')
print(y.to_json())
{
  "aggregate": "average",
  "field": "b",
  "type": "quantitative"
}

This short-hand is equivalent to spelling-out the attributes by name:

y = alt.Y(field='b', type='quantitative', aggregate='average')
print(y.to_json())

This more verbose means of specifying channels can be used directly in Altair chart specifications, a fact that becomes useful when using some of the more advanced field configurations:

alt.Chart(data).mark_bar().encode(
    alt.Y('a', type='nominal'),
    alt.X('b', type='quantitative', aggregate='average')
)

Customizing your Visualization

By default, Altair via Vega-Lite makes some choices about default properties of the visualization. Altair also provides an API to customize the look of the visualization. For example, we can specify the axis titles using the axis attribute of channel classes, and we can specify the color of the marking by setting the color keyword of the Chart.mark_* methods to any valid HTML color string:

alt.Chart(data).mark_bar(color='firebrick').encode(
    alt.Y('a', title='category'),
    alt.X('average(b)', title='avg(b) by category')
)

Publishing your Visualization

Once you have visualized your data, perhaps you would like to publish it somewhere on the web. This can be done straightforwardly using the Vega-Embed Javascript package. A simple example of a stand-alone HTML document can be generated for any chart using the Chart.save() method:

chart = alt.Chart(data).mark_bar().encode(
    x='a',
    y='average(b)',
)
chart.save('chart.html')

The basic HTML template produces output that looks like this, where the JSON specification for your plot produced by Chart.to_json() should be stored in the spec Javascript variable:

<!DOCTYPE html>
<html>
  <head>
    <script src="https://cdn.jsdelivr.net/npm/vega@3"></script>
    <script src="https://cdn.jsdelivr.net/npm/vega-lite@2"></script>
    <script src="https://cdn.jsdelivr.net/npm/vega-embed@3"></script>
  </head>
  <body>
    <div id="vis"></div>
    <script type="text/javascript">
      var spec = {};  /* JSON dump of your chart's spec */
      var opt = {"renderer": "canvas", "actions": false};  /* Options for the embedding */
      vegaEmbed("#vis", spec, opt);
    </script>
  </body>
</html>

The save() method provides a convenient way to save such HTML output to file. For more information on embedding Altair/Vega-Lite, see the documentation of the Vega-Embed project.

Bug Reports & Questions

SDG is Apache-licensed and the source is available on GitHub. If any questions or issues come up as you use Altair, please get in touch via Git Issues.

Indexes y tables