Advertisement
Guest User

scoretime

a guest
Jul 1st, 2014
949
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Written by Haseeb Mahmud
  2. # Requirements  : R 3.0 or higher with appropriate libraries installed.
  3. #               : Internet connection
  4. #               : R studio environment.
  5. # http://www.nirpata.com
  6.  
  7. library(XML)
  8. library(ggplot2)
  9. library(RColorBrewer)
  10. library(colorRamps)
  11.  
  12. # Goal scored time
  13. url <- "http://www.uefa.com/worldcup/season=2014/statistics/round=2000296/goaltimes/index.html"
  14. goaltime <- readHTMLTable(url)
  15. goaltime
  16. goaltime <- do.call(rbind.data.frame, goaltime)
  17. str(goaltime)
  18. Goal.Total <- as.numeric(as.character(goaltime$Total))
  19. Goaltime.data <- data.frame(goaltime, Goal.Total)
  20. # Expanding colorpallete
  21. colourCount = length(unique(Goaltime.data$Time))
  22. getPalette = colorRampPalette(brewer.pal(9, "Set1"))
  23. # plot with custom pallete  
  24. goaltime.graph <- ggplot(data=Goaltime.data, aes(x=Time, y=Goal.Total, fill=Time)) + geom_bar() +  scale_fill_manual(values =getPalette(colourCount)) + theme(axis.text.x=element_text(angle = -90, hjust = 0)) + theme(legend.position="none")
  25. goaltime.graph
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement