Skip to content

Instantly share code, notes, and snippets.

@tachycline
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tachycline/9419562 to your computer and use it in GitHub Desktop.
Save tachycline/9419562 to your computer and use it in GitHub Desktop.
Corruption vs Democracy chart

Yesterday on twitter, @DataRemixed and @albertocairo (among others) got into a discussion of a blog post by @ken_mke about governmental instability in Ukraine. I liked the post, and the visualization, and it got me thinking about other areas of the world. I downloaded the data, cleaned it a bit, and put together this little exploratory tool.

##Some comments about the data: I'm not a political scientist, but I think @ken_mke makes a reasonably compelling argument. What's especially interesting to me, looking at the countries of the world broken up by region, is what patterns emerge. For example:

  • The least authoritarian Middle Eastern states are more or less comparable to the most authoritarian European states (barring a few outliers).
  • For that matter, the lower right quadrant is occupied almost exclusively by Middle-eastern states.
  • Nearly all of Central America and the Carribean lies in the unstable quadrant.
  • Authoritarianism is at best a pretty imperfect protection against unrest. The collection of countries in the lower left corner (most corrupt, most authoritarian) all have significant unrest going on, with the exception of North Korea.

##Some comments about the process: People don't agree about lists of countries. I suppose I knew this, but hadn't tried to do this kind of visualization before, so it hadn't registered. Even when people do agree that a country should be included, they can disagree about what it should be called. Again, not a shocking revelation, but something I had to deal with in cleaning the data.

While I like pdfs for reading, they're a lousy way to transport a data set. In a perfect world, data sets would all be downloadable in a nice, machine parseable format. That is not the world we live in.

