Skip to content

Instantly share code, notes, and snippets.

@zjuul
Created July 9, 2019 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zjuul/57ae0eaea6ed59dbcdbbbb02c3b4a925 to your computer and use it in GitHub Desktop.
Save zjuul/57ae0eaea6ed59dbcdbbbb02c3b4a925 to your computer and use it in GitHub Desktop.
Tour de France 2019 - plot general classification
library(httr)
library(jsonlite)
library(ggplot2)
library(dplyr)
# url with TDF standings
url <- "https://sportapi.widgets.sports.gracenote.com/cycling/getresult/classificationid/2148837/languagecode/1.json?c=64&module=cycling&type=classification"
standings <- fromJSON(content(GET(url), "text")[[1]])
minutes <- 1.5 # only show riders that are this far behind the leader
ggplot(filter(standings, n_TimeRel/1000 < (60*minutes))) +
geom_bar(aes(x = reorder(c_Person, -n_TimeRel), y = n_TimeRel/1000), stat = "identity") +
coord_flip() + theme_minimal() +
xlab("") +
ylab("time difference in seconds") +
ggtitle(paste("Riders within", minutes, "minutes of leader - ",
nrow(filter(standings, n_TimeRel/1000 < (60*minutes))),"riders in TDF 2019"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment