File:NottinghamSouthGraph.svg
Summary
| Description |
English: United Kingdom general election results for Nottingham South constituency. |
| Date | |
| Source | Own work |
| Author | JeremyA |
| SVG development | Category:Invalid SVG created with R#1000NottinghamSouthGraph.svg |
Notes
The Background colour indicates the party of the sitting MP at any given year.
Graph drawn with R
Parties:
- Conservative = Conservative Party (1885–1918; 1964–present); Conservative and Liberal Unionist (1922–1959).
- Labour = Labour Party
- Liberal = Liberal Party (1885–1979); SDP-Liberal Alliance (1983–1987); Liberal Democrats (1992–present).
Data:
| Year | Conservative | Labour | Liberal | Other |
|---|---|---|---|---|
| 1923.93 | 51.4 | NA | 23.8 | 24.8 |
| 1929.41 | 41.3 | 42.9 | 15.8 | NA |
| 1931.82 | NA | 31.65 | NA | 68.35 |
| 1935.87 | NA | 36.81 | 10.95 | 52.24 |
| 1945.51 | NA | 50.46 | 14.07 | 35.47 |
| 1950.148 | 43.82 | 48.03 | 8.13 | NA |
| 1951.82 | 49.39 | 50.61 | NA | NA |
| 1955.4 | 56.88 | 43.12 | NA | NA |
| 1959.77 | 57.11 | 42.89 | NA | NA |
| 1964.79 | 45.97 | 41 | 13.03 | NA |
| 1966.25 | 49.68 | 50.32 | NA | NA |
| 1970.46 | 53.75 | 46.25 | NA | NA |
| 1983.44 | 45.9 | 34.1 | 20 | NA |
| 1987.44 | 45 | 40.8 | 14.2 | NA |
| 1992.27 | 41.8 | 47.7 | 10 | 0.5 |
| 1997.33 | 27.7 | 55.3 | 12.9 | 4 |
| 2001.43 | 27.2 | 54.5 | 16.6 | 1.7 |
| 2005.34 | 25.9 | 47.4 | 22.9 | 3.9 |
| 2010.35 | 32.9 | 37.3 | 23.1 | 6.7 |
| 2015.35 | 31.7 | 47.6 | 3.5 | 17.2 |
| 2017.44 | 30.9 | 62.4 | 3.2 | 3.5 |
Source code

This media was created with R (programming language for statistical analysis)Category:Images with R source code
Here is a listing of the source used to create this file.
Here is a listing of the source used to create this file.
The graph was produced with R. The following code will reproduce the graph using the data on this page.
library(tidyverse)
library(htmltab)
library(lubridate)
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:NottinghamSouthGraph.svg")
ggsave("NottinghamSouthGraph.svg", device = "svg", units = "cm", width = 20, height = 11, dpi = 120)
Licensing
JeremyA, the copyright holder of this work, hereby publishes it under the following license:
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
Attribution:
- 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.