###Resources:

Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
corrrank country corruption score surveys used ci:lower ci: upper 2012 score
175 Afghanistan 8 3 3 13 8
116 Albania 31 7 28 34 33
94 Algeria 36 6 31 41 34
153 Angola 23 7 18 28 22
106 Argentina 34 8 30 38 35
94 Armenia 36 6 30 42 34
9 Australia 81 8 79 83 85
26 Austria 69 8 64 74 69
127 Azerbaijan 28 6 22 34 27
57 Bahrain 48 5 39 57 51
136 Bangladesh 27 7 20 34 26
15 Barbados 75 3 63 87 76
123 Belarus 29 5 22 36 31
15 Belgium 75 7 71 79 75
94 Benin 36 6 30 42 36
31 Bhutan 63 4 59 67 63
106 Bolivia 34 7 28 40 34
72 Bosnia and Herzegovina 42 7 37 47 42
30 Botswana 64 7 61 67 65
72 Brazil 42 8 36 48 43
38 Brunei 60 3 43 77 55
77 Bulgaria 41 9 36 46 41
83 Burkina Faso 38 7 32 44 38
157 Burundi 21 5 17 25 19
160 Cambodia 20 7 15 25 22
144 Cameroon 25 8 20 30 26
9 Canada 81 7 77 85 84
41 Cape Verde 58 4 50 66 60
144 Central African Republic 25 4 16 34 26
163 Chad 19 5 13 25 19
22 Chile 71 9 68 74 72
80 China 40 9 35 45 39
94 Colombia 36 7 33 39 36
127 Comoros 28 3 16 40 28
49 Costa Rica 53 5 46 60 54
57 Croatia 48 9 43 53 46
63 Cuba 46 4 39 53 48
31 Cyprus 63 5 57 69 66
57 Czech Republic 48 10 43 53 49
154 Democratic Republic of the Congo 22 5 15 29 21
1 Denmark 91 7 87 95 90
94 Djibouti 36 3 22 50 36
41 Dominica 58 3 54 62 58
123 Dominican Republic 29 6 23 35 32
119 East Timor 30 3 25 35 33
102 Ecuador 35 6 29 41 32
114 Egypt 32 7 27 37 32
83 El Salvador 38 6 35 41 38
163 Equatorial Guinea 19 3 15 23 20
160 Eritrea 20 4 2 38 25
28 Estonia 68 9 64 72 64
111 Ethiopia 33 8 29 37 33
3 Finland 89 7 86 92 90
22 France 71 8 67 75 71
106 Gabon 34 5 32 36 35
127 Gambia 28 5 17 39 34
55 Georgia 49 6 38 60 52
12 Germany 78 8 74 82 79
63 Ghana 46 9 41 51 45
80 Greece 40 7 33 47 36
123 Guatemala 29 6 25 33 33
150 Guinea 24 7 18 30 24
163 Guinea Bissau 19 4 15 23 25
136 Guyana 27 4 22 32 28
163 Haiti 19 5 14 24 19
140 Honduras 26 6 22 30 28
15 Hong Kong 75 8 71 79 77
47 Hungary 54 10 48 60 55
12 Iceland 78 6 73 83 82
94 India 36 10 32 40 36
114 Indonesia 32 9 26 38 32
144 Iran 25 6 19 31 28
171 Iraq 16 4 12 20 18
21 Ireland 72 6 65 79 69
36 Israel 61 6 58 64 60
69 Italy 43 7 39 47 42
136 Ivory Coast 27 8 23 31 29
83 Jamaica 38 6 35 41 38
18 Japan 74 9 70 78 74
66 Jordan 45 7 41 49 48
140 Kazakhstan 26 8 21 31 28
136 Kenya 27 8 23 31 27
111 Kosovo 33 3 29 37 34
69 Kuwait 43 5 37 49 44
150 Kyrgyzstan 24 6 20 28 24
140 Laos 26 4 18 34 21
49 Latvia 53 8 47 59 49
127 Lebanon 28 6 23 33 30
55 Lesotho 49 5 43 55 45
83 Liberia 38 7 33 43 41
172 Libya 15 6 10 20 21
43 Lithuania 57 8 51 63 54
11 Luxembourg 80 6 75 85 80
67 Macedonia FYR 44 6 36 52 43
127 Madagascar 28 8 25 31 32
91 Malawi 37 8 34 40 37
53 Malaysia 50 9 44 56 49
127 Mali 28 6 23 33 34
45 Malta 56 5 52 60 57
119 Mauritania 30 5 23 37 31
52 Mauritius 52 5 50 54 57
106 Mexico 34 9 31 37 34
102 Moldova 35 8 30 40 36
83 Mongolia 38 7 34 42 36
67 Montenegro 44 4 40 48 41
91 Morocco 37 8 32 42 37
119 Mozambique 30 7 27 33 31
157 Myanmar 21 6 15 27 15
57 Namibia 48 6 42 54 48
116 Nepal 31 5 29 33 27
8 Netherlands 83 7 80 86 84
1 New Zealand 91 7 87 95 90
127 Nicaragua 28 7 24 32 29
106 Niger 34 5 28 40 33
144 Nigeria 25 9 20 30 27
175 North Korea 8 3 2 14 8
5 Norway 86 7 82 90 85
61 Oman 47 5 34 60 47
127 Pakistan 28 8 23 33 27
102 Panama 35 6 31 39 38
144 Papua New Guinea 25 5 18 32 25
150 Paraguay 24 5 19 29 25
83 Peru 38 7 34 42 38
94 Philippines 36 9 32 40 34
38 Poland 60 10 56 64 58
33 Portugal 62 7 57 67 63
33 Puerto Rico 62 3 52 72 63
28 Qatar 68 6 56 80 68
154 Republic of Congo 22 6 16 28 26
69 Romania 43 9 38 48 44
127 Russia 28 9 24 32 28
49 Rwanda 53 5 44 62 53
22 Saint Lucia 71 3 70 72 71
33 Saint Vincent and the Grenadines 62 3 53 71 62
72 Sao Tome and Principe 42 3 34 50 42
63 Saudi Arabia 46 5 35 57 44
77 Senegal 41 9 39 43 36
72 Serbia 42 7 36 48 39
47 Seychelles 54 4 41 67 52
119 Sierra Leone 30 8 26 34 31
5 Singapore 86 9 82 90 87
61 Slovakia 47 8 39 55 46
43 Slovenia 57 9 51 63 61
175 Somalia 8 4 5 11 8
72 South Africa 42 9 37 47 43
46 South Korea 55 10 51 59 56
173 South Sudan 14 3 11 17 0
40 Spain 59 7 51 67 65
91 Sri Lanka 37 7 34 40 40
174 Sudan 11 6 5 17 13
94 Suriname 36 3 31 41 37
82 Swaziland 39 4 36 42 37
3 Sweden 89 7 85 93 88
7 Switzerland 85 6 81 89 86
168 Syria 17 4 11 23 26
36 Taiwan 61 7 54 68 61
154 Tajikistan 22 5 16 28 22
111 Tanzania 33 8 29 37 35
102 Thailand 35 8 33 37 37
22 The Bahamas 71 3 69 73 71
123 Togo 29 5 23 35 30
83 Trinidad and Tobago 38 4 30 46 39
77 Tunisia 41 7 38 44 41
53 Turkey 50 9 46 54 49
168 Turkmenistan 17 3 12 22 17
140 Uganda 26 8 21 31 29
144 Ukraine 25 8 22 28 26
26 United Arab Emirates 69 7 61 77 68
14 United Kingdom 76 8 74 78 74
19 United States of America 73 9 66 80 73
19 Uruguay 73 6 71 75 72
168 Uzbekistan 17 6 14 20 17
160 Venezuela 20 7 16 24 19
116 Vietnam 31 8 27 35 31
167 Yemen 18 6 14 22 23
83 Zambia 38 8 35 41 37
157 Zimbabwe 21 8 14 28 20
Country name Geographic Region
Afghanistan Middle East, North Africa, and Greater Arabia
Albania Europe
Algeria Middle East, North Africa, and Greater Arabia
Andorra Europe
Angola Sub-saharan Africa
Antigua and Barbuda Central America and the Carribean
Argentina South America
Armenia Europe
Austria Europe
Australia Australia and Oceania
Azerbaijan Middle East, North Africa, and Greater Arabia
Bahrain Middle East, North Africa, and Greater Arabia
Bangladesh Asia
Barbados Central America and the Carribean
Belarus Europe
Belgium Europe
Belize Central America and the Carribean
Benin Sub-saharan Africa
Bhutan Asia
Bolivia South America
Bosnia and Herzegovina Europe
Botswana Sub-saharan Africa
Brazil South America
Brunei Asia
Bulgaria Europe
Burkina Faso Sub-saharan Africa
Burundi Sub-saharan Africa
Cambodia Asia
Cameroon Sub-saharan Africa
Canada North America
Cape Verde Sub-saharan Africa
Central African Republic Sub-saharan Africa
Chad Sub-saharan Africa
Chile South America
China Asia
Colombia South America
Comoros Sub-saharan Africa
Costa Rica Central America and the Carribean
Ivory Coast Sub-saharan Africa
Croatia Europe
Cuba Central America and the Carribean
Cyprus Europe
Czech Republic Europe
Democratic Republic of the Congo Sub-saharan Africa
Denmark Europe
Djibouti Sub-saharan Africa
Dominica Central America and the Carribean
Dominican Republic Central America and the Carribean
East Timor Australia and Oceania
Ecuador South America
Egypt Middle East, North Africa, and Greater Arabia
El Salvador Central America and the Carribean
Equatorial Guinea Sub-saharan Africa
Eritrea Sub-saharan Africa
Estonia Europe
Ethiopia Sub-saharan Africa
Federated States of Micronesia Australia and Oceania
Fiji Australia and Oceania
Finland Europe
France Europe
Gabon Sub-saharan Africa
Georgia Europe
Germany Europe
Ghana Sub-saharan Africa
Greece Europe
Grenada Central America and the Carribean
Guatemala Central America and the Carribean
Guinea Sub-saharan Africa
Guinea Bissau Sub-saharan Africa
Guyana South America
Haiti Central America and the Carribean
Honduras Central America and the Carribean
Hungary Europe
Iceland Europe
India Asia
Indonesia Asia
Iran Middle East, North Africa, and Greater Arabia
Iraq Middle East, North Africa, and Greater Arabia
Ireland Europe
Israel Middle East, North Africa, and Greater Arabia
Italy Europe
Jamaica Central America and the Carribean
Japan Asia
Jordan Middle East, North Africa, and Greater Arabia
Kazakhstan Asia
Kenya Sub-saharan Africa
Kiribati Australia and Oceania
Kosovo Europe
Kuwait Middle East, North Africa, and Greater Arabia
Kyrgyzstan Asia
Laos Asia
Latvia Europe
Lebanon Middle East, North Africa, and Greater Arabia
Lesotho Sub-saharan Africa
Liberia Sub-saharan Africa
Libya Middle East, North Africa, and Greater Arabia
Liechtenstein Europe
Lithuania Europe
Luxembourg Europe
Macedonia FYR Europe
Madagascar Sub-saharan Africa
Malawi Sub-saharan Africa
Malaysia Asia
Maldives Asia
Mali Sub-saharan Africa
Malta Europe
Marshall Islands Australia and Oceania
Mauritania Sub-saharan Africa
Mauritius Sub-saharan Africa
Mexico North America
Moldova Europe
Monaco Europe
Mongolia Asia
Montenegro Europe
Morocco Middle East, North Africa, and Greater Arabia
Mozambique Sub-saharan Africa
Myanmar Asia
Namibia Sub-saharan Africa
Nauru Australia and Oceania
Nepal Asia
Netherlands Europe
New Zealand Australia and Oceania
Nicaragua Central America and the Carribean
Niger Sub-saharan Africa
Nigeria Sub-saharan Africa
North Korea Asia
Norway Europe
Oman Middle East, North Africa, and Greater Arabia
Pakistan Middle East, North Africa, and Greater Arabia
Palau Australia and Oceania
Panama Central America and the Carribean
Papua New Guinea Australia and Oceania
Paraguay South America
Peru South America
Philippines Asia
Poland Europe
Portugal Europe
Qatar Middle East, North Africa, and Greater Arabia
Republic of Congo Sub-saharan Africa
Romania Europe
Russia Europe
Rwanda Sub-saharan Africa
Saint Kitts and Nevis Central America and the Carribean
Saint Lucia Central America and the Carribean
Saint Vincent and the Grenadines Central America and the Carribean
Samoa Australia and Oceania
San Marino Europe
Sao Tome and Principe Sub-saharan Africa
Saudi Arabia Middle East, North Africa, and Greater Arabia
Senegal Sub-saharan Africa
Serbia Europe
Seychelles Sub-saharan Africa
Sierra Leone Sub-saharan Africa
Singapore Asia
Slovakia Europe
Slovenia Europe
Solomon Islands Australia and Oceania
Somalia Middle East, North Africa, and Greater Arabia
South Africa Sub-saharan Africa
South Korea Asia
South Sudan Sub-saharan Africa
Spain Europe
Sri Lanka Asia
Sudan Sub-saharan Africa
Suriname South America
Swaziland Sub-saharan Africa
Sweden Europe
Switzerland Europe
Syria Middle East, North Africa, and Greater Arabia
Taiwan Asia
Tajikistan Asia
Tanzania Sub-saharan Africa
Thailand Asia
The Bahamas Central America and the Carribean
Gambia Sub-saharan Africa
Togo Sub-saharan Africa
Tonga Australia and Oceania
Trinidad and Tobago Central America and the Carribean
Tunisia Middle East, North Africa, and Greater Arabia
Turkey Middle East, North Africa, and Greater Arabia
Turkmenistan Asia
Tuvalu Australia and Oceania
Uganda Sub-saharan Africa
Ukraine Europe
United Arab Emirates Middle East, North Africa, and Greater Arabia
United Kingdom Europe
United States of America North America
Uruguay South America
Uzbekistan Asia
Vanuatu Australia and Oceania
Vatican City Europe
Venezuela South America
Vietnam Asia
Yemen Middle East, North Africa, and Greater Arabia
Zambia Sub-saharan Africa
Zimbabwe Sub-saharan Africa
[{"democracy":2.48,"corruption":8.0,"region":"Middle East, North Africa, and Greater Arabia","country":"Afghanistan"},{"democracy":5.67,"corruption":31.0,"region":"Europe","country":"Albania"},{"democracy":3.83,"corruption":36.0,"region":"Middle East, North Africa, and Greater Arabia","country":"Algeria"},{"democracy":3.35,"corruption":23.0,"region":"Sub-saharan Africa","country":"Angola"},{"democracy":6.84,"corruption":34.0,"region":"South America","country":"Argentina"},{"democracy":4.09,"corruption":36.0,"region":"Europe","country":"Armenia"},{"democracy":9.22,"corruption":81.0,"region":"Australia and Oceania","country":"Australia"},{"democracy":8.62,"corruption":69.0,"region":"Europe","country":"Austria"},{"democracy":3.15,"corruption":28.0,"region":"Middle East, North Africa, and Greater Arabia","country":"Azerbaijan"},{"democracy":2.53,"corruption":48.0,"region":"Middle East, North Africa, and Greater Arabia","country":"Bahrain"},{"democracy":5.86,"corruption":27.0,"region":"Asia","country":"Bangladesh"},{"democracy":3.04,"corruption":29.0,"region":"Europe","country":"Belarus"},{"democracy":8.05,"corruption":75.0,"region":"Europe","country":"Belgium"},{"democracy":6.0,"corruption":36.0,"region":"Sub-saharan Africa","country":"Benin"},{"democracy":4.65,"corruption":63.0,"region":"Asia","country":"Bhutan"},{"democracy":5.84,"corruption":34.0,"region":"South America","country":"Bolivia"},{"democracy":5.11,"corruption":42.0,"region":"Europe","country":"Bosnia and Herzegovina"},{"democracy":7.85,"corruption":64.0,"region":"Sub-saharan Africa","country":"Botswana"},{"democracy":7.12,"corruption":42.0,"region":"South America","country":"Brazil"},{"democracy":6.72,"corruption":41.0,"region":"Europe","country":"Bulgaria"},{"democracy":3.52,"corruption":38.0,"region":"Sub-saharan Africa","country":"Burkina Faso"},{"democracy":3.6,"corruption":21.0,"region":"Sub-saharan Africa","country":"Burundi"},{"democracy":4.96,"corruption":20.0,"region":"Asia","country":"Cambodia"},{"democracy":3.44,"corruption":25.0,"region":"Sub-saharan Africa","country":"Cameroon"},{"democracy":9.08,"corruption":81.0,"region":"North America","country":"Canada"},{"democracy":7.92,"corruption":58.0,"region":"Sub-saharan Africa","country":"Cape Verde"},{"democracy":1.99,"corruption":25.0,"region":"Sub-saharan Africa","country":"Central African Republic"},{"democracy":1.62,"corruption":19.0,"region":"Sub-saharan Africa","country":"Chad"},{"democracy":7.54,"corruption":71.0,"region":"South America","country":"Chile"},{"democracy":3.0,"corruption":40.0,"region":"Asia","country":"China"},{"democracy":6.63,"corruption":36.0,"region":"South America","country":"Colombia"},{"democracy":3.52,"corruption":28.0,"region":"Sub-saharan Africa","country":"Comoros"},{"democracy":8.1,"corruption":53.0,"region":"Central America and the Carribean","country":"Costa Rica"},{"democracy":6.93,"corruption":48.0,"region":"Europe","country":"Croatia"},{"democracy":3.52,"corruption":46.0,"region":"Central America and the Carribean","country":"Cuba"},{"democracy":7.29,"corruption":63.0,"region":"Europe","country":"Cyprus"},{"democracy":8.19,"corruption":48.0,"region":"Europe","country":"Czech Republic"},{"democracy":1.92,"corruption":22.0,"region":"Sub-saharan Africa","country":"Democratic Republic of the Congo"},{"democracy":9.52,"corruption":91.0,"region":"Europe","country":"Denmark"},{"democracy":2.74,"corruption":36.0,"region":"Sub-saharan Africa","country":"Djibouti"},{"democracy":6.49,"corruption":29.0,"region":"Central America and the Carribean","country":"Dominican Republic"},{"democracy":7.16,"corruption":30.0,"region":"Australia and Oceania","country":"East Timor"},{"democracy":5.78,"corruption":35.0,"region":"South America","country":"Ecuador"},{"democracy":4.56,"corruption":32.0,"region":"Middle East, North Africa, and Greater Arabia","country":"Egypt"},{"democracy":6.47,"corruption":38.0,"region":"Central America and the Carribean","country":"El Salvador"},{"democracy":1.83,"corruption":19.0,"region":"Sub-saharan Africa","country":"Equatorial Guinea"},{"democracy":2.4,"corruption":20.0,"region":"Sub-saharan Africa","country":"Eritrea"},{"democracy":7.61,"corruption":68.0,"region":"Europe","country":"Estonia"},{"democracy":3.72,"corruption":33.0,"region":"Sub-saharan Africa","country":"Ethiopia"},{"democracy":9.06,"corruption":89.0,"region":"Europe","country":"Finland"},{"democracy":7.88,"corruption":71.0,"region":"Europe","country":"France"},{"democracy":3.56,"corruption":34.0,"region":"Sub-saharan Africa","country":"Gabon"},{"democracy":3.31,"corruption":28.0,"region":"Sub-saharan Africa","country":"Gambia"},{"democracy":5.53,"corruption":49.0,"region":"Europe","country":"Georgia"},{"democracy":8.34,"corruption":78.0,"region":"Europe","country":"Germany"},{"democracy":6.02,"corruption":46.0,"region":"Sub-saharan Africa","country":"Ghana"},{"democracy":7.65,"corruption":40.0,"region":"Europe","country":"Greece"},{"democracy":5.88,"corruption":29.0,"region":"Central America and the Carribean","country":"Guatemala"},{"democracy":2.79,"corruption":24.0,"region":"Sub-saharan Africa","country":"Guinea"},{"democracy":1.43,"corruption":19.0,"region":"Sub-saharan Africa","country":"Guinea Bissau"},{"democracy":6.05,"corruption":27.0,"region":"South America","country":"Guyana"},{"democracy":3.96,"corruption":19.0,"region":"Central America and the Carribean","country":"Haiti"},{"democracy":5.84,"corruption":26.0,"region":"Central America and the Carribean","country":"Honduras"},{"democracy":6.96,"corruption":54.0,"region":"Europe","country":"Hungary"},{"democracy":9.65,"corruption":78.0,"region":"Europe","country":"Iceland"},{"democracy":7.52,"corruption":36.0,"region":"Asia","country":"India"},{"democracy":6.76,"corruption":32.0,"region":"Asia","country":"Indonesia"},{"democracy":1.98,"corruption":25.0,"region":"Middle East, North Africa, and Greater Arabia","country":"Iran"},{"democracy":4.1,"corruption":16.0,"region":"Middle East, North Africa, and Greater Arabia","country":"Iraq"},{"democracy":8.56,"corruption":72.0,"region":"Europe","country":"Ireland"},{"democracy":7.53,"corruption":61.0,"region":"Middle East, North Africa, and Greater Arabia","country":"Israel"},{"democracy":7.74,"corruption":43.0,"region":"Europe","country":"Italy"},{"democracy":3.25,"corruption":27.0,"region":"Sub-saharan Africa","country":"Ivory Coast"},{"democracy":7.39,"corruption":38.0,"region":"Central America and the Carribean","country":"Jamaica"},{"democracy":8.08,"corruption":74.0,"region":"Asia","country":"Japan"},{"democracy":3.76,"corruption":45.0,"region":"Middle East, North Africa, and Greater Arabia","country":"Jordan"},{"democracy":2.95,"corruption":26.0,"region":"Asia","country":"Kazakhstan"},{"democracy":4.71,"corruption":27.0,"region":"Sub-saharan Africa","country":"Kenya"},{"democracy":3.78,"corruption":43.0,"region":"Middle East, North Africa, and Greater Arabia","country":"Kuwait"},{"democracy":4.69,"corruption":24.0,"region":"Asia","country":"Kyrgyzstan"},{"democracy":2.32,"corruption":26.0,"region":"Asia","country":"Laos"},{"democracy":7.05,"corruption":53.0,"region":"Europe","country":"Latvia"},{"democracy":5.05,"corruption":28.0,"region":"Middle East, North Africa, and Greater Arabia","country":"Lebanon"},{"democracy":6.66,"corruption":49.0,"region":"Sub-saharan Africa","country":"Lesotho"},{"democracy":4.95,"corruption":38.0,"region":"Sub-saharan Africa","country":"Liberia"},{"democracy":5.15,"corruption":15.0,"region":"Middle East, North Africa, and Greater Arabia","country":"Libya"},{"democracy":7.24,"corruption":57.0,"region":"Europe","country":"Lithuania"},{"democracy":8.88,"corruption":80.0,"region":"Europe","country":"Luxembourg"},{"democracy":6.16,"corruption":44.0,"region":"Europe","country":"Macedonia FYR"},{"democracy":3.93,"corruption":28.0,"region":"Sub-saharan Africa","country":"Madagascar"},{"democracy":6.08,"corruption":37.0,"region":"Sub-saharan Africa","country":"Malawi"},{"democracy":6.41,"corruption":50.0,"region":"Asia","country":"Malaysia"},{"democracy":5.12,"corruption":28.0,"region":"Sub-saharan Africa","country":"Mali"},{"democracy":8.28,"corruption":56.0,"region":"Europe","country":"Malta"},{"democracy":4.17,"corruption":30.0,"region":"Sub-saharan Africa","country":"Mauritania"},{"democracy":8.17,"corruption":52.0,"region":"Sub-saharan Africa","country":"Mauritius"},{"democracy":6.9,"corruption":34.0,"region":"North America","country":"Mexico"},{"democracy":6.32,"corruption":35.0,"region":"Europe","country":"Moldova"},{"democracy":6.35,"corruption":38.0,"region":"Asia","country":"Mongolia"},{"democracy":6.05,"corruption":44.0,"region":"Europe","country":"Montenegro"},{"democracy":4.07,"corruption":37.0,"region":"Middle East, North Africa, and Greater Arabia","country":"Morocco"},{"democracy":4.88,"corruption":30.0,"region":"Sub-saharan Africa","country":"Mozambique"},{"democracy":2.35,"corruption":21.0,"region":"Asia","country":"Myanmar"},{"democracy":6.24,"corruption":48.0,"region":"Sub-saharan Africa","country":"Namibia"},{"democracy":4.16,"corruption":31.0,"region":"Asia","country":"Nepal"},{"democracy":8.99,"corruption":83.0,"region":"Europe","country":"Netherlands"},{"democracy":9.26,"corruption":91.0,"region":"Australia and Oceania","country":"New Zealand"},{"democracy":5.56,"corruption":28.0,"region":"Central America and the Carribean","country":"Nicaragua"},{"democracy":4.16,"corruption":34.0,"region":"Sub-saharan Africa","country":"Niger"},{"democracy":3.77,"corruption":25.0,"region":"Sub-saharan Africa","country":"Nigeria"},{"democracy":1.08,"corruption":8.0,"region":"Asia","country":"North Korea"},{"democracy":9.93,"corruption":86.0,"region":"Europe","country":"Norway"},{"democracy":3.26,"corruption":47.0,"region":"Middle East, North Africa, and Greater Arabia","country":"Oman"},{"democracy":4.57,"corruption":28.0,"region":"Middle East, North Africa, and Greater Arabia","country":"Pakistan"},{"democracy":7.08,"corruption":35.0,"region":"Central America and the Carribean","country":"Panama"},{"democracy":6.32,"corruption":25.0,"region":"Australia and Oceania","country":"Papua New Guinea"},{"democracy":6.26,"corruption":24.0,"region":"South America","country":"Paraguay"},{"democracy":6.47,"corruption":38.0,"region":"South America","country":"Peru"},{"democracy":6.3,"corruption":36.0,"region":"Asia","country":"Philippines"},{"democracy":7.12,"corruption":60.0,"region":"Europe","country":"Poland"},{"democracy":7.92,"corruption":62.0,"region":"Europe","country":"Portugal"},{"democracy":3.18,"corruption":68.0,"region":"Middle East, North Africa, and Greater Arabia","country":"Qatar"},{"democracy":2.89,"corruption":22.0,"region":"Sub-saharan Africa","country":"Republic of Congo"},{"democracy":6.54,"corruption":43.0,"region":"Europe","country":"Romania"},{"democracy":3.74,"corruption":28.0,"region":"Europe","country":"Russia"},{"democracy":3.36,"corruption":53.0,"region":"Sub-saharan Africa","country":"Rwanda"},{"democracy":1.71,"corruption":46.0,"region":"Middle East, North Africa, and Greater Arabia","country":"Saudi Arabia"},{"democracy":6.09,"corruption":41.0,"region":"Sub-saharan Africa","country":"Senegal"},{"democracy":6.33,"corruption":42.0,"region":"Europe","country":"Serbia"},{"democracy":4.71,"corruption":30.0,"region":"Sub-saharan Africa","country":"Sierra Leone"},{"democracy":5.88,"corruption":86.0,"region":"Asia","country":"Singapore"},{"democracy":7.35,"corruption":47.0,"region":"Europe","country":"Slovakia"},{"democracy":7.88,"corruption":57.0,"region":"Europe","country":"Slovenia"},{"democracy":7.79,"corruption":42.0,"region":"Sub-saharan Africa","country":"South Africa"},{"democracy":8.13,"corruption":55.0,"region":"Asia","country":"South Korea"},{"democracy":8.02,"corruption":59.0,"region":"Europe","country":"Spain"},{"democracy":5.75,"corruption":37.0,"region":"Asia","country":"Sri Lanka"},{"democracy":2.38,"corruption":11.0,"region":"Sub-saharan Africa","country":"Sudan"},{"democracy":6.65,"corruption":36.0,"region":"South America","country":"Suriname"},{"democracy":3.2,"corruption":39.0,"region":"Sub-saharan Africa","country":"Swaziland"},{"democracy":9.73,"corruption":89.0,"region":"Europe","country":"Sweden"},{"democracy":9.09,"corruption":85.0,"region":"Europe","country":"Switzerland"},{"democracy":1.63,"corruption":17.0,"region":"Middle East, North Africa, and Greater Arabia","country":"Syria"},{"democracy":7.57,"corruption":61.0,"region":"Asia","country":"Taiwan"},{"democracy":2.51,"corruption":22.0,"region":"Asia","country":"Tajikistan"},{"democracy":5.88,"corruption":33.0,"region":"Sub-saharan Africa","country":"Tanzania"},{"democracy":6.55,"corruption":35.0,"region":"Asia","country":"Thailand"},{"democracy":3.45,"corruption":29.0,"region":"Sub-saharan Africa","country":"Togo"},{"democracy":6.99,"corruption":38.0,"region":"Central America and the Carribean","country":"Trinidad and Tobago"},{"democracy":5.67,"corruption":41.0,"region":"Middle East, North Africa, and Greater Arabia","country":"Tunisia"},{"democracy":5.76,"corruption":50.0,"region":"Middle East, North Africa, and Greater Arabia","country":"Turkey"},{"democracy":1.72,"corruption":17.0,"region":"Asia","country":"Turkmenistan"},{"democracy":5.16,"corruption":26.0,"region":"Sub-saharan Africa","country":"Uganda"},{"democracy":5.91,"corruption":25.0,"region":"Europe","country":"Ukraine"},{"democracy":2.58,"corruption":69.0,"region":"Middle East, North Africa, and Greater Arabia","country":"United Arab Emirates"},{"democracy":8.21,"corruption":76.0,"region":"Europe","country":"United Kingdom"},{"democracy":8.11,"corruption":73.0,"region":"North America","country":"United States of America"},{"democracy":8.17,"corruption":73.0,"region":"South America","country":"Uruguay"},{"democracy":1.72,"corruption":17.0,"region":"Asia","country":"Uzbekistan"},{"democracy":5.15,"corruption":20.0,"region":"South America","country":"Venezuela"},{"democracy":2.89,"corruption":31.0,"region":"Asia","country":"Vietnam"},{"democracy":3.12,"corruption":18.0,"region":"Middle East, North Africa, and Greater Arabia","country":"Yemen"},{"democracy":6.26,"corruption":38.0,"region":"Sub-saharan Africa","country":"Zambia"},{"democracy":2.67,"corruption":21.0,"region":"Sub-saharan Africa","country":"Zimbabwe"}]
country rank overall score electoral process and pluralism functioning of government political participation political culture civil liberties
Afghanistan 152 2.48 2.5 0.79 2.78 2.5 3.82
Albania 90 5.67 7 4 5 5 7.35
Algeria 118 3.83 3 2.21 3.89 5.63 4.41
Angola 133 3.35 0.92 3.21 5 4.38 3.24
Argentina 52 6.84 8.75 5.71 5.56 6.25 7.94
Armenia 114 4.09 4.33 3.21 3.89 3.13 5.88
Australia 6 9.22 10 8.93 7.78 9.38 10
Austria 12 8.62 9.58 8.21 7.78 8.13 9.41
Azerbaijan 139 3.15 2.17 1.79 3.33 3.75 4.71
Bahrain 150 2.53 1.25 2.5 2.78 4.38 1.76
Bangladesh 84 5.86 7.42 5.43 5 4.38 7.06
Belarus 141 3.04 1.75 2.86 3.89 4.38 2.35
Belgium 24 8.05 9.58 8.21 5.56 7.5 9.41
Benin 79 6 7.33 6.43 4.44 5.63 6.18
Bhutan 107 4.65 6.67 5.36 3.33 4.38 3.53
Bolivia 85 5.84 7 5 6.11 3.75 7.35
Bosnia and Hercegovina 98 5.11 6.92 2.93 3.33 5 7.35
Botswana 30 7.85 9.17 7.14 6.67 6.88 9.41
Brazil 44 7.12 9.58 7.5 5 4.38 9.12
Bulgaria 54 6.72 9.17 5.71 6.11 4.38 8.24
Burkina Faso 127 3.52 4 3.21 2.22 3.75 4.41
Burundi 125 3.6 3 2.57 3.89 5 3.53
Cambodia 100 4.96 5.67 6.07 3.33 5.63 4.12
Cameroon 131 3.44 0.75 4.29 3.33 5 3.82
Canada 8 9.08 9.58 9.29 7.78 8.75 10
Cape Verde 26 7.92 9.17 7.86 7.22 6.25 9.12
Central African Republic 157 1.99 1.75 1.07 1.67 2.5 2.94
Chad 165 1.62 0 0 1.11 3.75 3.24
Chile 36 7.54 9.58 8.57 3.89 6.25 9.41
China 142 3 0 4.64 3.89 5 1.47
Colombia 57 6.63 9.17 7.5 3.89 3.75 8.82
Comoros 127 3.52 3.92 2.21 3.89 3.75 3.82
Republic of Congo 144 2.89 1.25 2.86 3.33 3.75 3.24
Costa Rica 22 8.1 9.58 8.21 6.11 6.88 9.71
Côte d’Ivoire 136 3.25 0 1.79 5 5.63 3.82
Croatia 50 6.93 9.17 6.07 5.56 5.63 8.24
Cuba 127 3.52 1.75 4.64 3.89 4.38 2.94
Cyprus 41 7.29 9.17 6.43 6.11 5.63 9.12
Czech Republic 17 8.19 9.58 7.14 6.67 8.13 9.41
Democratic Republic of Congo 159 1.92 1.75 0.71 2.22 3.13 1.76
Denmark 4 9.52 10 9.64 8.89 9.38 9.71
Djibouti 147 2.74 0.83 1.79 2.22 5.63 3.24
Dominican Republic 60 6.49 8.75 5.36 4.44 6.25 7.65
Ecuador 87 5.78 7.83 4.64 5 4.38 7.06
Egypt 109 4.56 3.42 4.64 5 5.63 4.12
El Salvador 61 6.47 9.17 6.07 3.89 5 8.24
Equatorial Guinea 160 1.83 0 0.79 2.22 4.38 1.76
Eritrea 153 2.4 0 2.86 1.11 6.88 1.18
Estonia 34 7.61 9.58 7.14 5 7.5 8.82
Ethiopia 123 3.72 0 3.57 5 5.63 4.41
Fiji 124 3.67 0.42 2.86 3.89 5 6.18
Finland 9 9.06 10 9.64 7.22 8.75 9.71
France 28 7.88 9.58 7.14 6.67 7.5 8.53
Gabon 126 3.56 2.58 2.21 3.89 5 4.12
Gambia 134 3.31 2.17 3.93 2.22 5 3.24
Georgia 93 5.53 8.25 3.21 5 5 6.18
Germany 14 8.34 9.58 8.21 6.67 8.13 9.12
Ghana 78 6.02 8.33 5 5 5 6.76
Greece 33 7.65 9.58 5.71 6.67 6.88 9.41
Guatemala 81 5.88 7.92 6.43 3.33 4.38 7.35
Guinea 146 2.79 3.5 0.43 3.33 3.75 2.94
Guinea-Bissau 166 1.43 0.42 0 2.22 1.88 2.65
Guyana 76 6.05 7.92 5.36 5.56 4.38 7.06
Haiti 116 3.96 5.17 2.21 2.22 3.75 6.47
Honduras 85 5.84 8.75 5.71 3.89 4.38 6.47
Hong Kong 63 6.42 4.75 6.07 5 6.88 9.41
Hungary 49 6.96 9.17 6.07 4.44 6.88 8.24
Iceland 3 9.65 10 9.64 8.89 10 9.71
India 38 7.52 9.58 7.5 6.11 5 9.41
Indonesia 53 6.76 6.92 7.5 6.11 5.63 7.65
Iran 158 1.98 0 2.86 2.78 2.5 1.76
Iraq 113 4.1 4.33 0.79 7.22 3.75 4.41
Ireland 13 8.56 9.58 7.86 7.22 8.13 10
Israel 37 7.53 8.75 7.5 8.33 7.5 5.59
Italy 32 7.74 9.58 6.43 6.67 7.5 8.53
Jamaica 39 7.39 9.17 6.79 5 6.88 9.12
Japan 23 8.08 9.17 8.21 6.11 7.5 9.41
Jordan 121 3.76 3.17 3.93 4.44 3.75 3.53
Kazakhstan 143 2.95 0.5 2.14 3.33 4.38 4.41
Kenya 104 4.71 3.92 4.29 4.44 5.63 5.29
Kuwait 119 3.78 3.17 3.93 3.89 4.38 3.53
Kyrgyz Republic 106 4.69 6.58 2.21 5 4.38 5.29
Laos 156 2.32 0 3.21 2.22 5 1.18
Latvia 47 7.05 9.58 5.36 5.56 5.63 9.12
Lebanon 99 5.05 5.67 1.79 7.22 5 5.59
Lesotho 55 6.66 8.25 5.71 6.67 5.63 7.06
Liberia 101 4.95 7.83 0.79 5.56 5 5.59
Libya 95 5.15 4.33 5.71 3.89 6.25 5.59
Lithuania 42 7.24 9.58 5.71 5.56 6.25 9.12
Luxembourg 11 8.88 10 9.29 6.67 8.75 9.71
Macedonia 73 6.16 7.75 4.64 6.11 4.38 7.94
Madagascar 117 3.93 2.17 2.14 5 5.63 4.71
Malawi 75 6.08 7 5.71 5.56 6.25 5.88
Malaysia 64 6.41 6.5 7.86 5.56 6.25 5.88
Mali 97 5.12 7.42 3.57 5 3.13 6.47
Malta 15 8.28 9.17 8.21 5.56 8.75 9.71
Mauritania 110 4.17 3.42 4.29 5 3.13 5
Mauritius 18 8.17 9.17 8.21 5 8.75 9.71
Mexico 51 6.9 8.33 7.14 6.67 5 7.35
Moldova 67 6.32 8.75 5 5.56 4.38 7.94
Mongolia 65 6.35 8.33 5.71 4.44 5 8.24
Montenegro 76 6.05 7.92 5.36 5.56 4.38 7.06
Morocco 115 4.07 3.5 4.64 2.78 5 4.41
Mozambique 102 4.88 4.83 4.29 5.56 5.63 4.12
Myanmar 155 2.35 1.5 1.79 1.67 5.63 1.18
Namibia 72 6.24 5.67 5 6.67 5.63 8.24
Nepal 111 4.16 2.67 4.29 3.89 4.38 5.59
Netherlands 10 8.99 9.58 8.93 8.89 8.13 9.41
New Zealand 5 9.26 10 9.29 8.89 8.13 10
Nicaragua 92 5.56 6.58 4.36 3.89 5.63 7.35
Niger 111 4.16 7.5 1.14 2.78 4.38 5
Nigeria 120 3.77 5.67 3.21 3.33 3.13 3.53
North Korea 167 1.08 0 2.5 1.67 1.25 0
Norway 1 9.93 10 9.64 10 10 10
Oman 135 3.26 0 3.93 3.89 4.38 4.12
Pakistan 108 4.57 5.58 5.36 2.22 4.38 5.29
Palestine 103 4.8 5.17 2.86 7.78 4.38 3.82
Panama 46 7.08 9.58 6.43 5.56 5 8.82
Papua New Guinea 67 6.32 7.33 6.43 3.33 6.25 8.24
Paraguay 70 6.26 8.33 5.36 5 4.38 8.24
Peru 61 6.47 9.17 5 5.56 4.38 8.24
Philippines 69 6.3 8.33 5.36 5.56 3.13 9.12
Poland 44 7.12 9.58 6.43 6.11 4.38 9.12
Portugal 26 7.92 9.58 6.43 6.67 7.5 9.41
Qatar 138 3.18 0 3.93 2.22 5.63 4.12
Romania 59 6.54 9.58 6.07 4.44 4.38 8.24
Russia 122 3.74 3.92 2.86 5 2.5 4.41
Rwanda 132 3.36 0.83 4.64 2.22 5 4.12
Saudi Arabia 163 1.71 0 2.86 1.11 3.13 1.47
Senegal 74 6.09 7.92 5.71 4.44 5.63 6.76
Serbia 66 6.33 9.17 4.64 6.11 4.38 7.35
Sierra Leone 104 4.71 7 2.21 2.78 6.25 5.29
Singapore 81 5.88 4.33 7.5 3.33 6.88 7.35
Slovakia 40 7.35 9.58 7.5 5.56 5 9.12
Slovenia 28 7.88 9.58 7.5 7.22 6.25 8.82
South Africa 31 7.79 8.75 8.21 7.22 6.25 8.53
South Korea 20 8.13 9.17 8.21 7.22 7.5 8.53
Spain 25 8.02 9.58 7.5 6.11 7.5 9.41
Sri Lanka 89 5.75 6.17 5.36 4.44 6.88 5.88
Sudan 154 2.38 0 1.79 3.33 5 1.76
Suriname 56 6.65 9.17 6.43 4.44 5 8.24
Swaziland 137 3.2 0.92 2.86 2.78 5.63 3.82
Sweden 2 9.73 9.58 9.64 9.44 10 10
Switzerland 7 9.09 9.58 9.29 7.78 9.38 9.41
Syria 164 1.63 0 0.36 2.78 5 0
Taiwan 35 7.57 9.58 7.14 6.11 5.63 9.41
Tajikistan 151 2.51 1.83 0.79 2.22 6.25 1.47
Tanzania 81 5.88 7.42 4.64 6.11 5.63 5.59
Thailand 58 6.55 7.83 6.07 5.56 6.25 7.06
East Timor 43 7.16 8.67 6.79 5.56 6.88 7.94
Togo 130 3.45 4 0.79 3.33 5 4.12
Trinidad and Tobago 48 6.99 9.58 7.14 5 5 8.24
Tunisia 90 5.67 5.75 5 6.67 6.25 4.71
Turkey 88 5.76 7.92 6.79 5 5 4.12
Turkmenistan 161 1.72 0 0.79 2.22 5 0.59
Uganda 94 5.16 5.67 3.57 4.44 6.25 5.88
Ukraine 80 5.91 7.92 4.64 5.56 4.38 7.06
United Arab Emirates 149 2.58 0 3.57 1.11 5 3.24
United Kingdom 16 8.21 9.58 7.5 6.11 8.75 9.12
United States of America 21 8.11 9.17 7.5 7.22 8.13 8.53
Uruguay 18 8.17 10 8.93 4.44 7.5 10
Uzbekistan 161 1.72 0.08 0.79 2.78 4.38 0.59
Venezuela 95 5.15 5.67 4.29 5.56 4.38 5.88
Vietnam 144 2.89 0 3.93 2.78 6.25 1.47
Yemen 140 3.12 3 1.43 5 5 1.18
Zambia 70 6.26 7.92 5.36 4.44 6.25 7.35
Zimbabwe 148 2.67 0.5 1.29 3.33 5 3.24
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Corruption, Democracy, and Stability</title>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<style type="text/css">
div.tooltip {
position: absolute;
text-align: center;
padding: 8px;
font: 10px sans-serif;
background: #ddd;
border: solid 1px #aaa;
border-radius: 8px;
pointer-events: none;
}
</style>
</head>
<body>
<script type="text/javascript">
var w=960;
var h=500;
var padding = 45;
var dataset;
var colors = {'Europe':'rgb(27,158,119)',
'Asia':'rgb(217,95,2)',
'North America':'rgb(117,112,179)',
'South America':'rgb(231,41,138)',
'Australia and Oceania':'rgb(102,166,30)',
'Central America and the Carribean':'rgb(230,171,2)',
'Middle East, North Africa, and Greater Arabia':'rgb(166,118,29)',
'Sub-saharan Africa':'rgb(102,102,102)'}
var colors2 = {'Europe':'rgb(102,194,165)',
'Asia':'rgb(252,141,98)',
'North America':'rgb(141,160,203)',
'South America':'rgb(231,138,195)',
'Australia and Oceania':'rgb(166,216,84)',
'Central America and the Carribean':'rgb(255,217,47)',
'Middle East, North Africa, and Greater Arabia':'rgb(229,196,148)',
'Sub-saharan Africa':'rgb(179,179,179)'}
var classnames = {'Europe':'EU',
'Asia':'AS',
'North America':'NA',
'South America':'SA',
'Australia and Oceania':'AO',
'Central America and the Carribean':'CA',
'Middle East, North Africa, and Greater Arabia':'ME',
'Sub-saharan Africa':'SSA'}
var buttontext = {'Europe':'Europe',
'Asia':'Asia',
'North America':'North America',
'South America':'South America',
'Australia and Oceania':'Australia and Oceania',
'Central America and the Carribean':'Central America',
'Middle East, North Africa, and Greater Arabia':'Middle East',
'Sub-saharan Africa':'Sub-saharan Africa'}
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
var corruptionScale = d3.scale.linear()
.domain([0, 100])
.range([padding, w-padding]);
var democracyScale = d3.scale.linear()
.domain([0, 10])
.range([h-padding, padding]);
var countries = svg.append("g").attr("id", "countries");
var decorations = svg.append("g").attr("id", "decorations");
var ctext = "Transparency International Corruption Perceptions Index 2013";
var dtext = "The Economist Democracy Index 2012";
//Define X axis
var xAxis = d3.svg.axis()
.scale(corruptionScale)
.orient("bottom")
.ticks(10);
//Define Y axis
var yAxis = d3.svg.axis()
.scale(democracyScale)
.orient("left")
.ticks(5);
//Add the x axis
// decorations.append("g")
// .attr("class", "x axis")
// .attr("transform", "translate(0," + (h - padding + 5) + ")")
// .call(xAxis);
//Create Y axis
// decorations.append("g")
// .attr("class", "y axis")
// .attr("transform", "translate(" + (padding - 5) + ",0)")
// .call(yAxis);
// Make the axes a little more attractive
d3.selectAll("g.tick line").attr("stroke", "black");
d3.selectAll("path").attr("fill", "none").attr("stroke","black");
d3.selectAll("g.tick text").style("font", "11px sans-serif");
// Add axis labels
svg.append("text")
.text(ctext)
.attr("x",w/2)
.attr("text-anchor", "middle")
.attr("y", h-4)
.attr("fill", "black")
.style("opacity", 0.5)
.style("font", "13px sans-serif");
svg.append("text")
.text(dtext)
.attr("x",0)
.attr("y", 0)
.attr("fill", "black")
.attr("text-anchor", "middle")
.style("font", "13px sans-serif")
.style("opacity", 0.5)
.attr("transform", "translate(17," + h/2 + ") rotate(-90)");
// Add explanatory text
var labels = []
function apply_label(text, x, y, rotated) {
if (rotated) {
transtr = "translate(" + [x,y] + ") rotate(-90)";
}
else {
transtr = "translate(" + [x,y] + ")";
}
thelabel = decorations.append("text")
.text(text)
.attr("text-anchor", "middle")
.attr("x", 0)
.attr("y", 0)
.style("font", "10px sans-serif")
.attr("transform", transtr)
.style("opacity", 0.5);
}
labels.push(apply_label("More democratic", padding+10, 3*padding, true));
labels.push(apply_label("More authoritarian", padding+10, h-3*padding, true));
labels.push(apply_label("More corrupt", 3*padding, h-padding-10, false));
labels.push(apply_label("Less corrupt", w-3*padding, h-padding-10, false));
// Controls
var tabwidth=20;
var controlwidth = 200;
var controls = svg.append("g")
.attr("id", "controls")
.attr("state", "in")
.attr("transform", "translate(" + [w-controlwidth+tabwidth, padding] + ")");
var tab = controls.append("g")
.attr("id", "tab")
.attr("transform", "translate(" + [-tabwidth, 2*tabwidth] +")");
tab.append("rect")
.attr("fill", "#ddd")
.attr("stroke", "#aaa")
.attr("width", tabwidth)
.attr("height", tabwidth)
.on("click", toggle_controls);
var inpoint = "5,5 5,15 15,10";
var outpoint = "15,5 15,15 5,10";
pointer = tab.append("polygon").attr("points", outpoint).attr("fill", "#aaa").style("pointer-events", "none");
controlarea = controls.append("g")
controlarea.append("rect")
.attr("width", controlwidth)
.attr("height", h-2*padding)
.attr("fill", "#ddd")
.attr("stroke", "#aaa")
.style("opacity", 0.5)
.attr("rx", tabwidth)
.attr("ry", tabwidth);
// region-based controls
keylist = Object.keys(colors)
controlarea.selectAll("g")
.data(keylist)
.enter()
.append("g")
.attr("class", function(d) {return classnames[d]})
.attr("transform", function(d, i) {return "translate(" + [tabwidth,(i+1)*(2*tabwidth+4)] + ")"})
.append("rect")
.attr("state", "on")
.attr("class", function(d) {return classnames[d]})
.attr("fill", function(d) {return colors[d]})
.attr("stroke", function(d) {return colors[d]})
.attr("stroke-width", 2)
.attr("rx", 5)
.attr("ry", 5)
.attr("x", 0)
.attr("y", 0)
.attr("width", controlwidth-2*tabwidth)
.attr("height", 2*tabwidth)
.on("click", function(d) {return toggle_region(d)});
controlarea.selectAll("g")
.append("text")
.attr("fill", "white")
.attr("class", function(d) {return classnames[d]})
.attr("x", tabwidth)
.attr("y", tabwidth+6)
.style("font", "12px sans-serif")
.style("pointer-events", "none")
.text(function(d) {return buttontext[d]});
controls.transition()
.delay(1000)
.duration(1500)
.attr("transform", "translate(" + [w-4, padding] + ")");
function toggle_region(d) {
var bselector = "g#controls rect."+classnames[d];
var thebutton = d3.select(bselector);
var cselector = "circle."+classnames[d];
var thecircles = d3.selectAll(cselector);
var rselector = "g#countries rect."+classnames[d];
var therects = d3.selectAll(rselector);
var lselector = "text."+classnames[d];
var thelabel = d3.select(lselector);
//check state
if (thebutton.attr("state") == "on") {
// change the button
thebutton.attr("state", "off")
.transition().delay(500)
.attr("fill", "#eee")
thelabel.transition()
.delay(500)
.attr("fill", function(d) {return colors[d]})
// fade the circles
thecircles.transition()
.delay(500)
.style("opacity", 0.1);
//turn mouse events off
therects.style("pointer-events", "none");
}
else {
// change the button
thebutton.attr("state", "on")
.transition().delay(500)
.attr("fill", function(d) {return colors[d]})
thelabel.transition()
.delay(500)
.attr("fill", "white")
// fade the circles
thecircles.transition()
.delay(500)
.style("opacity", 1.0);
// turn mouse events back on
therects.style("pointer-events","all");
}
}
function toggle_controls() {
if (controls.attr("state") == "in") {
// set state to out
controls.attr("state", "out");
// make it so
controls.transition()
.duration(500)
.attr("transform", "translate(" + [w-controlwidth+tabwidth, padding] + ")");
pointer.transition()
.duration(500)
.attr("points", inpoint);
}
else
{
// set state to in
controls.attr("state", "in");
// make it so
controls.transition()
.duration(500)
.attr("transform", "translate(" + [w-4, padding] + ")");
pointer.transition().duration(500).attr("points", outpoint);
}
};
function update_view() {
d3.select("g#countries")
.selectAll("g")
.data(dataset)
.enter()
.append("g")
.attr("id", function(d) {return d.country})
.attr("transform", function(d) {return "translate(" +
corruptionScale(d.corruption) + "," +
democracyScale(d.democracy) + ")"})
.append("circle")
.attr('r',4)
.attr('stroke', function(d) {return colors[d.region]})
.attr('stroke-width', 1.5)
.attr("class", function(d) {return classnames[d.region]})
.attr('pointer-events','none')
.attr('fill','none');
//mouse catcher
d3.selectAll("g#countries g")
.append("rect")
.style('visibility', 'hidden')
.attr("class", function(d) {return classnames[d.region]})
.attr('x', -5.5)
.attr('y', -5.5)
.attr("fill", "white")
.on("mouseover", function(d) {return mouseover(d)})
.on("mouseout", function(d) {return mouseout(d)})
.attr('pointer-events','all')
.attr('width', 11)
.attr('height', 11);
}
d3.select("g#decorations")
.append("line")
.attr('x1', corruptionScale(40))
.attr('x2', corruptionScale(40))
.attr('y1', democracyScale(0))
.attr('y2', democracyScale(10))
.attr('stroke', 'black')
.style("opacity", 0.3);
d3.select("g#decorations")
.append("line")
.attr('x1', corruptionScale(0))
.attr('x2', corruptionScale(100))
.attr('y1', democracyScale(4.25))
.attr('y2', democracyScale(4.25))
.attr('stroke', 'black')
.style('opacity', 0.5);
d3.json("data.json", function(error, json) {
if (error) return console.warn(error);
dataset = json;
update_view();
});
var tooltip = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
function mouseover(d) {
tooltip.text(d.country)
.style("left", (d3.event.pageX + 5) + "px")
.style("top", (d3.event.pageY + 15) + "px")
tooltip.transition()
.duration(500)
.style("opacity",1);
}
function mouseout(d) {
tooltip.transition()
.duration(500)
.style("opacity", 0);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment