Skip to content

Instantly share code, notes, and snippets.

@tukachev
Created February 15, 2014 18:15
Show Gist options
  • Save tukachev/9023035 to your computer and use it in GitHub Desktop.
Save tukachev/9023035 to your computer and use it in GitHub Desktop.
packs <- c("knitr", "ggplot2", "XML", "reshape2", "rCharts", "Cairo")
lapply(packs, require, character.only = TRUE)
theurl = "http://www.sochi2014.com/medalnyj-zachet"
## Grab Data, Clean and Reshape
raw <- readHTMLTable(theurl, header=FALSE,
colClasses = c(rep("factor", 2), rep("numeric", 4)))
raw <- as.data.frame(raw)[, -1]
colnames(raw) <- c("Страна", "Золото", "Серебро", "Бронза", "Всего")
raw <- with(raw, raw[order(Всего, Золото, Серебро, Бронза), ])
raw <- raw[raw[, "Всего"] != 0, ]
raw[, "Страна"] <- factor(raw[, "Страна"], levels = raw[, "Страна"])
rownames(raw) <- NULL
mdat <- melt(raw, value.name = "Всего", variable.name = "Место", id.var = "Страна")
mdat[, "Место"] <- factor(mdat[, "Место"], levels=c("Золото", "Серебро", "Бронза", "Всего"))
## Plot the Data
data <- paste(format(Sys.time(), "%d.%m.%Y %H:%M:%S"))
ann <- paste("Данные на",data)
CairoPNG(file="olympic2014.png",width=640,height=480)
ggplot(mdat, aes(x = Всего, y = Страна, colour = Место)) +
geom_point() +
facet_grid(.~Место) +
theme_bw()+
scale_colour_manual(values=c("#FFCC33", "#999999", "#CC6600" , "#000000")) +
ggtitle(paste("XXII Олимпийские зимние игры: медальный зачет \n", ann))
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment