Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement