File:HallamGraph.svg

Page contents not supported in other languages.
This is a file from the Wikimedia Commons
From Wikipedia, the free encyclopedia

Original file(SVG file, nominally 512 × 282 pixels, file size: 41 KB)

Summary

Description
English: Election results for Sheffield Hallam constituency from its creation in 1885 to the 2017 general election.
Date
Source Own work
Author JeremyA

Notes

The Background colour indicates the party of the sitting MP at any given year.

Elections held in 1895, 1900, 1916 (by-election) and 1918 do not appear on this graph, at each of these elections a single candidate was elected unopposed (Conservative in 1895, 1900, and 1918, Liberal in 1916). Gaps indicate the missing elections.

Statistics gathered from:

Parties:

Data Used:

Year Conservative Labour Liberal Other
1885.96 54.4 45.6
1886.57 57.8 42.2
1892.57 54.3 45.7
1895.6 unopp
1900.81 unopp
1906.61 50.4 49.6
1910.11 50.9 49.1
1910.97 50.9 49.1
1916 unopp
1918.95 unopp
1922.87 59.4 40.6
1923.93 57.7 23.9 23.4
1924.83 63.7 36.3
1928 53.7 30.8 15.5
1929.41 60.9 39.1
1931.82 77.5 22.5
1935.87 67.3 32.7
1939 61.7 38.3
1945.51 47.1 38.5 7.7 6.7
1950.15 65.1 26.5 8.4
1951.82 70.76 29.24
1955.4 66.23 33.77
1959.77 62.76 26.06 11.18
1964.79 54.95 26.96 18.09
1966.25 51.34 32.49 16.17
1970.46 61.32 31.43 7.25
1974.16 48.95 27.2 23.85
1974.78 49 28.97 22.03
1979.34 54.94 28.84 15.7 0.52
1983.44 50.62 19.72 28.42 1.24
1987.44 46.29 20.38 32.51 0.83
1992.27 45.52 20.15 33.09 1.24
1997.33 33.1 13.5 51.3 2
2001.43 31 12.4 55.4 1.1
2005.34 29.7 12.6 51.1 6.7
2010.35 23.5 16.1 53.4 6.8
2015.35 13.6 35.8 40 10.6
2017.44 23.8 38.4 34.6 3.1

Code:

The graph was produced with R. The following code will reproduce the graph using the data on this page.

library(tidyverse)
library(htmltab)

election_graph <- function(pageURL) {
  election <- htmltab(pageURL,
                      which = 2,
                      rm_nodata_cols = F)
  election <- as.tibble(lapply(election, function(x) {gsub("unopp", "100", x)}))
  
  tidy_election <- gather(election, "Party", "Votes", 2:length(election))
  tidy_election$Year <- as.numeric(tidy_election$Year)
  tidy_election$Party <- factor(tidy_election$Party, levels = c("Conservative", "Labour", "Liberal", "Green", "SNP", "UKIP", "Other"))
  tidy_election$Votes <- as.numeric(tidy_election$Votes)
  
  election_victor <- tidy_election %>% filter(is.na(Votes) == FALSE) %>% group_by(Year) %>% summarize(Party = Party[which(Votes == max(Votes))])
  election_victor$Year <- as.numeric(election_victor$Year)
  election_victor$start_year <- election_victor$Year
  election_victor$end_year <- c(election_victor$Year[-1], ceiling(election_victor$Year[length(election_victor$Year)] + 1))
  election_victor[1,3] <- floor(election_victor[1,3] - 1)
  
  tidy_election$Votes <- as.numeric(sapply(tidy_election$Votes, function(x) {gsub(100, NA, x)}))
  
  party_colours <- c("#0087DC", "#DC241F", "#FAA61A", "#008066", "#FFF95D", "#EFE600", "dark grey")
  names(party_colours) <- c("Conservative", "Labour", "Liberal", "Green", "SNP", "UKIP", "Other")
  
  ggplot(tidy_election) +
    geom_rect(data = election_victor,
              aes(xmin = start_year,xmax = end_year, ymin = -Inf, ymax = Inf, fill = Party),
              alpha = 0.35,
              show.legend = F) +
    geom_line(aes(x = Year, y = Votes, colour = Party), size = 0.703) +
    geom_point(aes(x = Year, y = Votes, colour = Party)) +
    geom_hline(yintercept = 100, color="black", size = 1.5) +
    geom_vline(xintercept = 2019, color="black", size = 1.5) +
    scale_colour_manual(values = party_colours) +
    scale_fill_manual(values = party_colours) +
    theme(text = element_text(color="black", size = 14),
          axis.text = element_text(color="black", size = 11),
          axis.line.x = element_line(color="black", size = 0.703),
          axis.ticks.x = element_line(color="black", size = 0.703),
          axis.line.y = element_line(color="black", size = 0.703),
          axis.ticks.y = element_line(color="black", size = 0.703),
          axis.ticks.length = unit(5, "points"),
          panel.grid.major = element_line(color="blue", size = 0.5, linetype = 3),
          panel.grid.minor = element_blank(),
          panel.background = element_blank(),
          legend.position = c(.98, .97),
          legend.direction = "horizontal",
          legend.text = element_text(color="black", size = 11),
          legend.title=element_blank(),
          legend.justification = c("right", "top"),
          legend.box.just = "right",
          legend.key = element_blank(),
          legend.background = element_rect(fill = "white", colour = "black"),
          legend.margin = margin(0, 4, 4, 4)) +
    scale_x_continuous(expand = c(0, 0), limits = c(election_victor[[1,3]], election_victor$end_year[length(election_victor$end_year)]), breaks = seq(1890, 2010, 10)) +
    scale_y_continuous(expand = c(0, 0), limits = c(0, 100), breaks = seq(0, 100, 20)) +
    labs(x = "Year", y = "Percentage Vote")
}

election_graph("https://commons.wikimedia.org/wiki/File:HallamGraph.svg")

ggsave("HallamGraph.svg", device = "svg", units = "cm", width = 20, height = 11, dpi = 120)

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

14 June 2017

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current20:36, 14 June 2017Thumbnail for version as of 20:36, 14 June 2017512 × 282 (41 KB)JeremyAUser created page with UploadWizard
The following pages on the English Wikipedia use this file (pages on other projects are not listed):

Metadata