Skip to content

Instantly share code, notes, and snippets.

@briatte
Last active August 29, 2015 14: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 briatte/1e9c4aecf96c1bcfa062 to your computer and use it in GitHub Desktop.
Save briatte/1e9c4aecf96c1bcfa062 to your computer and use it in GitHub Desktop.
An overview of the Reinhart & Rogoff data, from an exercise by Cosma Shalizi.
# An overview of the Reinhart & Rogoff data, from an exercise by Cosma Shalizi.
# 2014-10-09
#
# package
#
library(ggplot2)
#
# dataset
#
file = "debt.csv"
if(!file.exists(file))
download.file("http://www.stat.cmu.edu/~cshalizi/uADA/13/hw/11/debt.csv", file, mode = "wb")
#
# inspect
#
debt = read.csv(file)
str(debt)
table(debt$Country)
head(debt)
debt = debt[, -1]
#
# variables
#
ra = "\nratio dette / produit intérieur brut"
gr = "taux de croissance du produit intérieur brut\n"
debt$Decade = factor(10 * debt$Year %/% 10)
# plots
# fig. 1
qplot(data = debt, y = growth, x = Year, geom = "line") +
facet_wrap(~ Country) +
labs(x = NULL, y = gr)
# fig. 2
qplot(data = debt, y = ratio, x = Year, geom = "line") +
facet_wrap(~ Country) +
labs(x = NULL, y = ra)
# fig. 3
ggplot(data = debt, aes(y = growth, x = ratio)) +
geom_point(color = "grey50") +
geom_smooth(method = "loess", size = 1, color = "black", se = FALSE) +
scale_x_continuous(breaks = seq(0, 200, by = 100)) +
facet_wrap(~ Decade, nrow = 1) +
labs(y = gr, x = ra) +
theme_linedraw(12)
# uncomment to save last plot
# ggsave("reinhart_rogoff.png", width = 11, height = 6.375)
# have a nice day
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment