Skip to content

Instantly share code, notes, and snippets.

@migonzalvar
Created April 1, 2012 18:11
Show Gist options
  • Save migonzalvar/2277459 to your computer and use it in GitHub Desktop.
Save migonzalvar/2277459 to your computer and use it in GitHub Desktop.
Visualization of Vig-Bay 2012 half marathon results
#!/usr/bin/Rscript --vanilla --default-packages=utils
#
# (c) 2012 Miguel Gonzalez <migonzalvar@gmail.com>
#
# This work is licensed under a Creative Commons Attribution 3.0 Unported
# License. (CC BY 3.0)
#
# Data source: http://www.vig-bay.com/index.php?option=com_content&view=article&id=518&Itemid=164
str_to_seconds <- function(s){
sapply(strsplit(s,":"),
function(x) {
x <- as.numeric(x)
(x[1]*3600) + (x[2]*60) + x[3]
})}
seconds_to_str <- function(x){
h = x%/%3600
m = x%%3600%/%60
s = x%%3600%%60
sprintf("%d:%02d:%02d", h, m, s)
}
resultados = read.csv("resultados.txt")
tiempos = str_to_seconds(as.character(resultados$T.Oficial))
eje_y = mat.or.vec(length(tiempos),1)
eje_x = seq(3600,3*3600,600)
eje_x_etiquetas = seconds_to_str(eje_x)
png("vigbay2012.png", width=900)
plot(tiempos, jitter(eje_y),
xlab="Tiempo", ylab="",
ylim=c(-0.1,0.1),
col=rgb(0,100,0,50,maxColorValue=255), pch=16,
axes=FALSE
)
axis(1, at=eje_x, label=eje_x_etiquetas)
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment