Skip to content

Instantly share code, notes, and snippets.

@Tafkas
Created November 13, 2013 12:48
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 Tafkas/7448533 to your computer and use it in GitHub Desktop.
Save Tafkas/7448533 to your computer and use it in GitHub Desktop.
Distribution of Birth Year and Top 10 Participating Nations in Berlin Marathon 2014
Distribution of Birth Year and Top 10 Participating Nations in Berlin Marathon 2014
setwd("~/")
bm <- read.csv("BerlinMarathon2014.csv", header=T)
library(ggplot2)
p <- ggplot(bm, aes(birth_date, ..density..))
p <- p + geom_histogram(binwidth=1, colour = "black", fill = "lightblue") + geom_density()
p + ggtitle("Distribution of Birth Year for the Berlin Marathon 2014") + xlab("Year of Birth") + ylab("Density")
# get the top 10 particpating nations
library(plyr)
top10 <- ddply(bm, "country" ,summarise, count = length(country))
top10 <- as.data.frame(lapply(top10, unlist))
top10 <- head(arrange(top10, desc(count)), n=10)
p <- ggplot(top10, aes(x = reorder(country, count, function(x) -x), y = count))
p <- p + geom_bar(colour="black", fill="lightblue", stat="identity", position="dodge")
p + ggtitle("Top 10 Participating Nations in Berlin Marathon 2014") + xlab("Country") + ylab("Particpants")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment