<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/visualization-of-nyc-bus-delays-with-r/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://datascienceplus.com/nyc-bus-delays/"> R Programming – DataScience+</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<ul></ul>
<p><strong>
<p>Categories</p>
<p></p></strong>
<ol>
<li><a rel="nofollow" href="https://datascienceplus.com/category/advanced-modeling/" title="Permanent Link toAdvanced Modeling" target="_blank">Advanced Modeling</a></li>
</ol>
<p><strong>
<p>Tags</p>
<p></p></strong>
<ol>
<li><a rel="nofollow" href="https://datascienceplus.com/tag/data-manipulation/" title="Permanent Link toData Manipulation" target="_blank">Data Manipulation</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/tag/data-visualisation/" title="Permanent Link toData Visualisation" target="_blank">Data Visualisation</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/tag/ggplot2/" title="Permanent Link toggplot2" target="_blank">ggplot2</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/tag/rstats/" title="Permanent Link toR Programming" target="_blank">R Programming</a></li>
</ol>
<p>The motivation for choosing this data set to explore is straightforward: I wanted a real-world data set for which additional meta data would be easy to find, making NYC data perfect; I wanted something which did not require specialised domain knowledge, and so buses are a good choice; and I wanted a data set that might produce some interesting insights. As an additional bonus, this data set had very few downloads or kernels on Kaggle, so it seemed like mostly untrodden ground.</p>
<h2>Data loading and initial exporation</h2>
<p>Data are available from <a rel="nofollow" href="https://data.cityofnewyork.us/Transportation/Bus-Breakdown-and-Delays/ez4e-fazm" target="_blank">the NYC open data site</a>. Linked is the main data page, which contains the bus breakdown ID number, as well as the route number, the schools serviced, the borough through which the bus travels, and so on.</p>
<p>The readme file included in this bundle also contains references to linking information. Specifically, the <a rel="nofollow" href="https://data.cityofnewyork.us/Transportation/Drivers-and-Attendants/4tqt-y424" target="_blank">drivers and attendants</a>, <a rel="nofollow" href="https://data.cityofnewyork.us/Transportation/Routes/8yac-vygm" target="_blank">routes</a>, <a rel="nofollow" href="https://data.cityofnewyork.us/Transportation/Transportation-Sites/hg3c-2jsy" target="_blank">transportation sites</a>, <a rel="nofollow" href="https://data.cityofnewyork.us/Transportation/Vehicles/28rh-vpvr" target="_blank">vehicles</a>, <a rel="nofollow" href="https://data.cityofnewyork.us/Transportation/PreK-Riders-by-Transportation-Site/kjgh-ywbx" target="_blank">pre-k riders by transportation site</a>, <a rel="nofollow" href="https://data.cityofnewyork.us/Transportation/Routes-by-Transportation-Sites/fgqh-vfzz" target="_blank">routes by transportation site</a>, and <a rel="nofollow" href="https://data.cityofnewyork.us/Transportation/PreK-Vendors-by-Transportation-Site/8wau-idzf" target="_blank">pre-k vendors by transportation site</a>. All of this data can be combined (see later) to provide route- and vendor- level data to the main delay data set. For example, to quanitfy the total number of drivers employed by each company, the total number of students or schools that they service, and so on.</p>
<p>Our goal is to be able to make some kind of useful prediction about how long a bus is going to be delayed, at the time its delay is called into the operations centre. So we take a look at our primary 'ii_' data set.</p>
<pre><code>in_csv &lt;- &quot;../data/II_Bus_Breakdown_and_Delays.csv&quot;
ii_breakdowns &lt;- read_csv(in_csv)
ii_breakdowns %>% glimpse</code>
<em>## Observations: 259,637
## Variables: 21
## $ School_Year </em></pre>