Skip to content

Instantly share code, notes, and snippets.

@cavedave
Created October 5, 2019 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cavedave/110f7222ba835db9b0c79e47392120e3 to your computer and use it in GitHub Desktop.
Save cavedave/110f7222ba835db9b0c79e47392120e3 to your computer and use it in GitHub Desktop.
Visualisation of UK elections. I keep seeing 'the referendum, we saw the biggest democratic exercise in our history' so I looked the the number of votes/turnout numbers and the EU referendum isn't https://fullfact.org/europe/eu-referendum-not-largest-democratic-exercise/
elect <- read.csv("ElectionsUk.csv", header = TRUE)
#turn this format into a date
library(lubridate)
elect$date2 <- dmy(elect$date)
p <- ggplot(elect,aes(x = date2, y = Millions.of.Votes)) +#, colour = elect$Type
geom_point(aes(colour = Type),
shape=21,
fill= "White",
size =3,
stroke=1.5
)
p <- p + scale_y_continuous(labels = scales::comma)
p <- p + annotate("text", x = as.Date("1989-01-05"), y = 33.1, label = "33,614,074")
p <- p + annotate("text", x = as.Date("2010-07-05"), y = 32.9, label = "33,577,342")
p <- p + theme_economist_white() +
scale_colour_economist()
p <- p + #ggtitle("Democratic Exercises in UK History") +
xlab("Year") + ylab("Millions of Votes") +
theme(plot.title = element_text(hjust = 0.5),legend.position = "none",plot.background = element_rect(fill = "white"),
legend.background = element_rect(fill="white",
size=0.5, linetype="solid"))
p
ggsave("Votes.png")
p2 <- ggplot(elect,aes(x = date2, y = Turnout), colour = factor(Type)) +
geom_point(aes(colour = Type),
shape=21,
fill= "White",
size =3,
stroke=1.5
)+
geom_smooth(method=lm, se=FALSE)
p2 <- p2 + annotate("text", x = as.Date("2014-07-05"), y = 74.2, label = "EU Ref")
p2 <- p2 + scale_y_continuous()#position = "right"
p2 <- p2 + theme_economist_white() +
scale_colour_economist()
p2 <- p2 + #ggtitle("Turnout of Democratic Exercises in UK History") +
xlab("Year") + ylab("Turnout") +
theme(plot.title = element_text(hjust = 0.5),plot.background = element_rect(fill = "white"),
legend.background = element_rect(fill="white"),legend.key = element_rect(fill = "white", color = NA))
p2
ggsave("turnout.png")
library(grid)
g<-grid.arrange(
p,
p2,
nrow = 1,
top=textGrob("Democratic Exercises in UK History", gp=gpar(fontsize=15,font=8)),
#top = "Democratic Exercises in UK History",
bottom = textGrob(
"since WW2",
gp = gpar(fontface = 3, fontsize = 9),
hjust = 1.1,
x = 1
)
)
ggsave(file="Democratic Exercise in UK History.png", g)
Election Votes Millions of Votes Turnout Type mps votes per seat date
1945 United Kingdom general election 24073025 24.073025 72.8 GE 5 July 1945
1950 United Kingdom general election 28771124 28.771124 83.9 GE 23 February 1950
1951 United Kingdom general election 28596594 28.596594 82.6 GE 25 October 1951
1955 United Kingdom general election 26759729 26.759729 76.8 GE 26 May 1955
1959 United Kingdom general election 27862652 27.862652 78.7 GE 8 October 1959
1964 United Kingdom general election 27657148 27.657148 77 GE 15 October 1964
1975 United Kingdom European Communities membership referendum 25903194 25.903194 64.62 Ref 5 June 1975
2011 United Kingdom Alternative Vote referendum 19279022 19.279022 42.2 Ref 5 May 2011
1966 United Kingdom general election 27264747 27.264747 75.8 GE 31 March 1966
1970 United Kingdom general election 28305534 28.305534 72 GE 18 June 1970
February 1974 United Kingdom general election 31321982 31.321982 78.8 GE 28 February 1974
October 1974 United Kingdom general election 29189104 29.189104 72.8 GE 10 October 1974
1979 United Kingdom general election 31221362 31.221362 76 GE 3 May 1979
1983 United Kingdom general election 30671137 30.671137 72.7 GE 9 June 1983
1987 United Kingdom general election 32529578 32.529578 75.3 GE 11 June 1987
1992 United Kingdom general election 33614074 33.614074 77.7 GE 9 April 1992
1997 United Kingdom general election 31286284 31.286284 71.3 GE 1 May 1997
2001 United Kingdom general election 26367383 26.367383 59.4 GE 659 7 June 2001
2005 United Kingdom general election 27148510 27.14851 61.4 GE 646 42,026 5 May 2005
2010 United Kingdom general election 29687604 29.687604 65.1 GE 6 May 2010
2015 United Kingdom general election 30697525 30.697525 66.4 GE 7 May 2015
2016 United Kingdom European Union membership referendum 33577342 33.577342 72.21 Ref 23 June 2016
2017 United Kingdom general election 32204124 32.204124 68.8 GE 8 June 2017
Election,Votes,Millions of Votes,Turnout,Type,mps,votes per seat,date
1945 United Kingdom general election,24073025,24.073025,72.8,GE,,,5 July 1945
1950 United Kingdom general election,28771124,28.771124,83.9,GE,,,23 February 1950
1951 United Kingdom general election,28596594,28.596594,82.6,GE,,,25 October 1951
1955 United Kingdom general election,26759729,26.759729,76.8,GE,,,26 May 1955
1959 United Kingdom general election,27862652,27.862652,78.7,GE,,,8 October 1959
1964 United Kingdom general election,27657148,27.657148,77,GE,,,15 October 1964
"1975 United Kingdom European Communities membership referendum
",25903194,25.903194,64.62,Ref,,,5 June 1975
2011 United Kingdom Alternative Vote referendum,19279022,19.279022,42.2,Ref,,,5 May 2011
1966 United Kingdom general election,27264747,27.264747,75.8,GE,,,31 March 1966
1970 United Kingdom general election,28305534,28.305534,72,GE,,,18 June 1970
February 1974 United Kingdom general election,31321982,31.321982,78.8,GE,,,28 February 1974
October 1974 United Kingdom general election,29189104,29.189104,72.8,GE,,,10 October 1974
1979 United Kingdom general election,31221362,31.221362,76,GE,,,3 May 1979
1983 United Kingdom general election,30671137,30.671137,72.7,GE,,,9 June 1983
1987 United Kingdom general election,32529578,32.529578,75.3,GE,,,11 June 1987
1992 United Kingdom general election,33614074,33.614074,77.7,GE,,,9 April 1992
1997 United Kingdom general election,31286284,31.286284,71.3,GE,,,1 May 1997
2001 United Kingdom general election,26367383,26.367383,59.4,GE,659,,7 June 2001
2005 United Kingdom general election,27148510,27.14851,61.4,GE,646,"42,026",5 May 2005
2010 United Kingdom general election,29687604,29.687604,65.1,GE,,,6 May 2010
2015 United Kingdom general election,30697525,30.697525,66.4,GE,,,7 May 2015
2016 United Kingdom European Union membership referendum,33577342,33.577342,72.21,Ref,,,23 June 2016
2017 United Kingdom general election,32204124,32.204124,68.8,GE,,,8 June 2017
@cavedave
Copy link
Author

cavedave commented Oct 5, 2019

Democratic Exercise in UK History
turnout
Votes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment