Part 1
# Load the Penn World Table data
pwt <- read_csv("pwt71_wo_country_names_wo_g_vars.csv")
#filter the observations so that we only have the data from 1985-2010.
pwt2 <- pwt %>% filter(year>=1985)
#Plotting countries based on investment
pwt2ki <- pwt2 %>% group_by(isocode) %>%
summarise(Inv = mean(ki))
pwt2kiplot <- qplot(isocode, Inv, data=pwt2ki, label=isocode,main="Investment")
pwt2kiplot + geom_text(size=4, aes(colour=factor(Inv))) + theme(legend.position="none") + scale_colour_discrete(l=40)

#Plotting countries based on Population
pwt3ki <- pwt2 %>% group_by(isocode) %>%
summarise(n = log(last(POP)/first(POP))/n())
pwt3ki %>%
mutate(isocode = reorder(isocode, n)) %>%
ggplot(aes(x = isocode, y = n,label=isocode,main="Population Growth")) +
geom_bar(stat = "identity") +
coord_flip() + geom_text(angle = 300, size=4, aes(colour=factor(n))) + theme(legend.position="none") + scale_colour_discrete(l=40)

#Filter for 2010
pwt4 <- pwt %>% filter(year>=2010)
#Plotting countries based on income per capita relative to the united states in 2010
pwt4inc <- pwt4 %>% group_by(isocode) %>%
summarise(inc = last(y))
pwt4plot <- qplot(isocode, inc, data=pwt4inc, label=isocode,main="Income per Capita 2010")
pwt4plot + geom_text(size=4,aes(colour=factor(inc))) + theme(legend.position="none") + scale_colour_discrete(l=40)
