Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. elect <- read.csv("ElectionsUk.csv", header = TRUE)
  2.  
  3. #turn this format into a date
  4. library(lubridate)
  5. elect$date2 <- dmy(elect$date)
  6.  
  7. p <- ggplot(elect,aes(x = date2, y = Millions.of.Votes)) +#, colour = elect$Type
  8. geom_point(aes(colour = Type),
  9. shape=21,
  10. fill= "White",
  11. size =3,
  12. stroke=1.5
  13. )
  14. p <- p + scale_y_continuous(labels = scales::comma)
  15.  
  16. p <- p + annotate("text", x = as.Date("1989-01-05"), y = 33.1, label = "33,614,074")
  17. p <- p + annotate("text", x = as.Date("2010-07-05"), y = 32.9, label = "33,577,342")
  18.  
  19. p <- p + theme_economist_white() +
  20. scale_colour_economist()
  21.  
  22. p <- p + #ggtitle("Democratic Exercises in UK History") +
  23. xlab("Year") + ylab("Millions of Votes") +
  24. theme(plot.title = element_text(hjust = 0.5),legend.position = "none",plot.background = element_rect(fill = "white"),
  25. legend.background = element_rect(fill="white",
  26. size=0.5, linetype="solid"))
  27.  
  28. p
  29. ggsave("Votes.png")
  30.  
  31. p2 <- ggplot(elect,aes(x = date2, y = Turnout), colour = factor(Type)) +
  32. geom_point(aes(colour = Type),
  33. shape=21,
  34. fill= "White",
  35. size =3,
  36. stroke=1.5
  37. )+
  38. geom_smooth(method=lm, se=FALSE)
  39.  
  40. p2 <- p2 + annotate("text", x = as.Date("2014-07-05"), y = 74.2, label = "EU Ref")
  41. p2 <- p2 + scale_y_continuous()#position = "right"
  42. p2 <- p2 + theme_economist_white() +
  43. scale_colour_economist()
  44. p2 <- p2 + #ggtitle("Turnout of Democratic Exercises in UK History") +
  45. xlab("Year") + ylab("Turnout") +
  46. theme(plot.title = element_text(hjust = 0.5),plot.background = element_rect(fill = "white"),
  47. legend.background = element_rect(fill="white"),legend.key = element_rect(fill = "white", color = NA))
  48. p2
  49. ggsave("turnout.png")
  50.  
  51. library(grid)
  52.  
  53. g<-grid.arrange(
  54. p,
  55. p2,
  56. nrow = 1,
  57. top=textGrob("Democratic Exercises in UK History", gp=gpar(fontsize=15,font=8)),
  58. #top = "Democratic Exercises in UK History",
  59. bottom = textGrob(
  60. "since WW2",
  61. gp = gpar(fontface = 3, fontsize = 9),
  62. hjust = 1.1,
  63. x = 1
  64. )
  65. )
  66.  
  67. ggsave(file="Democratic Exercise in UK History.png", g)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement