<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/science-of-the-super-bowl/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://jessepiburn.com/2017/02/science-of-the-super-bowl/"> R – Jesse Piburn</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>A couple days ago, I participated in a <a target="_blank" rel="nofollow" href="http://newswise.com/articles/view/668352/">Science of the Super Bowl</a> Panel discussion organized by Newswise. I was asked to give a 5 (which turned more into about 10) minute overview, so I focused on answering 3 questions.</p>
<ul>
<li>What is data science?</li>
<li>How is data science used in the NFL?</li>
<li>How might data science affect the outcome of the Super Bowl?</li>
</ul>
<p>For my <a target="_blank" rel="nofollow" href="https://vimeo.com/202280406">talk</a>  (around 21:45 mark) I made some visuals, so I thought I would recreate one here and include the R code. Here is the finished product, below is the code to reproduce it. <a target="_blank" rel="nofollow" href="http://i.imgur.com/VadWiLx.png">Here</a> is a higher res copy, that is actually readable.</p>
<p><img sizes="(max-width: 640px) 100vw, 640px" data-image-description="" data-orig-file="https://i0.wp.com/jessepiburn.com/wp-content/uploads/2017/02/rb-direction2.png?fit=3600%2C2000" data-orig-size="3600,2000" data-image-title="rb direction2" class="wp-image-207" data-comments-opened="1" data-recalc-dims="1" data-attachment-id="207" data-permalink="http://jessepiburn.com/2017/02/science-of-the-super-bowl/rb-direction2/" data-medium-file="https://i0.wp.com/jessepiburn.com/wp-content/uploads/2017/02/rb-direction2.png?fit=300%2C167" data-large-file="https://i0.wp.com/jessepiburn.com/wp-content/uploads/2017/02/rb-direction2.png?fit=640%2C356" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i0.wp.com/jessepiburn.com/wp-content/uploads/2017/02/rb-direction2.png?resize=640%2C356"></p>
<p> </p>
<pre>######################################################
# RB direction charts
# 2/1/2017
#
#
######################################################

library(nflscrapR)
library(dplyr)
library(ggplot2)
library(ggthemes)
library(gtable)
library(grid)
library(gridExtra)


# download all paly by play data for 2016 including playoffs -----
# this is going to take a while
reg_games &lt;- extracting_gameids(2016, playoffs = FALSE)
post_games &lt;- extracting_gameids(2016, playoffs = TRUE)
all_games &lt;- c(reg_games, post_games)

game_list &lt;- lapply(all_games, game_play_by_play)

s16 &lt;- bind_rows(game_list)


# calculate run percentages -----
rundf &lt;- s16 %>% filter(PlayType %in% c(&quot;Run&quot;) &amp; 
                          !is.na(down) &amp; 
                          posteam %in% c(&quot;NE&quot;, &quot;ATL&quot;)) %>%
  mutate(depth = ifelse(Yards.Gained &lt;= 0, &quot;Negative&quot;, &quot;Short&quot;),
         depth = ifelse(Yards.Gained >= 5, &quot;Middle&quot;, depth),
         depth = ifelse(Yards.Gained >= 10, &quot;Deep&quot;, depth)) %>%
  group_by(posteam, Rusher) %>%
  mutate(down_n = n()) %>% 
  group_by(posteam, Rusher, RunLocation, RunGap, depth) %>%
  summarise(play_per = (n() / mean(down_n)) * 100,
            loc_att = n(),
            total_att = mean(down_n))

# just a little clean up -----
rundf[is.na(rundf$RunLocation), &quot;RunLocation&quot;] &lt;- &quot;middle&quot;
rundf[rundf$RunLocation == &quot;middle&quot;, &quot;RunGap&quot;] &lt;- &quot;&quot;

rundf$runplace &lt;- stringr::str_trim(paste(rundf$RunLocation, rundf$RunGap))

rundf$runplace &lt;- factor(rundf$runplace, c(&quot;left end&quot;, &quot;left tackle&quot;, 
                                           &quot;left guard&quot;, &quot;middle&quot;, 
                                           &quot;right guard&quot;, &quot;right tackle&quot;, 
                                           &quot;right end&quot;))

rundf$depth &lt;- factor(rundf$depth, c(&quot;Negative&quot;, &quot;Short&quot;, &quot;Middle&quot;, &quot;Deep&quot;))

# not all RBs will have runs to all locations, so make a full data frame -----
# and join to it before charting
fulldf &lt;- expand.grid(&quot;runplace&quot; =c(&quot;left end&quot;, &quot;left tackle&quot;, &quot;left guard&quot;, 
                                    &quot;middle&quot;, &quot;right guard&quot;, &quot;right tackle&quot;, 
                                    &quot;right end&quot;), 
                      &quot;depth&quot; = c(&quot;Negative&quot;, &quot;Short&quot;, &quot;Middle&quot;, &quot;Deep&quot;))


# Devonta Freeman -----
freemandf &lt;- rundf %>% filter(Rusher == &quot;D.Freeman&quot;) %>% 
  right_join(fulldf) %>% mutate(play_per = ifelse(is.na(play_per), 0, play_per))

