Created
March 14, 2017 16:39
-
-
Save expersso/6d632221b06ca63e2d906bc4207b87d3 to your computer and use it in GitHub Desktop.
Timeline of structural indices
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
# Based on https://twitter.com/andrewheiss/status/841655403087822848 | |
library(tidyverse) | |
url <- paste0("https://gist.githubusercontent.com/andrewheiss/", | |
"db6c981f1032207fd5a1d1a59113c469/raw/", | |
"23768ef3d9dc87a53efd891da4d3d1a448dbca34/long.csv") | |
df <- read.csv(url, stringsAsFactors = FALSE) %>% | |
tbl_df() %>% | |
mutate(component = str_replace(components_clean, "^\\w+ ", ""), | |
group = str_replace(components_clean, " .*$", ""), | |
lbl = paste(component, index), | |
components_clean = str_replace(components_clean, "^(\\w+) ", "\\1\n")) | |
labels <- df$component | |
names(labels) <- df$lbl | |
xend <- as.POSIXlt(Sys.Date())$year + 1900 | |
ggplot(df, aes( | |
x = start_year, | |
xend = xend, | |
y = lbl, | |
yend = lbl, | |
color = index | |
)) + | |
geom_segment(show.legend = FALSE) + | |
geom_vline(xintercept = seq(1995, 2015, 5), | |
color = "white", | |
size = 1) + | |
geom_text(aes(label = sprintf(" %s", index), x = xend), | |
hjust = 0, | |
size = 3) + | |
facet_grid( | |
components_clean ~ ., | |
drop = TRUE, | |
space = "free_y", | |
shrink = TRUE, | |
scales = "free" | |
) + | |
scale_y_discrete(labels = labels) + | |
scale_x_continuous(limits = c(NA, xend + 12), | |
breaks = seq(1995, 2015, 5)) + | |
theme( | |
legend.position = "none", | |
panel.background = element_rect(color = "grey90", fill = "white"), | |
axis.text.y = element_blank(), | |
axis.ticks.y = element_blank(), | |
strip.text.y = element_text( | |
angle = 0, | |
color = "grey50", | |
face = "bold" | |
), | |
strip.background = element_blank(), | |
axis.ticks.x = element_line(color = "grey90"), | |
axis.text.x = element_text(color = "grey50") | |
) + | |
labs( | |
x = NULL, | |
y = NULL, | |
title = "Structural indices", | |
subtitle = "Timeline" | |
) |
Author
expersso
commented
Mar 14, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment