Skip to content

Instantly share code, notes, and snippets.

@cavedave
Last active January 22, 2020 22:07
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 cavedave/c43ff9b7da10724330b520099b375b35 to your computer and use it in GitHub Desktop.
Save cavedave/c43ff9b7da10724330b520099b375b35 to your computer and use it in GitHub Desktop.
World gdp growth rates by region
Country Continent random randomC
Algeria AFRICA 60.6167300016224 61
Angola AFRICA 71.5212095913241 72
Benin AFRICA 51.7624535957612 52
Botswana AFRICA 15.7730987774009 16
Burkina AFRICA 43.4650351116097 44
Burundi AFRICA 65.5623808542023 66
Cameroon AFRICA 50.6499306806902 51
Cape Verde AFRICA 13.4829147803843 14
Central African Republic AFRICA 17.8374229865049 18
Chad AFRICA 29.924381836669 30
Comoros AFRICA 71.4692715596517 72
Congo AFRICA 37.2450618758762 38
Congo, Democratic Republic of AFRICA 7.82166481236349 8
Djibouti AFRICA 72.2313116479816 73
Egypt AFRICA 47.6374570093139 48
Equatorial Guinea AFRICA 60.8276744520727 61
Eritrea AFRICA 50.4594349319479 51
Ethiopia AFRICA 20.4307033690226 21
Gabon AFRICA 8.00888406164509 9
Gambia AFRICA 96.1342705396023 97
Ghana AFRICA 32.2011682222616 33
Guinea AFRICA 63.0052737426284 64
Guinea-Bissau AFRICA 65.6684702230086 66
Ivory Coast AFRICA 89.0525038027716 90
Kenya AFRICA 31.5108347528361 32
Lesotho AFRICA 69.8298656158086 70
Liberia AFRICA 54.0246444613355 55
Libya AFRICA 29.3832670235385 30
Madagascar AFRICA 17.6137309263152 18
Malawi AFRICA 65.1967144592625 66
Mali AFRICA 93.8250351534233 94
Mauritania AFRICA 40.7110860184194 41
Mauritius AFRICA 48.7838460294809 49
Morocco AFRICA 90.5541180758008 91
Mozambique AFRICA 61.0685656552458 62
Namibia AFRICA 38.343361776327 39
Niger AFRICA 16.4729179045592 17
Nigeria AFRICA 87.2675694596433 88
Rwanda AFRICA 13.166351009014 14
Sao Tome and Principe AFRICA 90.0182837345859 91
Senegal AFRICA 37.8485308501602 38
Seychelles AFRICA 30.1871843891817 31
Sierra Leone AFRICA 56.2564920047803 57
Somalia AFRICA 93.6179765515136 94
South Africa AFRICA 39.5096127001066 40
South Sudan AFRICA 32.3402098734751 33
Sudan AFRICA 11.7553759435875 12
Swaziland AFRICA 80.4614919445087 81
Tanzania AFRICA 89.5178679574181 90
Togo AFRICA 51.6577608675679 52
Tunisia AFRICA 38.8429571480379 39
Uganda AFRICA 47.8952280291542 48
Zambia AFRICA 63.2637659636957 64
Zimbabwe AFRICA 52.1931520254656 53
Afghanistan ASIA 41.7414112810643 42
Bahrain ASIA 83.6420885996847 84
Bangladesh ASIA 87.6928396619939 88
Bhutan ASIA 30.987062267755 31
Brunei ASIA 43.4605914527885 44
Burma (Myanmar) ASIA 88.2075485875595 89
Cambodia ASIA 96.7845379189223 97
China ASIA 22.7542522156107 23
East Timor ASIA 45.7987973935801 46
India ASIA 9.84720142126543 10
Indonesia ASIA 58.0493093489922 59
Iran ASIA 90.7267139150375 91
Iraq ASIA 10.2039458048294 11
Israel ASIA 35.9870711615945 36
Japan ASIA 65.3176734919355 66
Jordan ASIA 25.0749728901542 26
Kazakhstan ASIA 74.0064053552349 75
Korea, North ASIA 59.517103824574 60
Korea, South ASIA 19.7413560531922 20
Kuwait ASIA 33.4960476397987 34
Kyrgyzstan ASIA 42.3478822425574 43
Laos ASIA 87.8939399370659 88
Lebanon ASIA 41.4559002893637 42
Malaysia ASIA 93.5890287289432 94
Maldives ASIA 46.8233988327355 47
Mongolia ASIA 97.3567298647253 98
Nepal ASIA 27.3954135905726 28
Oman ASIA 59.0593907938577 60
Pakistan ASIA 16.5969613733266 17
Philippines ASIA 53.3176095049627 54
Qatar ASIA 93.4443941462758 94
Russian Federation ASIA 81.7138557069442 82
Saudi Arabia ASIA 36.9816802766212 37
Singapore ASIA 71.5391144607582 72
Sri Lanka ASIA 61.6743111793183 62
Syria ASIA 82.8514062102289 83
Tajikistan ASIA 94.6143650191239 95
Thailand ASIA 76.0844294241207 77
Turkey ASIA 50.3744302487417 51
Turkmenistan ASIA 56.5736092757109 57
United Arab Emirates ASIA 67.0892662215485 68
Uzbekistan ASIA 88.5925292642167 89
Vietnam ASIA 62.2442448607378 63
Yemen ASIA 28.9261304666786 29
Albania EUROPE 31.9302882764087 32
Andorra EUROPE 37.1898947085438 38
Armenia EUROPE 82.9464411489346 83
Austria EUROPE 57.5670321627154 58
Azerbaijan EUROPE 79.0320390507358 80
Belarus EUROPE 33.8331616606583 34
Belgium EUROPE 27.2297747146218 28
Bosnia and Herzegovina EUROPE 77.2198908717871 78
Bulgaria EUROPE 83.330001524536 84
Croatia EUROPE 77.8402007886649 78
Cyprus EUROPE 51.5746698243359 52
Czech Republic EUROPE 23.8606214648663 24
Denmark EUROPE 73.5277310112556 74
Estonia EUROPE 89.2741188761241 90
Finland EUROPE 54.1415688884643 55
France EUROPE 52.9147553934293 53
Georgia EUROPE 64.7581324731776 65
Germany EUROPE 23.9368842488435 24
Greece EUROPE 32.9503748810979 33
Hungary EUROPE 43.427168739971 44
Iceland EUROPE 14.778460045693 15
Ireland EUROPE 85.885247386953 86
Italy EUROPE 59.5685779807038 60
Latvia EUROPE 66.5809003749686 67
Liechtenstein EUROPE 41.5971142280833 42
Lithuania EUROPE 44.0258020960584 45
Luxembourg EUROPE 83.2929859819699 84
Macedonia EUROPE 95.2839525632425 96
Malta EUROPE 58.5818494018854 59
Moldova EUROPE 87.1478886856595 88
Monaco EUROPE 78.9060687252128 79
Montenegro EUROPE 68.9755292911948 69
Netherlands EUROPE 76.6603027744751 77
Norway EUROPE 91.0854582162888 92
Poland EUROPE 0.386688652785589 1
Portugal EUROPE 21.1093754726772 22
Romania EUROPE 20.2660331713941 21
San Marino EUROPE 75.4150342304565 76
Serbia EUROPE 40.9894042466659 41
Slovakia EUROPE 50.597902950745 51
Slovenia EUROPE 44.4856901562959 45
Spain EUROPE 6.38430953895731 7
Sweden EUROPE 93.1185369240532 94
Switzerland EUROPE 69.9825604085906 70
Ukraine EUROPE 0.307435944042224 1
United Kingdom EUROPE 28.0060847527685 29
Vatican City EUROPE 35.751487250501 36
Antigua and Barbuda N. AMERICA 82.8037254708978 83
Bahamas N. AMERICA 50.0405384610616 51
Barbados N. AMERICA 89.2032630821603 90
Belize N. AMERICA 51.6447017353713 52
Canada N. AMERICA 75.1850164135689 76
Costa Rica N. AMERICA 46.9799454317141 47
Cuba N. AMERICA 49.7339578490649 50
Dominica N. AMERICA 31.2100599563296 32
Dominican Republic N. AMERICA 16.6057911750866 17
El Salvador N. AMERICA 53.5968526207674 54
Grenada N. AMERICA 76.2273582408734 77
Guatemala N. AMERICA 66.4496748710394 67
Haiti N. AMERICA 27.3331705195688 28
Honduras N. AMERICA 12.1352682601282 13
Jamaica N. AMERICA 61.0757445209222 62
Mexico N. AMERICA 58.7025891350084 59
Nicaragua N. AMERICA 57.0769113165023 58
Panama N. AMERICA 75.6396109985276 76
Saint Kitts and Nevis N. AMERICA 52.258197822752 53
Saint Lucia N. AMERICA 38.2821943627656 39
Saint Vincent and the Grenadines N. AMERICA 95.1443461241663 96
Trinidad and Tobago N. AMERICA 10.2846177428616 11
United States N. AMERICA 32.4440793935977 33
Australia OCEANIA 27.1816429743819 28
Fiji OCEANIA 75.6725124293908 76
Kiribati OCEANIA 57.7189775158871 58
Marshall Islands OCEANIA 77.437997315951 78
Micronesia OCEANIA 52.3076053862099 53
Nauru OCEANIA 35.9217477786092 36
New Zealand OCEANIA 82.4372521083138 83
Palau OCEANIA 20.8939721765936 21
Papua New Guinea OCEANIA 97.8853262107647 98
Samoa OCEANIA 12.6836792492572 13
Solomon Islands OCEANIA 29.3566389933936 30
Tonga OCEANIA 8.61883267529269 9
Tuvalu OCEANIA 68.9900117795411 69
Vanuatu OCEANIA 21.1025209925495 22
Argentina S. AMERICA 82.9618984739205 83
Bolivia S. AMERICA 15.9077221230356 16
Brazil S. AMERICA 92.2751355693951 93
Chile S. AMERICA 12.0016352639622 13
Colombia S. AMERICA 35.2721144080479 36
Ecuador S. AMERICA 73.0152115408201 74
Guyana S. AMERICA 6.92037675353188 7
Paraguay S. AMERICA 30.4515723473095 31
Peru S. AMERICA 52.9516415910102 53
Suriname S. AMERICA 51.2210352712741 52
Uruguay S. AMERICA 5.02272509577985 6
Venezuela S. AMERICA 28.7356946537238 29
data <- read.csv("countriesGates.csv")
data$Country <- factor(data$Country, levels = data$Country)
#make a simple graph
ggplot(data, aes(x=Country, y=randomC, color=Continent,group = Continent)) +
geom_bar(stat="identity")
#more complicated picture
ggplot(data, aes(x=Country, y=randomC, color=Continent,group = Continent)) +
geom_bar(stat="identity") + coord_polar(theta = "x")
#
sequence_length = length(unique(small$Country))
first_sequence = c(1:(sequence_length%/%2))
second_sequence = c((sequence_length%/%2+1):sequence_length)
first_angles =c(90 - 180/length(first_sequence) * first_sequence)
second_angles = c(-90 - 180/length(second_sequence) * second_sequence)
p<-ggplot(small, aes(x=bothG, y=Growth.Rate.., fill=Continent,group = Continent)) +
geom_bar(stat="identity") + coord_polar()+
theme(plot.caption = element_text(hjust=0.5,vjust=-0.5, size=rel(6)),
axis.text.y=element_blank(),axis.ticks=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank(),legend.position="none",
panel.background=element_blank(),panel.border=element_blank(),panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),plot.background=element_blank(),
axis.text.x=element_text(angle= c(second_angles),size=15),
plot.margin=unit(c(1,1,1.5,1.2),"cm")
)
p <- p +
annotate("text", x = 18, y = 3.3,
label = "Africa", size=10, colour="red",alpha = .9)
p <- p +
annotate("text", x = 52, y = 3,
label = "Asia", size=10, colour="#ffdb58",alpha = .99)
p <- p +
annotate("text", x = 95, y = 3,
label = "Europe", size=10, colour="green",alpha = .9)
p <- p +
annotate("text", x = 105
, y = 3,
label = "N. America", size=10, colour="#00CED1",alpha = .99)
p <- p + annotate("text", x = 120, y = 3,
label = "Oceania", size=10, colour="darkblue",alpha = .9)
p <- p +
annotate("text", x = 125, y = 3,
label = "S. America", size=10, colour="purple",alpha = .9)
p <- p +
scale_fill_manual(values = alpha(c("green", "red", "darkblue", "yellow","pink","purple"), .3),aesthetics = "colour")
#p<-p + ggtitle("Population Growth", size=12)
p <- p + labs(caption = "Population Growth Rate")
ggsave('GrowthMore4Mil.png', width=20, height=20)
@cavedave
Copy link
Author

I saw this graph Bill Gates posted and I wanted to create something similar https://www.reddit.com/r/Infographics/comments/aulqu1/africa_is_the_youngest_continent/?sort=old

Data from Countries and Continents from https://www.worldatlas.com/cntycont.htm (which does not contain Palestine and Taiwan) Growth rates from http://worldpopulationreview.com/countries/

This graph only contains countries of size more than than 4 million. 121 countries of this size or 194 in total. So the graph is much clearer only looking at larger countries.

R package GGplot2 code. From various dplyr hacking the two datasets get combined to look like. I can do a full write up of the steps if people want it.

Country Continent Growth.Rate bothG

...

Algeria AFRICA 1.60 Algeria 1.6 2

Angola AFRICA 3.29 Angola 3.29

Benin AFRICA 2.75 Benin 2.75

@cavedave
Copy link
Author

growth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment