Skip to content

Instantly share code, notes, and snippets.

@halhen
Last active April 22, 2017 16:54
Show Gist options
  • Save halhen/4dbfa310baa7e334138cbb677a47d3fa to your computer and use it in GitHub Desktop.
Save halhen/4dbfa310baa7e334138cbb677a47d3fa to your computer and use it in GitHub Desktop.
HEIGHT <- 50 # points per column
closing_df[rep(1:nrow(closing_df), closing_df$total), ] %>%
group_by(store) %>%
mutate(rank = row_number() - 1) %>%
mutate(x = rank %/% HEIGHT,
y = rank %% HEIGHT + 0.5) %>%
arrange(y, x) %>%
mutate(rank = row_number() - 1,
status = ifelse(rank < closing, 'closing', 'remaining')) %>%
ggplot(aes(x, y)) +
geom_point(aes(color=status)) +
scale_y_continuous(labels=function(x) {paste0(x*100/HEIGHT, "%")}) +
scale_x_continuous(breaks=NULL) +
scale_color_manual(values=c('closing'='#F7464A', 'remaining'='#4D5360'), name='') +
labs(x="", y="", title="American retailers are\nclosing stores at a record pace") +
coord_flip() +
facet_grid(store ~ ., scales='free', space='free', switch='y') +
theme_minimal(base_family='Arial Narrow') +
theme(legend.position='bottom',
title=element_text(family='Georgia', size=16),
axis.text=element_text(size=12),
legend.text=element_text(size=12),
strip.text.y = element_text(hjust=1, angle=180, size=14) )
# Looks is very sensitive to output size, so I brute forced something that looks OK
# A little love in Illustrator wouldn't hurt, for example fixing the facets cutting
# off the bottom points, and some general layout easier done there.
ggsave('/tmp/stores.png', width=6, height=13)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment