README.md

About

This R package contains datasets on German federal, parliamentary elections, from 1949 to 2013. It comprises five separate datasets:

Comma-separated/JSON files will be published in the near future.

Installation & Usage

The package can be installed from this Github repository:

#install.packages("devtools")
devtools::install_github("crubba/bundestagswahl")

To access the data in R type:

library("bundestagswahl")

data("btw_votes")
data("btw_candidates")
data("btw_districts_neighbors")
data("btw_districts")
data("btw_districts_maps")

Example

This example illustrates how to create a map of party vote shares:

library("dplyr")
library("ggplot2")

# Subsetting and merging maps and votes datasets
districts1987 <- subset(btw_districts_maps, year == 1987)
btw_votes_spd <- filter(btw_votes, party == "SPD", year == 1987, mandate == "pvote") %>%
  select(., year, wk,  per)
gg_df <- left_join(districts1987, btw_votes_spd, 
                   by = c("year" = "year", "wk" = "wk"))

# Creating a unique district identifier (necessary since some districts are composites of multiple, disconnected polygons)
gg_df$groupid <- paste(gg_df$wk, gg_df$part)

# Plotting
ggplot(data = gg_df, aes(x = long, y = lat, group = groupid, fill = per)) + 
  geom_polygon(colour = "white", size = 0.1) + 
  scale_fill_gradient(low = "white", high = "#660000") +
  ggtitle("Party vote shares for SPD in 1987") +
  xlab("") + ylab("") +
  theme(legend.text = element_text(size = 8),
        panel.border = element_blank(),
        panel.background = element_rect(fill = "#8DB6CD", colour = NA),
        legend.key = element_rect(fill = "white"),
        legend.box = "horizontal",
        legend.position = "bottom",
        axis.text = element_text(size = rel(0.8)),
        axis.text.y = element_blank(),
        axis.text.x = element_blank(),
        axis.title = element_blank(),
        axis.ticks = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank())

Citation

If you use the datasets provided through this package, please consider citing it. To receive citing information type:

citation("bundestagswahl")


crubba/bundestagswahl documentation built on May 14, 2019, 12:05 p.m.