library(readr)
library(dplyr)
library(ggplot2)
library(parlitools)
library(sf)
UK Elections 2017
political science
dataViz
This post is a quickie to show how we can visualize the UK election results with just a few lines of R code. (Really, very few). 1
We can load in our usual tidyverse tools, along with a handy little data package, parlitools.
Thanks to this R Bloggers post, we have the data (the UK Electoral Commission must have it up by now anyway), so visualizing it is very easy:
<- read_csv("/Users/robert/Downloads/EconomistUK2017.csv")
results
<- west_hex_map
uk
<- inner_join(results, uk, by = c("Constituency.ID" = "gss_code")) %>%
res filter(!is.na(win)) %>%
st_as_sf()
ggplot(res) +
geom_sf(aes(fill = win), size = 0.2) +
theme_minimal() +
guides(fill = guide_legend(title = "party")) +
scale_fill_manual(values = c("#006BA4", "#800B05", "#349B3A", "#888888", "#DB434E",
"#E8B335", "#98B3D1", "#60B031", "#8DDC64","#FCDD02"))
Bam! Easy, quick and lovely š.
Footnotes
Iām using the dev version of ggplot2 here, we need it for
geom_sf()
.ā©ļø