Skip to content

Instantly share code, notes, and snippets.

@stedy
Created June 12, 2016 03:00
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 stedy/59fe24c6b5ab02a870d2584e4ce89ef9 to your computer and use it in GitHub Desktop.
Save stedy/59fe24c6b5ab02a870d2584e4ce89ef9 to your computer and use it in GitHub Desktop.
Slopegraph of African GDP in R
library(dplyr)
library(ggplot2)
library(directlabels)
raw <- read.csv("Jerven_Table1.csv", encoding = "UTF-8")
mad <- raw[, 1:2]
names(mad) <- c("Country", 'Per.Capita.GDP')
mad$group <- "Maddison"
wdi <- raw[, 3:4]
names(wdi) <- c("Country", 'Per.Capita.GDP')
wdi$group <- "World Development Indicators"
pwt <- raw[, 5:6]
names(pwt) <- c("Country", 'Per.Capita.GDP')
pwt$group <- "Penn World Tables"
forplot <- dplyr::bind_rows(mad, wdi, pwt)
ggplot(forplot, aes(x = group, y = Per.Capita.GDP, group = Country, colour = Country)) +
geom_line(size=2) +
scale_colour_discrete(guide = 'none') +
scale_x_discrete(expand=c(0, 1)) +
geom_dl(aes(label = Country), method = list(dl.combine("first.points", "last.points"),
cex = 1.5)) + theme_bw() +
theme(axis.text=element_text(size=12),
axis.title=element_text(size=14,face="bold")) + ylab("Per Capita GDP") +
ggtitle("African Economies ranked by per capita GDP (in international USD)")
ggsave("AfricanEconomiesbyGDP.png")
#log transformed
ggplot(forplot, aes(x = group, y = log10(Per.Capita.GDP), group = Country, colour = Country)) +
geom_line(size=2) +
scale_colour_discrete(guide = 'none') +
scale_x_discrete(expand=c(0, 1)) +
geom_dl(aes(label = Country), method = list(dl.combine("first.points", "last.points"),
cex = 1.5)) + theme_bw() +
theme(axis.text=element_text(size=12),
axis.title=element_text(size=14,face="bold")) + ylab("log10(Per Capita GDP)")+
ggtitle("African Economies ranked by per capita GDP (in international USD)")
ggsave("AfricanEconomiesbyGDP_logscaled.png")
Maddison Maddison Per capita GDP World Development Indicators WDI Per capita GDP Penn World Tables PWT Per capita GDP
Congo-Kinshasa 217 Congo-Kinshasa 92 Congo-Kinshasa 359
Sierra Leone 410 Ethiopia 115 Liberia 472
Chad 429 Burundi 139 Sierra Leone 684
Niger 486 Sierra Leone 153 Burundi 699
Burundi 496 Malawi 169 Ethiopia 725
Tanzania 535 Tanzania 190 Guinea-Bissau 762
Guinea 572 Liberia 191 Niger 867
Central African Rep. 576 Mozambique 191 Tanzania 817
Comoro Islands 581 Niger 200 Togo 823
Ethiopia 605 Guinea-Bissau 210 Madagascar 823
Togo 614 Chad 218 Chad 830
Zambia 645 Rwanda 242 Malawi 839
Malawi 656 Burkina Faso 243 Zambia 866
Guinea-Bissau 681 Madagascar 246 Burkina Faso 933
Madagascar 706 Nigeria 254 Central African Rep. 945
Angola 765 Mali 294 Gambia 954
Uganda 797 Sudan 313 Rwanda 1018
Rwanda 819 Togo 323 Mali 1047
Mali 892 Kenya 328 Sudan 1048
Gambia 895 Central African Rep. 339 Uganda 1058
Burkina Faso 921 São Tomé & Príncipe 341 Nigeria 1074
Liberia 990 Uganda 348 Mozambique 1093
Sudan 991 Gambia 370 Benin 1251
Mauritania 1017 Zambia 394 Kenya 1268
Kenya 1031 Ghana 413 Congo-Brazzaville 1286
Cameroon 1082 Benin 414 São Tomé & Príncipe 1300
São Tomé & Príncipe 1226 Comoros 436 Comoros 1359
Nigeria 1251 Mauritania 495 Ghana 1392
Ghana 1270 Angola 524 Mauritania 1521
Benin 1283 Lesotho 548 Senegal 1571
Zimbabwe 1328 Guinea 605 Lesotho 1834
Côte d'Ivoire 1352 Senegal 609 Angola 1975
Senegal 1358 Zimbabwe 620 Côte d'Ivoire 2171
Mozambique 1365 Cameroon 675 Cameroon 2472
Lesotho 1490 Côte d'Ivoire 739 Guinea 2546
Cape Verde 1777 Congo-Brazzaville 791 Zimbabwe 3256
Congo-Brazzaville 2005 Swaziland 1538 Cape Verde 4984
Swaziland 2630 Cape Verde 1541 Namibia 5269
Namibia 3637 Equatorial Guinea 1599 Equatorial Guinea 6495
Gabon 3847 Namibia 2366 Botswana 7256
South Africa 3978 Botswana 3931 South Africa 8226
Botswana 4269 South Africa 4020 Swaziland 8517
Seychelles 6354 Mauritius 4104 Gabon 10439
Equatorial Guinea 7973 Gabon 4378 Seychelles 10593
Mauritius 10652 Seychelles 6557 Mauritius 15121
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment