Skip to content

Instantly share code, notes, and snippets.

@carlislerainey
Created February 20, 2017 17:00
Show Gist options
  • Select an option

  • Save carlislerainey/fcd437f28c441ae497a15641467a8689 to your computer and use it in GitHub Desktop.

Select an option

Save carlislerainey/fcd437f28c441ae497a15641467a8689 to your computer and use it in GitHub Desktop.
# set working directory
setwd("~/Dropbox/classes/pols-209")
# load packages
library(ggplot2) # for creating figures
library(tibble) # for glimpse()
# load data
leg <- readRDS("data/state-legislators.rds") # data are in the data subfolder
# quick look at the data
glimpse(leg)
# subset to the 2014 data
leg2014 <- subset(leg, year == 2014)
# build plot
ggplot(leg2014, aes(x = ideology_score, fill = party)) +
geom_density(alpha = 0.5) +
facet_wrap(~ state) +
labs(x = "Ideology Score",
y = "Density",
fill = "Party",
title = "Density Plots of the Ideology for Republicans, Independents, and Democrats in the 50 States in 2014",
subtitle = "Polarization and Extremity Vary Across the States",
caption = "Data from https://americanlegislatures.com") +
theme_bw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment