<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/data-science-for-operational-excellence-part-3/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.r-exercises.com/2017/04/24/data-science-for-operational-excellence-part-3-exercises/?utm_source=rss&utm_medium=rss&utm_campaign=data-science-for-operational-excellence-part-3-exercises"> R-exercises</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a target="_blank" rel="nofollow" href="https://i1.wp.com/www.r-exercises.com/wp-content/uploads/2017/04/code-1839406__340.jpg"><img sizes="(max-width: 150px) 100vw, 150px" alt="" class="wp-image-4872" src="https://i1.wp.com/www.r-exercises.com/wp-content/uploads/2017/04/code-1839406__340-150x150.jpg?resize=150%2C150" data-recalc-dims="1"></a><br>
Optimized transportation planning is a task usually left to the firm’s logistic department. However, it is often difficult to visualize, specially if there are many points involved in the logistic network. R and its packages can help solving this issue. Our goal here is to expand logistics networking visualization. In order to do that, we will use packages as ggmap and leaflet.</p>
<p>Answers to the exercises are available <a target="_blank" rel="nofollow" href="http://www.r-exercises.com/2017/04/24/data-science-for-operational-excellence-part-3-solutions/">here</a>.</p>
<p><strong>Exercise 1</strong><br>
Load libraries: ggmap, fields, lpSolve, leaflet, dplyr, magrittr. Use the following vectors to create a new one called <code>allCitiesAux</code>: <code>soyaCities &lt;- c(&quot;Sapezal&quot;,&quot;Sorriso&quot;, &quot;Nova Mutum&quot;, &quot;Diamantino&quot;, &quot;Cascavel&quot;) , transhipment &lt;- c(&quot;Alto Araguaia&quot;, &quot;Cascavel&quot;), ports &lt;- c(&quot;Santos&quot;, &quot;Paranagua&quot;)</code>.<br>
<strong>Exercise 2</strong><br>
Use the function <code>geocode</code> to collect latitude and longitude for all cities.<br>
<strong>Exercise 3</strong><br>
Create a data frame and with columns names: City, lat and lng.<br>
<strong>Exercise 4</strong><br>
Create a matrix that contains all the distance between all cities. We will use this in the <code>lp.transportation</code> function, so remember that rows must be offer points and columns demand points.</p>
<div>
<aside><img src="http://www.r-exercises.com/2017/04/24/data-science-for-operational-excellence-part-3-exercises/?utm_source=rss&utm_medium=rss&utm_campaign=data-science-for-operational-excellence-part-3-exercises"></aside>
<div><strong>Learn more</strong> about geo visualization in the online course <a target="_blank" rel="nofollow" href="http://www.r-exercises.com/product/r-complete-data-visualization-solutions/">R: Complete Data Visualization Solutions</a>. In this course you will learn how to:
<ul>
<li>Build advanced map visualizations</li>
<li>Work with different sources for maps</li>
<li>And much more visualizations</li>
</ul>
</div>
</div>
<p><strong>Exercise 5</strong><br>
Create <code>row.signs, row.rhs, col.signs, col.rhs</code>. For that, remember to set a seed equals to 123 and that all soya must be exported through ports. For the “right hand side” variables use random generated number. Port demands should be between 300 and 600. Soya production should be between 50 and 300.<br>
<strong>Exercise 6</strong><br>
Solve the transportation problem and change columns and row names to match the names from the cost matrix.<br>
<strong>Exercise 7</strong><br>
Create a list of data frames to store all segments presented in the solution. Example, one of this segments should be Sapezal to Santos.<br>
<strong>Exercise 8</strong><br>
Create a map using leaflet and add lines for each segment based on the list of data frames created previously.<br>
<strong>Exercise 9</strong><br>
Create a list of data frames to store road routes extracted using the <code>route</code> function from ggmap.<br>
<strong>Exercise 10</strong><br>
Create a new map using leaflet that, instead of showing straight lines from origin to destination, shows road routes.</p>
<div>
<h3>Related exercise sets:</h3>
<ol>
<li><a title="Descriptive Analytics-Part 5: Data Visualisation (Spatial data)" target="_blank" rel="nofollow" href="http://www.r-exercises.com/2016/12/26/descriptive-analytics-part-5-data-visualisation-spatial/">Descriptive Analytics-Part 5: Data Visualisation (Spatial data) </a></li>
<li><a title="Bind exercises" target="_blank" rel="nofollow" href="http://www.r-exercises.com/2016/02/22/bind-exercises/">Bind exercises </a></li>
<li><a title="Spatial analysis with ggmap Exercises (part-1)" target="_blank" rel="nofollow" href="http://www.r-exercises.com/2017/03/09/spatial-analysis-with-ggmap-exercises-part-1/">Spatial analysis with ggmap Exercises (part-1) </a></li>
<li><a target="_blank" rel="nofollow" href="http://www.r-exercises.com/start-here-to-learn-r/">Explore all our (>1000) R exercises</a></li>
<li><a target="_blank" rel="nofollow" href="http://www.r-exercises.com/r-courses/">Find an R course using our R Course Finder</a> directory</li>
</ol>
</div>
<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://www.r-exercises.com/2017/04/24/data-science-for-operational-excellence-part-3-exercises/?utm_source=rss&utm_medium=rss&utm_campaign=data-science-for-operational-excellence-part-3-exercises"> R-exercises</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/DOCPYb8PDcw"></a></div>