Skip to content

Instantly share code, notes, and snippets.

@expersso
Last active June 13, 2017 12:08
Show Gist options
  • Select an option

  • Save expersso/e43bbd3d3e6fa98465a6c22b497a3682 to your computer and use it in GitHub Desktop.

Select an option

Save expersso/e43bbd3d3e6fa98465a6c22b497a3682 to your computer and use it in GitHub Desktop.
Chart on banking crises using Reinhart, Rogoff (2009) data
library(tidyverse)
library(scales)
library(readxl)
library(forcats)
get_data <- function() {
tmp <- tempfile(fileext = ".xlsx")
on.exit(unlink(tmp))
download.file("http://www.carmenreinhart.com/user_uploads/data/124_data.xlsx",
tmp, mode = "wb")
read_excel(tmp, "Banking Crisis", skip = 2) %>%
.[-c(1,2), 1:67] %>%
set_names(c("year", names(.)[-1])) %>%
gather(country, value, -year) %>%
mutate(year = as.numeric(year)) %>%
filter(!is.na(year))
}
df <- get_data()
ggplot(df, aes(x = year, y = fct_rev(country), fill = as.logical(value))) +
geom_tile(alpha = 0.25) +
theme(axis.text.y = element_text(size = 6)) +
scale_x_continuous(expand = c(0, 0), breaks = pretty_breaks(10)) +
scale_fill_manual(values = c("green", "red"), labels = c("No crisis", "Crisis")) +
theme(legend.position = "bottom") +
labs(x = NULL, y = NULL, fill = NULL,
title = "Banking crises",
subtitle = "(1800-2008)",
caption = "Source: Reinhart, Rogoff (2009)")
@expersso

expersso commented Jun 13, 2017

Copy link
Copy Markdown
Author

image

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