<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/nfl-series/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://tlfvincent.github.io//2017/10/08/nlf-running-back-deep-dive/"> StatOfMind</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>If you have previously attempted to analyze NFL data, it is likely that you have tried to scrape ESPN or football-reference, which provides a wealth on statistics surrounding game data. However, if you ever wanted to obtain truly in-depth data, then it is likely that you found yourself leveraging the API maintained by NFL.com. Unfortunately, it’s data is surfaced in a <code>JSON</code> format that leaves a lot to be desired (i.e. it’s a nightmare). Lucky for me, I was recently scrolling through my Twitter feed and came across an interesting mention of a new R package called <code>nflscrapR</code>. After some exploration, I came through this quote from the author of the package:</p>
<div>
<pre><code>NFL fans and sports enthusiastic alike, I would like to introduce the nflscrapR package, an American football data aggregator that will scrape, clean, and parse play-by-play data across games, seasons, and careers.
</code></pre>
</div>
<p>The <code>nflscrapR</code> essentiallys surfaces all play-by-play data for the last 7 seasons, and this has motivated me to start a deep dive on NFL data. I plan to have two main topics, one that focusses on players at specific positions, and another focussing on team dynamics and patterns. To kick this series off, we will begin with an <em>exploration into the performance of NFL’s best running backs</em>.</p>
<h3>1. Prerequisites</h3>
<p>In order to reproduce the figures below, wou will need to have <code>R</code> (v3.2.3 or above) installed on your machine. There are also a couple of additional libraries that will be required. Details on how to install those are shown in the commands below.</p>
<figure>
<pre><code data-lang="r"><span># install.packages('devtools')
</span><span>
</span><span>library</span><span>(</span><span>devtools</span><span>)</span><span>
</span><span>#> Skipping install for github remote, the SHA1 (05815ef8) has not changed since last install.
#> Use `force = TRUE` to force installation
</span><span>
</span><span>devtools</span><span>::</span><span>install_github</span><span>(</span><span>repo</span><span> </span><span>=</span><span> </span><span>&quot;maksimhorowitz/nflscrapR&quot;</span><span>,</span><span> </span><span>force</span><span>=</span><span>TRUE</span><span>)</span></code></pre>
</figure>
<h3>2 Collecting the Data</h3>
<p>With the <code>nflscrapR</code> library now installed, you are now ready to collect play-by-play data for the 2016-2017 NFL season. Start by loading the library and collect the data using the command below:</p>
<figure>
<pre><code data-lang="r"><span># Load the package
</span><span>
</span><span>library</span><span>(</span><span>nflscrapR</span><span>)</span><span>
</span><span>library</span><span>(</span><span>ggplot2</span><span>)</span><span>
</span><span>library</span><span>(</span><span>dplyr</span><span>)</span><span>
</span><span>library</span><span>(</span><span>pheatmap</span><span>)</span><span>
</span><span># Collect data for 2016 NFL season
</span><span>
</span><span>pbp_2016</span><span> </span><span>&lt;-</span><span> </span><span>season_play_by_play</span><span>(</span><span>2016</span><span>)</span></code></pre>
</figure>
<p>Overall the <code>pbp_2016</code> dataframe contains 100 data points for 45,737 plays, but for the purpose of this post, we will be focussing exclusively on fields related to running backs (In future posts, we will explore data relevant to other positions on the football field). In addition, we’ll focus primarily on frequently used running backs, which we empirically define as any player that has had at least 200 rushes over the course of the 2016-2017 season.</p>
<figure>
<pre><code data-lang="r"><span># Get all players with at least 200 rushes during the season
</span><span>
</span><span>min_rush_cnt</span><span> </span><span>&lt;-</span><span> </span><span>200</span><span>
</span><span>rush_cnt</span><span> </span><span>&lt;-</span><span> </span><span>pbp_2016</span><span> </span><span>%>%</span><span> </span><span>filter</span><span>(</span><span>PlayType</span><span> </span><span>==</span><span> </span><span>'Run'</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>group_by</span><span>(</span><span>Rusher</span><span>)</span><span> </span><span>%>%</span><span> </span><span>summarise</span><span>(</span><span>rush_cnt</span><span> </span><span>=</span><span> </span><span>n</span><span>(),</span><span>
</span><span>total_yards</span><span> </span><span>=</span><span> </span><span>sum</span><span>(</span><span>Yards.Gained</span><span>),</span><span>
</span><span>mean_yards</span><span> </span><span>=</span><span> </span><span>round</span><span>(</span><span>mean</span><span>(</span><span>Yards.Gained</span><span>),</span><span> </span><span>2</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>filter</span><span>(</span><span>rush_cnt</span><span> </span><span>>=</span><span> </span><span>min_rush_cnt</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>arrange</span><span>(</span><span>desc</span><span>(</span><span>rush_cnt</span><span>))</span><span>
</span><span># Get all rushing data for eligible players
</span><span>
</span><span>rushing_stats</span><span> </span><span>&lt;-</span><span> </span><span>pbp_2016</span><span> </span><span>%>%</span><span>
</span><span>filter</span><span>(</span><span>PlayType</span><span> </span><span>==</span><span> </span><span>'Run'</span><span> </span><span>&amp;</span><span> </span><span>Rusher</span><span> </span><span>%in%</span><span> </span><span>rush_cnt</span><span>$</span><span>Rusher</span><span> </span><span>&amp;</span><span> </span><span>Yards.Gained</span><span> </span><span>&lt;=</span><span>50</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>filter</span><span>(</span><span>down</span><span>!=</span><span>4</span><span> </span><span>&amp;</span><span> </span><span>!</span><span>is.na</span><span>(</span><span>down</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>filter</span><span>(</span><span>!</span><span>is.na</span><span>(</span><span>RunLocation</span><span>))</span></code></pre>
</figure>
<p>Altogether, we find that a total of 19 players rushed over 200 times during the 2016-2017 season. A short summary of their performance is show below.</p>
<p><center><br>
<iframe width="450" allowfullscreen="allowfullscreen" src="https://statofmind-blog.nyc3.digitaloceanspaces.com/images/top_rushers.html"></iframe><br>
</center></p>
<h3>3. Who are the most consistent and productive running backs?</h3>
<p>When talking about the overall performance of running backs, it is common for people to report the total number of yards that were rushed for, or the average yards per run. While these are perfectly acceptable numbers to share, I’ve always felt like they did not tell the whole story. For example, a player could have a high average yards per run, only for us to realize that he actually often loses yards on a run but makes up for it with a few very long runs. Therefore, I started by looking at the overall distribution of number of yards gained/lost for each play, with the hope that this would reveal whether some players were more consistent on a play-by-play basis than others. We can use the <code>ggplot2</code> library to generate a density plot of yards gained per play for each of our eligible players:</p>
<figure>
<pre><code data-lang="r"><span># Compare distribution of rushes for eligible players
</span><span>
</span><span>ggplot</span><span>(</span><span>rushing_stats</span><span>,</span><span> </span><span>aes</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>Yards.Gained</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>Rusher</span><span>,</span><span> </span><span>fill</span><span>=</span><span>Rusher</span><span>))</span><span> </span><span>+</span><span>
</span><span>geom_joy</span><span>(</span><span>scale</span><span> </span><span>=</span><span> </span><span>3</span><span>)</span><span> </span><span>+</span><span>
</span><span>theme_joy</span><span>()</span><span> </span><span>+</span><span>
</span><span>scale_fill_manual</span><span>(</span><span>values</span><span>=</span><span>rep</span><span>(</span><span>c</span><span>(</span><span>'gray'</span><span>,</span><span> </span><span>'lightblue'</span><span>),</span><span> </span><span>length</span><span>(</span><span>rushing_stats</span><span>$</span><span>Rusher</span><span>)</span><span>/</span><span>2</span><span>))</span><span> </span><span>+</span><span>
</span><span>scale_y_discrete</span><span>(</span><span>expand</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>0.01</span><span>,</span><span> </span><span>0</span><span>))</span><span> </span><span>+</span><span>
</span><span>scale_x_continuous</span><span>(</span><span>expand</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>0</span><span>,</span><span> </span><span>0</span><span>))</span><span> </span><span>+</span><span>
</span><span>theme</span><span>(</span><span>legend.position</span><span>=</span><span>&quot;none&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>labs</span><span>(</span><span>x</span><span>=</span><span>&quot;Yards gained per play&quot;</span><span> </span><span>,</span><span>y</span><span>=</span><span>&quot;&quot;</span><span>)</span></code></pre>
</figure>
<p><img alt="Yards gained by run" src="https://i0.wp.com/tlfvincent.github.io/img/nlf-running-back-deep-dive-fig1.png?w=456" data-recalc-dims="1"></p>
<p>Overall, we see that most running backs have a similar distribution of yards gained by run. However, we can see that LeSean McCoy (7th distribution from the top) has a much “flatter” distribution (i.e. more variance in the distribution of yards gained per run), meaning his performance can be a lot more variable/unpredictable for any given run.</p>
<h3>4. When are running backs used?</h3>
<p>Another statement that is also commonly reported is that running backs are primarily used in early downs. To verify whether this is generall true, we can compute the total amount of runs that each player made across different downs, and go even further by breaking this down by quarter too. The code chunk below counts the number of runs that each rushing back made during pairs of downs and quarters.</p>
<figure>
<pre><code data-lang="r"><span># Compare when rushers are used
</span><span>
</span><span>usage_stats</span><span> </span><span>&lt;-</span><span> </span><span>pbp_2016</span><span> </span><span>%>%</span><span> </span><span>filter</span><span>(</span><span>!</span><span>is.na</span><span>(</span><span>down</span><span>)</span><span> </span><span>&amp;</span><span> </span><span>Rusher</span><span> </span><span>%in%</span><span> </span><span>rush_cnt</span><span>$</span><span>Rusher</span><span> </span><span>&amp;</span><span> </span><span>qtr</span><span>!=</span><span>5</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>group_by</span><span>(</span><span>Rusher</span><span>,</span><span> </span><span>down</span><span>,</span><span> </span><span>qtr</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>summarise</span><span>(</span><span>cnt</span><span> </span><span>=</span><span> </span><span>n</span><span>())</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>qtr_down</span><span> </span><span>=</span><span> </span><span>paste</span><span>(</span><span>&quot;Q&quot;</span><span>,</span><span> </span><span>qtr</span><span>,</span><span> </span><span>&quot;- Down: &quot;</span><span>,</span><span> </span><span>down</span><span>,</span><span> </span><span>sep</span><span>=</span><span>&quot;&quot;</span><span>))</span></code></pre>
</figure>
<p>We can then leverage the <code>d3heatmap</code> to quickly generate a simple heatmap of how often running backs are used during specific downs and quarters.</p>
<figure>
<pre><code data-lang="r"><span>library</span><span>(</span><span>d</span><span>3</span><span>heatmap</span><span>)</span><span>
</span><span># pivot dataframe
</span><span>
</span><span>usage</span><span> </span><span>&lt;-</span><span> </span><span>usage_stats</span><span> </span><span>%>%</span><span> </span><span>dcast</span><span>(</span><span>Rusher</span><span> </span><span>~</span><span> </span><span>qtr_down</span><span>,</span><span> </span><span>value.var</span><span> </span><span>=</span><span> </span><span>&quot;cnt&quot;</span><span>)</span><span>
</span><span># clean data
</span><span>
</span><span>row.names</span><span>(</span><span>usage</span><span>)</span><span> </span><span>&lt;-</span><span> </span><span>usage</span><span>$</span><span>Rusher</span><span>
</span><span>usage</span><span> </span><span>&lt;-</span><span> </span><span>usage</span><span> </span><span>%>%</span><span> </span><span>select</span><span>(</span><span>-</span><span>Rusher</span><span>)</span><span>
</span><span>usage</span><span>[</span><span>is.na</span><span>(</span><span>usage</span><span>)]</span><span> </span><span>&lt;-</span><span> </span><span>0</span><span>
</span><span># normalize data
</span><span>
</span><span>usage_norm</span><span> </span><span>&lt;-</span><span> </span><span>t</span><span>(</span><span>apply</span><span>(</span><span>usage</span><span>,</span><span> </span><span>1</span><span>,</span><span> </span><span>function</span><span>(</span><span>x</span><span>)</span><span> </span><span>x</span><span>/</span><span>sum</span><span>(</span><span>x</span><span>)))</span><span>
</span><span># Plot heatmap of proportions of rushes by different field locations and gaps
</span><span>
</span><span>p</span><span> </span><span>&lt;-</span><span> </span><span>d</span><span>3</span><span>heatmap</span><span>(</span><span>usage_norm</span><span>,</span><span>
</span><span>colors</span><span>=</span><span>&quot;Blues&quot;</span><span>,</span><span>
</span><span>Colv</span><span>=</span><span>FALSE</span><span>,</span><span>
</span><span>show_grid</span><span>=</span><span>3</span><span>)</span><span>
</span><span>saveWidget</span><span>(</span><span>p</span><span>,</span><span> </span><span>file</span><span>=</span><span>&quot;rusher_usage_down_quarter.html&quot;</span><span>)</span></code></pre>
</figure>
<p><center>
<h5>Proportion of rushes per quarter and downs for NFLs best running backs</h5>
<p> <iframe width="450" src="https://statofmind-blog.nyc3.digitaloceanspaces.com/images/rusher_usage_down_quarter.html"></iframe><br>
</p>
<p>In the plot above, we are essentially plotting the usage of each running back as a function of what stage of the game we are in. As we can see, it is abundantly clear that running backs are primarily used in the first two downs, and rarely during the third and fourth downs. Overall, there does not appear to be significant differences between how players are used. However, it does not answer whether some running backs perform better on certains downs, which is what we will address now.</p>
<h3>5. Are some running backs better on certain downs?</h3>
<p>Another question we can ask ourselves is whether some running backs perform better on later downs. To visualize this data, we can again generate a density plot of yards gained per play for each of our eligible players, while also facetting the data by downs.</p>
<figure>
<pre><code data-lang="r"><span># Compare distribution of rushes by downs
</span><span>
</span><span>ggplot</span><span>(</span><span>rushing_stats</span><span>,</span><span> </span><span>aes</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>Yards.Gained</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>down</span><span>))</span><span> </span><span>+</span><span>
</span><span>geom_joy</span><span>(</span><span>scale</span><span>=</span><span>1</span><span>,</span><span> </span><span>rel_min_height</span><span>=</span><span>.03</span><span>,</span><span> </span><span>fill</span><span>=</span><span>'black'</span><span>)</span><span> </span><span>+</span><span>
</span><span>scale_y_discrete</span><span>(</span><span>expand</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>0.01</span><span>,</span><span> </span><span>0</span><span>))</span><span> </span><span>+</span><span>
</span><span>xlab</span><span>(</span><span>'Value'</span><span>)</span><span> </span><span>+</span><span>
</span><span>facet_wrap</span><span>(</span><span>~</span><span>Rusher</span><span>,</span><span> </span><span>scales</span><span>=</span><span>'free'</span><span>,</span><span> </span><span>ncol</span><span>=</span><span>3</span><span>)</span><span> </span><span>+</span><span>
</span><span>theme_joy</span><span>()</span><span> </span><span>+</span><span>
</span><span>theme</span><span>(</span><span>axis.title.y</span><span> </span><span>=</span><span> </span><span>element_blank</span><span>())</span><span>+</span><span>
</span><span>labs</span><span>(</span><span>x</span><span>=</span><span>&quot;Yards gained per play&quot;</span><span> </span><span>,</span><span>y</span><span>=</span><span>&quot;Down&quot;</span><span>)</span></code></pre>
</figure>
<p><img alt="Yards gained by run" src="https://i2.wp.com/tlfvincent.github.io/img/nlf-running-back-deep-dive-fig2.png?w=456" data-recalc-dims="1"></p>
<p>Again, we do not see any striking differences between players and the distribution of yards gained by down. However, it is interesting to note that most “long runs” (10 yards or above) tend to occur on the first down. When we look closely, we can also see that some rushers such as DeMarco Murray do exhibit visual differences between yards gained by downs. In this case, the “mass” of yards gained on the third down is much closer to zero than when compared to the “mass” for the first and second downs, which suggests that he may struggle during this down (this could be attributable to many factors: stamina, weaker offensive line on 3rd downs, etc…)</p>
<h3>6. Where do the best running backs run?</h3>
<p>It is fairly well accepted that the performance of a running back will be heavily influenced by the strength of the offensive line in front of them. With that in mind, let’s start by looking at the field location in which different running backs prefer to run. The plot below shows the number of yards gained by each running back based on which side of the field they ran towards (left, middle or right).</p>
<figure>
<pre><code data-lang="r"><span>ggplot</span><span>(</span><span>data</span><span>=</span><span>rushing_stats</span><span>,</span><span> </span><span>aes</span><span>(</span><span>x</span><span>=</span><span>RunLocation</span><span>,</span><span> </span><span>y</span><span>=</span><span>Yards.Gained</span><span>,</span><span> </span><span>color</span><span>=</span><span>RunLocation</span><span>))</span><span> </span><span>+</span><span>
</span><span>geom_jitter</span><span>(</span><span>position</span><span>=</span><span>position_jitter</span><span>(</span><span>0.2</span><span>))</span><span> </span><span>+</span><span>
</span><span>stat_summary</span><span>(</span><span>fun.data</span><span>=</span><span>mean_sdl</span><span>,</span><span> </span><span>mult</span><span>=</span><span>1</span><span>,</span><span> </span><span>geom</span><span>=</span><span>&quot;pointrange&quot;</span><span>,</span><span> </span><span>color</span><span>=</span><span>&quot;black&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>scale_color_brewer</span><span>(</span><span>palette</span><span>=</span><span>&quot;Dark2&quot;</span><span>)</span><span> </span><span>+</span><span> </span><span>theme_minimal</span><span>()</span><span> </span><span>+</span><span>
</span><span>facet_wrap</span><span>(</span><span>~</span><span>Rusher</span><span>)</span></code></pre>
</figure>
<p><img alt="Yards gained by run" src="https://i0.wp.com/tlfvincent.github.io/img/nlf-running-back-deep-dive-fig4.png?w=456" data-recalc-dims="1"></p>
<p>We can take this further by looking at the field location in which different running backs prefer to run. This can be achieved by generating a matrix that contains the proportion of rushes by field location for each player.</p>
<figure>
<pre><code data-lang="r"><span># Get proportions of rushes on different field locations
</span><span>
</span><span>rush_locations</span><span> </span><span>&lt;-</span><span> </span><span>rushing_stats</span><span> </span><span>%>%</span><span> </span><span>filter</span><span>(</span><span>PlayType</span><span>==</span><span>'Run'</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>filter</span><span>(</span><span>!</span><span>is.na</span><span>(</span><span>RunLocation</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>group_by</span><span>(</span><span>Rusher</span><span>,</span><span> </span><span>RunLocation</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>summarise</span><span>(</span><span>rush_cnt</span><span> </span><span>=</span><span> </span><span>n</span><span>())</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>freq</span><span> </span><span>=</span><span> </span><span>rush_cnt</span><span> </span><span>/</span><span> </span><span>sum</span><span>(</span><span>rush_cnt</span><span>))</span><span>
</span><span>loc_mat</span><span> </span><span>&lt;-</span><span> </span><span>rush_locations</span><span> </span><span>%>%</span><span> </span><span>dcast</span><span>(</span><span>Rusher</span><span> </span><span>~</span><span> </span><span>RunLocation</span><span>,</span><span> </span><span>value.var</span><span> </span><span>=</span><span> </span><span>&quot;freq&quot;</span><span>)</span><span>
</span><span>row.names</span><span>(</span><span>loc_mat</span><span>)</span><span> </span><span>&lt;-</span><span> </span><span>loc_mat</span><span>$</span><span>Rusher</span><span>
</span><span>loc_mat</span><span> </span><span>&lt;-</span><span> </span><span>loc_mat</span><span> </span><span>%>%</span><span> </span><span>select</span><span>(</span><span>-</span><span>Rusher</span><span>)</span></code></pre>
</figure>
<p>The content of the <code>loc_mat</code> matrix contains the preferred rush locations of each running back, and can be plotted as a clustered heatmaps using the <code>pheatmap</code> library in <code>R</code>.</p>
<figure>
<pre><code data-lang="r"><span># Plot heatmap of proportions of rushes by different field locations
</span><span>
</span><span>pheatmap</span><span>(</span><span>loc_mat</span><span>,</span><span> </span><span>border</span><span>=</span><span>&quot;white&quot;</span><span>,</span><span> </span><span>color</span><span> </span><span>=</span><span> </span><span>brewer.pal</span><span>(</span><span>9</span><span>,</span><span>&quot;Blues&quot;</span><span>),</span><span> </span><span>cluster_cols</span><span>=</span><span>FALSE</span><span>)</span></code></pre>
</figure>
<p><img alt="Rushes by field location" src="https://i2.wp.com/tlfvincent.github.io/img/nlf-running-back-deep-dive-fig3a.png?w=456" data-recalc-dims="1"></p>
<p>The plot above highlights which running back are most similar in their run locations. Rushers such as J. Ajayi, E. Elliot and M. Ingram, clearly avoid running in the middle of the field. On the flipside, rushers such as M. Gordon D. Johnson, S.ware and F. Gore clearly prefer running down the middle rather than to the sides. These patterns could be attributed to the running styles of each rushers (speed, mobility, strength etc…), but also the strength of the offensive line at particular positions.</p>
<h3>7. Who creates the gaps for the running backs?</h3>
<p>We can also explore the number of yards gained by each running back based on the offensive line positions that created space for them.</p>
<figure>
<pre><code data-lang="r"><span>ggplot</span><span>(</span><span>data</span><span>=</span><span>rushing_stats</span><span> </span><span>%>%</span><span> </span><span>filter</span><span>(</span><span>!</span><span>is.na</span><span>(</span><span>RunGap</span><span>)),</span><span> </span><span>aes</span><span>(</span><span>x</span><span>=</span><span>RunGap</span><span>,</span><span> </span><span>y</span><span>=</span><span>Yards.Gained</span><span>,</span><span> </span><span>color</span><span>=</span><span>RunGap</span><span>))</span><span> </span><span>+</span><span>
</span><span>geom_jitter</span><span>(</span><span>position</span><span>=</span><span>position_jitter</span><span>(</span><span>0.2</span><span>))</span><span> </span><span>+</span><span>
</span><span>stat_summary</span><span>(</span><span>fun.data</span><span>=</span><span>mean_sdl</span><span>,</span><span> </span><span>mult</span><span>=</span><span>1</span><span>,</span><span> </span><span>geom</span><span>=</span><span>&quot;pointrange&quot;</span><span>,</span><span> </span><span>color</span><span>=</span><span>&quot;black&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>scale_color_brewer</span><span>(</span><span>palette</span><span>=</span><span>&quot;Dark2&quot;</span><span>)</span><span> </span><span>+</span><span> </span><span>theme_minimal</span><span>()</span><span> </span><span>+</span><span>
</span><span>facet_wrap</span><span>(</span><span>~</span><span>Rusher</span><span>)</span></code></pre>
</figure>
<p><img alt="Yards gained by run" src="https://i2.wp.com/tlfvincent.github.io/img/nlf-running-back-deep-dive-fig5.png?w=456" data-recalc-dims="1"></p>
<p>The proportions of run opportunities that was enabled by each offensive line position can also be summarized in a matrix using the command below.</p>
<figure>
<pre><code data-lang="r"><span># Get proportions of gaps created by different offensive line positions
</span><span>
</span><span>rush_gaps</span><span> </span><span>&lt;-</span><span> </span><span>rushing_stats</span><span> </span><span>%>%</span><span> </span><span>filter</span><span>(</span><span>!</span><span>is.na</span><span>(</span><span>RunGap</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>filter</span><span>(</span><span>!</span><span>is.na</span><span>(</span><span>RunGap</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>group_by</span><span>(</span><span>Rusher</span><span>,</span><span> </span><span>RunGap</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>summarise</span><span>(</span><span>rush_cnt</span><span> </span><span>=</span><span> </span><span>n</span><span>())</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>freq</span><span> </span><span>=</span><span> </span><span>rush_cnt</span><span> </span><span>/</span><span> </span><span>sum</span><span>(</span><span>rush_cnt</span><span>))</span><span>
</span><span>gap_mat</span><span> </span><span>&lt;-</span><span> </span><span>rush_gaps</span><span> </span><span>%>%</span><span> </span><span>dcast</span><span>(</span><span>Rusher</span><span> </span><span>~</span><span> </span><span>RunGap</span><span>,</span><span> </span><span>value.var</span><span> </span><span>=</span><span> </span><span>&quot;freq&quot;</span><span>)</span><span>
</span><span>row.names</span><span>(</span><span>gap_mat</span><span>)</span><span> </span><span>&lt;-</span><span> </span><span>gap_mat</span><span>$</span><span>Rusher</span><span>
</span><span>gap_mat</span><span> </span><span>&lt;-</span><span> </span><span>gap_mat</span><span> </span><span>%>%</span><span> </span><span>select</span><span>(</span><span>-</span><span>Rusher</span><span>)</span></code></pre>
</figure>
<figure>
<pre><code data-lang="r"><span># Plot heatmap of proportions of rushes by different field gaps
</span><span>
</span><span>pheatmap</span><span>(</span><span>gap_mat</span><span>,</span><span> </span><span>border</span><span>=</span><span>&quot;white&quot;</span><span>,</span><span> </span><span>color</span><span> </span><span>=</span><span> </span><span>brewer.pal</span><span>(</span><span>9</span><span>,</span><span>&quot;Blues&quot;</span><span>),</span><span> </span><span>cluster_cols</span><span>=</span><span>FALSE</span><span>)</span></code></pre>
</figure>
<p><img alt="Gaps created by Offensive Line Position" src="https://i0.wp.com/tlfvincent.github.io/img/nlf-running-back-deep-dive-fig3b.png?w=456" data-recalc-dims="1"></p>
<p>Again, we see many differences among the leagues top running backs. Unsurprisingly, a number of players have the most run opportunities created by the guard position, but a few players such as F. Gore, L. McCoy and D. Johnson run in gaps created by the tackle position. Finally, S. Ware from the Kansas City Chiefs often runs through gaps created by tight ends, which may be more representative of the team’s formation.</p>
<h3>Conclusion</h3>
<p>In this introductory post, we have explored the performance and patterns of some of NFL’s best running backs. Overall, it was a fairly superficial analysis, as it never considered interactions with other components of the team, or temporal patterns, but it does show the depth and power of this data. In the next series, I will dive into the performance and behavior of wide receivers, so stay tuned!</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://tlfvincent.github.io//2017/10/08/nlf-running-back-deep-dive/"> StatOfMind</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 rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/OCAqEk7X9n8" height="1"></a></div></center>