Last active
June 13, 2017 12:08
-
-
Save expersso/e43bbd3d3e6fa98465a6c22b497a3682 to your computer and use it in GitHub Desktop.
Chart on banking crises using Reinhart, Rogoff (2009) data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.