<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by TallGibbs on Medium]]></title>
        <description><![CDATA[Stories by TallGibbs on Medium]]></description>
        <link>https://medium.com/@cagibbs_92472?source=rss-527a45fd300c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*1cbBLrApYAT2hi2S</url>
            <title>Stories by TallGibbs on Medium</title>
            <link>https://medium.com/@cagibbs_92472?source=rss-527a45fd300c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 14:10:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cagibbs_92472/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How To Perform an Undercut in Formula 1 — Told Using R & Data Science]]></title>
            <link>https://medium.com/@cagibbs_92472/how-to-perform-an-undercut-in-formula-1-told-using-r-data-science-22141000ee5a?source=rss-527a45fd300c------2</link>
            <guid isPermaLink="false">https://medium.com/p/22141000ee5a</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[formula-1]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[r-programming]]></category>
            <dc:creator><![CDATA[TallGibbs]]></dc:creator>
            <pubDate>Tue, 14 Nov 2023 11:40:25 GMT</pubDate>
            <atom:updated>2023-11-14T11:40:25.923Z</atom:updated>
            <content:encoded><![CDATA[<h3>How To Perform an Undercut in Formula 1 — Told Using R &amp; Data Science</h3><p>Today I want to share with you one of the fundamental strategy decisions a race engineer will make in Formula 1; to perform an undercut, or not? In order to tell this story, we are going back to 2014 to a closely fought race between Lewis Hamilton and his teammate, Nico Rosberg, at the Bahrain Grand Prix.</p><p>For those of you not intimately familiar with Formula 1, you may be wondering “What is an undercut?” The undercut is a strategy decision in which one car begins its pit stop process before another car in the hopes of gaining an advantage after the pit stop process is completed. The “pit stop process” unfolds over multiple laps and typically takes at least 4 total laps to completely be settled (when attempting an undercut). You can see this progression below in my handout which I created to tell the story of an undercut. Not only do I want to tell you this story, but I want to tell it to you using detailed visualizations I created in R.</p><p>Before we get to the data, let’s quickly review the fundamental steps to a successful undercut. To execute this strategy both the race engineer and driver must be well acquainted with this 3 step process:</p><p>1) Identify the opportunity</p><p>2) Decide to be first &amp; take the risk</p><p>3) Execute the pit stop &amp; nail the out-lap</p><p><strong>The undercut in 1 page using R and data science:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*cl5w7hbD3wwfT1pExQ5tug.png" /><figcaption>The story of an undercut unfolds at the 2014 Bahrain Grand Prix</figcaption></figure><p>The goal of this deliverable was to tell a full story in 1 page. To succeed in telling a story, we want to leverage the 3 phases of storytelling: stability, conflict, and resolution.</p><p><strong>Phase 1- Stability: </strong>In this story, the stability phase is the early part of the race when tires are fresh, there is a minimal gap between drivers and no major decisions have been made. Unfortunately, due to space constraints, a proper plot depicting the stability phase is not used. Therefore, the stability is inferred in the top-right plot by showing the early part of the race lap times (before tire degradation occurred).</p><p><strong>Phase 2- Conflict: </strong>Tire degradation begins to show by lap times increasing (the plot in Step 1) and also when the risk has been taken by being the first driver to pit. By pitting earlier, a conflict arises because there will be an immediate advantage (the undercut), but there is an unknown risk later in the race: you risk having to run a longer 2nd stint and the tires may not “hold on”. If the tires do not hold on during the 2nd stint, the driver may lose more time than they gained when performing the undercut.</p><p><strong>Phase 3- Resolution: </strong>Finally, we get a resolution to this story by seeing the results of the undercut and how the lead (gap) increased by nearly 10x. Before phase 2 began, Hamilton’s lead was only 0.5 seconds but at the end of the story, he was now leading by 5.6 seconds.</p><p>To ensure the main points of the story are visually told, a consistent color theme was used. This allowed disparity in the data to easily be seen, yet by controlling the quantity of color used there is not any increase in visual distractions.</p><p><strong>Background information: </strong>To complete the desired analysis, I was able to find an excellent dataset that is publicly available. The dataset is a historical collection of F1 race results with data about tracks, drivers, results, and, most importantly, lap times. A Kaggle user from Milton Keyes, England (“cjgdev”) made this available for us to use; you can review the <a href="https://www.kaggle.com/datasets/cjgdev/formula-1-race-data-19502017/data">Kaggle data set here</a>. The license number for sharing is CC BY-NC-SA 4.0 DEED which can be found here: <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">License Link</a>. Also, the dataset originates from the ergast data which can be found here: <a href="https://ergast.com/mrd/">ergast data</a>.</p><p>As a lifelong fan of Formula 1, I was excited to dive into this type of data and see how to tell a story using the data. My technical background comes from my bachelor’s degree in Mechanical Engineering, plus a childhood of growing up with both a father and grandfather, who were mechanical engineers. Additionally, my father raced competitively during his teenage years in both Europe and the US. Needless to say, racing and engineering have been an ever-present force in my life. On the academic side, I am pursuing my M.S. in Data Science which led to the creation of this story as a final project for my Data Visualization course.</p><p><strong>Technical Aspects, using R</strong>: Story-telling is never a straightforward task and the process of creating the final story typically requires multiple iterations. Even when constructing a “data story”, you must expect a full exploratory process until eventually settling on the final story. In this case, I knew I wanted to tell some story around lap times but my vision was not set in stone.</p><p>By conducting an initial exploration of the data, I began to hone in on what my story may become. Eventually, I determined that my story would be how to explain an “undercut” in F1 racing. To craft this story, I needed to study the data from a particular race and create 4 interesting plots to explain this story. I am not going to include my entire R code script because of the extensive length of data exploration. However, here is a snippet showing the first filtering step which narrowed my data’s focus to the 2014 Bahrain Grand Prix data.</p><pre># Overall exploration to see all drivers laptimes distribution<br><br># First, we need to create our race data frame from our main data<br># The reading in of the source CSV files is omitted for brevity.<br><br># Filter the dataset first to only study the 2014 Bahrain Grand Prix:<br>df_2014_Bahrain = df_main %&gt;% <br>   filter(<br>     year == &#39;2014&#39;,<br>     race_event_name == &#39;Bahrain Grand Prix&#39;) %&gt;% <br>  as.data.frame()<br><br># Use a boxplot to quickly see what may stand out<br>ggboxplot(<br>  df_2014_Bahrain,<br>  y = &#39;lap_time_sec&#39;,<br>  x = &#39;driver_code&#39;<br>)<br><br># After reviewing the boxplot, we can see that 2 drivers had noticeably<br># lower lap time distributions.  <br># This was &quot;HAM&quot; and &quot;ROS&quot;<br><br># Let&#39;s filter the dataset further to zoom in on this:<br>df_2014_Bahrain_2drivers = df_2014_Bahrain %&gt;% filter(<br>  driver_code %in% c(&#39;HAM&#39;, &#39;ROS&#39;)) %&gt;% <br>    as.data.frame()</pre><p>Now we have a dataset of particular interest to us, we need to create different aggregations to plot our desired elements of the story. The details of all these aggregations, again, are omitted for brevity but are available if desired. Please comment below if you would like a full copy of the R code.</p><pre># Plot 1 to show the lead time change and explain the undercut<br># This is just a simple barchart with formatting:<br><br>ggbarplot(<br>  df_gap,<br>  x = &#39;Status&#39;,<br>  y = &#39;Gap&#39;,<br>  label = TRUE,<br>  lab.size = c(20, 14),<br>  lab.pos = &#39;in&#39;,<br>  lab.h = c(1, 1),<br>  lab.v = c(0.5, 0.8),<br>  xlab = &#39;&#39;,<br>  ylab = &#39;Lead (Sec)&#39;,<br>  orientation = &#39;horizontal&#39;,<br>  order = c(&#39;After&#39;, &#39;Before&#39;),<br>  color = &#39;Status&#39;,<br>  fill = &#39;Status&#39;,<br>  palette = c(&#39;#a52dc2&#39;, &#39;#c4c4c4&#39;),<br>  title = &#39;An undercut can increase your lead by 10x!&#39;,<br>  subtitle = &quot;When done correctly, an undercut will increase a driver&#39;s lead after the<br>pit stops are completed.  An undercut is when a driver pits earlier.&quot;<br>) + font(&#39;title&#39;, size = 50, face = &#39;bold&#39;, family = &#39;Tahoma&#39;, color = &#39;#a52dc2&#39;) +<br>  font(&#39;subtitle&#39;, size = 35, family = &#39;Tahoma&#39;, color =&#39;black&#39; ) +<br>  font(&quot;x.text&quot;, family = &#39;Arial&#39;, size = 30) +<br>  font(&quot;y.text&quot;, family = &#39;Arial&#39;, size = 35) +<br>  font(&quot;xy.title&quot;, family = &#39;Arial&#39;, size = 20, face = &#39;bold&#39;) +<br>  theme(aspect.ratio = 1.5/5,<br>        legend.position = &quot;right&quot;,<br>        legend.title = element_blank(),<br>        legend.text = element_text(size = 20)<br>  ) +<br>  easy_remove_legend()</pre><pre># Plot 2- Create the lollipop chart showing tire degradation:<br><br>ggdotchart(<br>  df_tire_deg,<br>  x = &#39;lap&#39;,<br>  y = &#39;lap_time_sec&#39;,<br>  ylab = &#39;Lap Time (sec)&#39;,<br>  xlab = &#39;Lap Number&#39;,<br>  ylim = c(99, 103),<br>  color = &#39;black&#39;,<br>  palette = c(&#39;#c4c4c4&#39;),<br>  add = &#39;segments&#39;,<br>  dot.size = 7,<br>  sorting = &quot;none&quot;,<br>  size = 3,<br>  title = &#39;Step 1: Identify the opportunity&#39;,<br>  subtitle = &#39;Tire degradation&#39;<br>  )  + <br>  font(&#39;title&#39;, size = 50, face = &#39;bold&#39;, family = &#39;Tahoma&#39;, color = &#39;#a52dc2&#39;) +<br>  font(&#39;subtitle&#39;, size = 35, family = &#39;Tahoma&#39;, color =&#39;black&#39; ) +<br>  font(&quot;x.text&quot;, family = &#39;Arial&#39;, size = 30) +<br>  font(&quot;y.text&quot;, family = &#39;Arial&#39;, size = 35) +<br>  font(&quot;xy.title&quot;, family = &#39;Arial&#39;, size = 20, face = &#39;bold&#39;) +<br>  theme(aspect.ratio = 1.5/4,<br>        legend.position = &quot;right&quot;,<br>        legend.title = element_blank(),<br>        legend.text = element_text(size = 20)<br>        )</pre><pre># Plot 3 - Hamilton deciding to pit before Rosberg-<br><br>ggline(<br>  df_pit_stop,<br>  x = &#39;lap&#39;,<br>  y = &#39;lap_time_sec&#39;,<br>  xlab = &#39;Lap Number&#39;,<br>  ylab = &#39;Lap Time (sec)&#39;,<br>  color = &#39;driver_code&#39;,<br>  palette = c(&#39;#a52dc2&#39;, &#39;#c4c4c4&#39;),<br>  size = 3,<br>  point.size = 8,<br>  title = &#39;Step 2: Take the risk  <br>Hamilton pits first, attempts the undercut.&#39;,<br>  subtitle = &#39;We can see Hamilton pits on lap 20 which gives him 2 laps at <br>a faster pace than Rosberg.  We expect this to increase his lead.&#39;<br> ) + <br>  font(&#39;title&#39;, size = 50, face = &#39;bold&#39;, family = &#39;Tahoma&#39;, color = &#39;#a52dc2&#39;) +<br>  font(&#39;subtitle&#39;, size = 35, family = &#39;Tahoma&#39;, color =&#39;black&#39; ) +<br>  font(&quot;x.text&quot;, family = &#39;Arial&#39;, size = 30) +<br>  font(&quot;y.text&quot;, family = &#39;Arial&#39;, size = 35) +<br>  font(&quot;xy.title&quot;, family = &#39;Arial&#39;, size = 20, face = &#39;bold&#39;) +<br>  theme(aspect.ratio = 1.5/4,<br>        legend.position = &quot;right&quot;,<br>        legend.title = element_blank(),<br>        legend.text = element_text(size = 20)<br>       )<br></pre><pre><br># PLOT 4-<br># Do a horizontal barplot with facet showing the laptime comparisons and the lead<br># highlight the pitstop being executed &amp; the out lap (laps 20, 21, 22).<br><br>ggbarplot(<br>  df_pit_stop_laptimes,<br>  x = &#39;lap_string&#39;,<br>  y = &#39;lap_time_sec&#39;,<br>  ylab = &#39;&#39;,<br>  xlab = &#39;Lap Number&#39;,<br>  title = &#39;Step 3: Execute<br>Hamilton executes his pit stop &amp; out lap perfectly.&#39;,<br>  subtitle = &#39;By driving his fastest laps while Rosberg was doing his slowest laps, Hamlton increased his lead by <br>executing the undercut perfectly.&#39;,<br>  orientation =&#39;horizontal&#39;,<br>  facet.by = &#39;driver_code&#39;,<br>  color = &#39;before_pit_sequence&#39;,<br>  fill = &#39;before_pit_sequence&#39;,<br>  palette = c(&#39;#a52dc2&#39;, &#39;#c4c4c4&#39;),<br>  label = TRUE,<br>  lab.size = c(6, 6, 12, 12, 6, 6, 6, 6,6, 6, 12, 12, 6, 6, 6, 6,6, 6, 12, 12, 6, 6, 6, 6),<br>  lab.pos = &#39;in&#39;,<br>  lab.h = c(rep(1.5, 24)),<br>  lab.v = 0.5<br>  #lab.v = c(0.5, 0.8),<br>  #labeller = labeller(c(&#39;Hamilton&#39;, &#39;Robserg&#39;, &#39;Difference&#39;))<br>  ) + <br>  theme(aspect.ratio = 5/4) +<br>  facet_wrap(&#39;driver_code&#39;, scales = &#39;free_x&#39;) +<br>  easy_remove_legend() + <br>  easy_remove_x_axis() +<br>  font(&#39;title&#39;, size = 40, face = &#39;bold&#39;, family = &#39;Tahoma&#39;, color = &#39;#a52dc2&#39;) +<br>  font(&#39;subtitle&#39;, size = 25, family = &#39;Tahoma&#39;, color =&#39;black&#39;) +<br>  #font(&quot;x.text&quot;, family = &#39;Arial&#39;, size = 30) +<br>  font(&quot;y.text&quot;, family = &#39;Arial&#39;, size = 25) +<br>  font(&quot;xy.title&quot;, family = &#39;Arial&#39;, size = 30)</pre><p>Thanks for reading and please comment below and let me know what you learned! Hope to see you at the next race :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22141000ee5a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>