Skip to content

Instantly share code, notes, and snippets.

Created January 4, 2013 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4448895 to your computer and use it in GitHub Desktop.
Save anonymous/4448895 to your computer and use it in GitHub Desktop.
plot no huddle plays by team by quarter in R
setwd("R/")
setwd("NFL Play-by-Play Data 2002-2012/")
## read in the sweet, sweet NFL data
n <- read.csv("2012_nfl_pbp_data_reg_season.csv", header=TRUE)
## grab the no huddle plays
nh <- n[grep("Huddle", n$description),]
## table by offensive team and quarter
nh.df <- data.frame(table(nh$off, nh$qtr))[-1,]
colnames(nh.df) <- c("Team", "Quarter", "Number")
## plot bar chart, ordered by number of plays and colored by quarter
ggplot(x, aes(x=reorder(Team, Number), y=Number, fill=Quarter)) + geom_bar() + labs(x="Team", y="Number", title="Number of No Huddle Plays in the NFL by Team by Quarter") + theme(axis.text.x = element_text(angle = 50, hjust = 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment