Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Written by Haseeb Mahmud
- # Requirements : R 3.0 or higher with appropriate libraries installed.
- # : Internet connection
- # : Environment R studio.
- library(XML)
- library(ggplot2)
- library(RColorBrewer)
- library(colorRamps)
- # Average Fouls committed by country - 2
- url <- "http://www.uefa.com/worldcup/season=2014/statistics/round=2000296/teams/type=foulscommitted/index.html"
- foulbycountry <- readHTMLTable(url)
- foulbycountry
- foulbycountry1 <- do.call(rbind.data.frame, foulbycountry)
- str(foulbycountry1)
- Av.Foul <- as.numeric(as.character(foulbycountry1$Average))
- TotalFoul <- as.numeric(as.character(foulbycountry1$Total))
- FoulCountry <- data.frame(foulbycountry1, Av.Foul, TotalFoul)
- # Reordering the data to fit it into the plot
- FoulCountry.data <- transform(FoulCountry, Team = reorder(Team, Av.Foul))
- # Expanding colorpallete
- colourCount = length(unique(FoulCountry.data$Team))
- getPalette = colorRampPalette(brewer.pal(9, "Set1"))
- #plot
- 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()
- foul.bycountry
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement