Skip to content

Instantly share code, notes, and snippets.

@dmi3kno
Created April 18, 2019 19:09
Show Gist options
  • Save dmi3kno/9ca04c192e401c070c3c587dc0203d96 to your computer and use it in GitHub Desktop.
Save dmi3kno/9ca04c192e401c070c3c587dc0203d96 to your computer and use it in GitHub Desktop.
plotting running time distribution from
library(readxl)
library(tidyverse)
library(hms)
library(hrbrthemes)
library(extrafont)
read_excel("lundaloppet2018.xlsx", col_names = F, col_types = "text") %>%
janitor::clean_names() %>%
mutate(x2=parse_number(x2),
x5n = parse_number(x5),
x5c = factor(str_remove_all(x5, "\\d+"),
levels = c("T", "P"),
#labels=c("Women", "Men")
labels=c("Damer", "Herrar")
),
x14=parse_number(x14),
x15=parse_number(x15),
x16=parse_number(x16)) %>%
drop_na(x2) %>%
filter(x5n==5) %>%
mutate(time=x14*60*60+x15*60+x16) %>% {
ggplot(., aes(x=time, fill=x5c, color=x5c))+
#geom_histogram(bins=60)+
geom_density(alpha=0.3)+
#stat_ecdf(size=1.2)+
scale_x_time(breaks = seq(10*60, 120*60, by=10*60), expand=c(0.1, 0))+
theme_ipsum_rc(grid=FALSE)+
scale_fill_ipsum()+
scale_color_ipsum()+
#facet_wrap(vars(x5))+
labs(
title= "Resultat för Lundaloppet 2018",
subtitle= paste("Fördelning för löptider för", first(.$x5n),"km"),
caption="Källa: www.lundaloppet.se",
x="Löptider (hh:mm:ss)",
#title="Results for Lundaloppet 2018",
#subtitle= paste("Distribution of running times for", first(.$x5n),"km"),
#caption="Source: www.lundaloppet.se",
#x="Running time (hh:mm:ss)",
y=NULL, fill=NULL, color=NULL)+
theme(axis.text.y = element_blank(),
legend.position = c(0.9, 0.3))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment