Advertisement
Guest User

averagefoulsbycountry

a guest
Jun 30th, 2014
1,093
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.21 KB | None | 0 0
  1. # Written by Haseeb Mahmud
  2. # Requirements  : R 3.0 or higher with appropriate libraries installed.
  3. #               : Internet connection
  4. #               : Environment R studio.
  5.  
  6. library(XML)
  7. library(ggplot2)
  8. library(RColorBrewer)
  9. library(colorRamps)
  10.  
  11. # Average Fouls committed by country - 2
  12. url <- "http://www.uefa.com/worldcup/season=2014/statistics/round=2000296/teams/type=foulscommitted/index.html"
  13. foulbycountry <- readHTMLTable(url)
  14. foulbycountry
  15. foulbycountry1 <- do.call(rbind.data.frame, foulbycountry)
  16. str(foulbycountry1)
  17. Av.Foul <- as.numeric(as.character(foulbycountry1$Average))
  18. TotalFoul <- as.numeric(as.character(foulbycountry1$Total))
  19. FoulCountry <- data.frame(foulbycountry1, Av.Foul, TotalFoul)
  20. # Reordering the data to fit it into the plot
  21. FoulCountry.data <- transform(FoulCountry, Team = reorder(Team, Av.Foul))
  22. # Expanding colorpallete
  23. colourCount = length(unique(FoulCountry.data$Team))
  24. getPalette = colorRampPalette(brewer.pal(9, "Set1"))
  25. #plot
  26. foul.bycountry <- ggplot(data=FoulCountry.data, aes(x=Team, y=Av.Foul, fill=Team)) + geom_bar() +  scale_fill_manual(values =getPalette(colourCount)) + theme(axis.text.x=element_text(angle = -90, hjust = 0)) + coord_flip()
  27. foul.bycountry
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement