House of Commons Library Presentation

Evan Odell

2020-01-15

R Packages

hansard

CRAN_Status_Badge license GitHub tag DOI

mnis

CRAN_Status_Badge license GitHub tag DOI

nomisr

CRAN_Status_Badge license GitHub tag DOI

parlitools

CRAN_Status_Badge license GitHub tag DOI

What do MPs talk about?

Research question

Do female Labour MPs selected through all women shortlists differ from other female Labour MPs in how they speak or what they speak about?

Tools

Labour vs Conservatives

Labour MPs

Female Labour MPs

Topic Models

The hansard package

Early Day Motions

library(hansard)
library(ggplot2)
library(dplyr)

edm <- early_day_motions(start_date = "2010-01-01")

edm_sum <- edm %>% group_by(number_of_signatures) %>% summarise(n=n())

theme_set(theme_bw())

p1 <- ggplot(edm_sum) + 
  geom_line(aes(x = number_of_signatures, y = n, colour = n), 
            size = 1.1, alpha = 0.85) + 
  scale_y_sqrt(breaks = c(1,5,10,20,50,100,200,300)) + 
  scale_x_sqrt(breaks = c(1,5,10,20,50,100,200,300)) + 
  scale_colour_viridis_c() + 
  theme(legend.position = "none") + 
  labs(x = "Number of Signatures", y = "Number of Early Day Motions")

p1

EDM Signatures

EDM Title Wordcloud Code

library(quanteda)

title_dfm <- edm$title %>%
  tokens(remove_punct = TRUE, remove_numbers =TRUE) %>% 
  dfm(remove = c(stopwords()))

textplot_wordcloud(title_dfm, max_words = 350, rotation=0,
                   color = viridis::viridis_pal(option = "C")(30))

EDM Title Wordcloud

parlitools

library(parlitools)
library(sf)
library(cartogram)
library(leaflet)

seats19 <- parlitools::bes_2019 %>% 
  left_join(parlitools::party_colour, by = c("winner_19" ="party_name")) 

gb_hex_map <- parlitools::west_hex_map %>% 
  left_join(seats19, by = c("gss_code"="ons_const_id"))

gb_hex_map <- gb_hex_map %>% 
  mutate(majority_19_perc = (majority_19/total_vote_19)*100)

gb_hex_map <- st_transform(gb_hex_map, "+init=epsg:3395")

gb_hex_scaled <- cartogram_cont(gb_hex_map, 'majority_19_perc', itermax = 5)

gb_hex_scaled <- st_transform(gb_hex_scaled, "+init=epsg:4326")

# Creating map labels
labels <- paste0(
  "Constituency: ", gb_hex_scaled$constituency_name.y, "</br>",
  "Winner: ", gb_hex_scaled$winner_19, "</br>",
  "Majority (votes): ", gb_hex_scaled$majority_19,"</br>",
  "Majority (% points): ", round(gb_hex_scaled$majority_19_perc,1),"</br>",
  "Turnout: ", round(gb_hex_scaled$turnout_19,1), "%"
) %>% lapply(htmltools::HTML)

leaflet(options=leafletOptions(
  dragging = FALSE, zoomControl = FALSE, tap = FALSE,
  minZoom = 6, maxZoom = 6, maxBounds = list(list(2.5,-7.75),list(58.25,50.0)),
  attributionControl = FALSE),
  gb_hex_scaled) %>%
  addPolygons(
    color = "lightgrey",
    weight=0.75,
    opacity = 0.5,
    fillOpacity = 1,
    fillColor = ~party_colour,
    label=labels) %>% 
  htmlwidgets::onRender(
    "function(x, y) {
        var myMap = this;
        myMap._container.style['background'] = '#fff';
    }")%>% 
  mapOptions(zoomToLimits = "first")

How safe are seats?

Notes