Skip to content

Instantly share code, notes, and snippets.

@kanishkamisra
Created February 24, 2018 22:36
Show Gist options
  • Save kanishkamisra/ac754e9995e5c0dc74df0243e8200f96 to your computer and use it in GitHub Desktop.
Save kanishkamisra/ac754e9995e5c0dc74df0243e8200f96 to your computer and use it in GitHub Desktop.
Code for r/dataisbeautiful monthly DataViz Battle thread - Feb 2018
library(tidyverse)
library(geofacet)
library(kani)
same_sex <- read_csv("https://raw.githubusercontent.com/zonination/samesmarriage/master/ssm.csv")
same_sex %>%
gather(`1995`:`2015`, key = "Year", value = "Law") %>%
mutate(
Year = as.numeric(Year),
Law = factor(Law, levels = c("No Law", "Constitutional Ban", "Statutory Ban", "Legal"))
) %>%
ggplot(aes(Year, 1, group = 1, fill = Law)) +
geom_hline(yintercept = 0, color = rgb(210, 210, 210, max = 255)) +
geom_hline(yintercept = 1, color = rgb(210, 210, 210, max = 255)) +
geom_col(width = 1, alpha = 0.8) +
facet_geo(~State, grid = "us_state_grid4", label = "code") +
scale_x_continuous(labels = c("'95", "'00", "'05", "'10", "'15")) +
scale_fill_kani() +
theme_kani() +
theme(
legend.position = "top",
legend.margin = margin(b = -1, unit = "cm"),
plot.background = element_rect(fill = "white"),
panel.background = element_rect(fill = "white"),
legend.background = element_rect(fill = "white"),
legend.key = element_rect(fill = "white"),
strip.background = element_rect(fill = "white"),
strip.text = element_text(face = "bold"),
legend.text = element_text(size = rel(1)),
legend.title = element_text(size = rel(1.2), face = "bold"),
axis.text.y = element_blank(),
plot.title = element_text(hjust = 0.5),
panel.grid.major.y = element_blank()
) +
labs(
y = "",
x = "Year",
title = "Changes in Same Sex Marriage Laws between 1995 - 2015",
caption = "Source: Pew Research Center"
)
ggsave("samesex_laws.png", height = 10, width = 13)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment