Skip to content

Instantly share code, notes, and snippets.

@zjuul
Created Jul 9, 2019
Embed
What would you like to do?
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