William Marble
February 19, 2016
The good:
The bad:
# load ggplot, install if not already installed
if (!require(ggplot2)){
install.packages("ggplot2")
require(ggplot2)
}
# and for fun themes
if (!require(ggthemes)){
install.packages("ggthemes")
require(ggthemes)
}
Congressional district-level data; unit of observation is district-year
ideol.data = read.csv(file="http://stanford.edu/~wpmarble/data/rep_data.csv")
print(head(ideol.data[, c("year", "dwnom1", "median", "gini", "party")]), digits=2)
year dwnom1 median gini party
1 1984 0.234 0.439 0.40 Republican
2 1984 0.354 0.584 0.43 Republican
3 1984 0.343 0.344 0.44 Republican
4 1984 -0.036 0.153 0.42 Democrat
5 1984 -0.202 0.318 0.42 Democrat
6 1984 -0.156 0.023 0.41 Democrat
ggplot(ideol.data, aes(x = dwnom1)) + geom_histogram()
ggplot(ideol.data, aes(x = median, y = dwnom1)) + geom_point()