freeman_plot &lt;- ggplot(freemandf, aes(x = runplace, y = depth)) + 
  geom_tile(aes(fill = play_per),colour = &quot;white&quot;) +
  scale_fill_gradient(high = &quot;#ca0020&quot;, low = &quot;#0571b0&quot;, 
                      limits = c(0,15), guide_colourbar(title = &quot;%&quot;)) + 
  theme_fivethirtyeight() +
    labs(title = &quot;Devonta Freeman&quot;)


  
# Dion Lewis -----
lewisdf &lt;- rundf %>% filter(Rusher == &quot;D.Lewis&quot;) %>% 
  right_join(fulldf) %>% mutate(play_per = ifelse(is.na(play_per), 0, play_per))

  
lewis_plot &lt;-  ggplot(lewisdf, aes(x = runplace, y = depth)) + 
  geom_tile(aes(fill = play_per),colour = &quot;white&quot;) +
  scale_fill_gradient(high = &quot;#ca0020&quot;, low = &quot;#0571b0&quot;, 
                      limits = c(0,30), guide_colourbar(title = &quot;%&quot;)) + 
  theme_fivethirtyeight() +
    labs(title = &quot;Dion Lewis&quot;)


  
# blount -----  
blountdf &lt;- rundf %>% filter(Rusher == &quot;L.Blount&quot;) %>% 
  right_join(fulldf) %>% mutate(play_per = ifelse(is.na(play_per), 0, play_per))
  
  
blount_plot&lt;-  ggplot(blountdf, aes(x = runplace, y = depth)) + 
    geom_tile(aes(fill = play_per),colour = &quot;white&quot;) + 
    scale_fill_gradient(high = &quot;#ca0020&quot;, low = &quot;#0571b0&quot;, 
                        limits = c(0,15), guide_colourbar(title = &quot;%&quot;)) + 
  theme_fivethirtyeight() +
    labs(title = &quot;LeGarrette Blount&quot;)



# colemen -----  
colemandf &lt;- rundf %>% filter(Rusher == &quot;T.Coleman&quot;) %>% 
    right_join(fulldf) %>% mutate(play_per = ifelse(is.na(play_per), 0, play_per))
  

coleman_plot &lt;- ggplot(colemandf, aes(x = runplace, y = depth)) + 
    geom_tile(aes(fill = play_per),colour = &quot;white&quot;) + 
    scale_fill_gradient(high = &quot;#ca0020&quot;, low = &quot;#0571b0&quot;,
                        limits = c(0,15), guide_colourbar(title = &quot;%&quot;)) + 
  theme_fivethirtyeight() +
    labs(title = &quot;Tevin Coleman&quot;)



# combine plots and add text -----

p1 &lt;- arrangeGrob(freeman_plot, coleman_plot,
                    blount_plot, lewis_plot)

# sub title ----
titleback &lt;- rectGrob(gp=gpar(fill = &quot;#F0F0F0&quot;, col = NA))
titlesub &lt;- textGrob(&quot;2016 Run Tendency for Super Bowl Running Backs&quot;, 
                     gp = gpar(fontsize = 12, fontface = &quot;bold&quot;, 
                               fontfamily = &quot;sans&quot;, col = &quot;#3C3C3C&quot;),
                     just = &quot;left&quot;, x = unit(0.01, &quot;npc&quot;))

padding &lt;- unit(5,&quot;mm&quot;)

p1 &lt;- gtable_add_rows(p1, heights = grobHeight(titlesub) + padding, pos = 0)
p1 &lt;- gtable_add_grob(p1, grobTree(titleback, titlesub), 1, 1, 1, ncol(p1))

# title ----
title &lt;- textGrob(&quot;Which Way Did he Go?&quot;, 
                  gp = gpar(fontsize = 18, fontface = &quot;bold&quot;,
                            fontfamily = &quot;sans&quot;, col = &quot;#3C3C3C&quot;),
                  just = &quot;left&quot;, x = unit(0.01, &quot;npc&quot;))

p1 &lt;- gtable_add_rows(p1, heights = grobHeight(title) + padding, pos = 0)
p1 &lt;- gtable_add_grob(p1, grobTree(titleback, title), 1, 1, 1, ncol(p1))

# bottom ----
subtext &lt;- textGrob(&quot;Source: @JesseOPiburn&quot;,
                    gp = gpar(fontsize = 10, fontface = &quot;bold.italic&quot;,
                              fontfamily = &quot;sans&quot;, col = &quot;#3C3C3C&quot;),
                    just = &quot;left&quot;, x = unit(0.01, &quot;npc&quot;))

p1 &lt;- gtable_add_rows(p1, heights = grobHeight(subtext) + padding, pos = -1)
p1 &lt;- gtable_add_grob(p1, grobTree(titleback,subtext), t = nrow(p1), l = 1, 
                      b = nrow(p1), r = 2)
grid.draw(p1)

ggsave(plot = p1, filename = &quot;plots/rb direction.png&quot;, 
       width = 18, height = 10, units = &quot;in&quot;, dpi = 600)</pre>
<p> </p>
<p> </p>
<p> </p>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://jessepiburn.com/2017/02/science-of-the-super-bowl/"> R – Jesse Piburn</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/mho0y8SDCUk"></a></div>