Skip to content

Instantly share code, notes, and snippets.

@floswald
Created November 29, 2018 08:57
Show Gist options
  • Save floswald/69d543cf0aa3f08603cf42fed6d77163 to your computer and use it in GitHub Desktop.
Save floswald/69d543cf0aa3f08603cf42fed6d77163 to your computer and use it in GitHub Desktop.
I think this is what you did.
# download data
download.file("http://microdata.worldbank.org/index.php/catalog/428/download/28457","~/Downloads/data.zip")
unzip("~/Downloads/data.zip")
# read data
library(data.table)
x = fread("Downloads/edattainxtry_1.csv")
d = x[,list(year,country,aAll_6,aQuint1x_6,aQuint5x_6)]
# plot data
library(ggplot2)
# x vs x
p = ggplot(subset(d,aQuint5x_6<1),aes(x=aAll_6,y=aAll_6)) + geom_point()
# x vs x_poor
p = p + geom_point(aes(x=aAll_6,y=aQuint1x_6),color="red")
# x vs x_rich
p = p + geom_point(aes(x=aAll_6,y=aQuint5x_6),color="green")
# proper labels
p = p + scale_y_continuous(name = "attainment of all(black),poor(red),rich(green)") + scale_x_continuous(name = "attainment of all")
p = p + theme_bw() + ggtitle("Rich and Poor vs Overall Attainment")
# save
ggsave(p,file="ravallion.png",width=8,height=7)
# view
p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment