<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/spatial-analysis-with-ggmap-exercises-part-1/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://r-exercises.com/2017/03/09/spatial-analysis-with-ggmap-exercises-part-1/?utm_source=rss&utm_medium=rss&utm_campaign=spatial-analysis-with-ggmap-exercises-part-1"> 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="http://r-exercises.com/wp-content/uploads/2017/03/unnamed-chunk-1-5.png?x61433"><img sizes="(max-width: 150px) 100vw, 150px" alt="" class="wp-image-4703" src="https://i2.wp.com/r-exercises.com/wp-content/uploads/2017/03/unnamed-chunk-1-5-150x150.png?resize=150%2C150" data-recalc-dims="1"></a>R has many powerful libraries to handle spatial data, and the things that R can do with maps can only grow. This exercise tries to demonstrate a few basic functionalities of the <code>ggmap</code> package in R while dealing with raster images. </p>
<p>The <code>ggmap</code> package can be used to access maps from the Google Maps API and other APIs as raster layers and perform various raster operations on it. Moreover, many other features such as points, polygons, lines etc. can be added to the basemap using layered grammar of graphics on the lines of the <code>ggplot2</code> package. In addition, the package provides Geocoding facilities using the popular Google API.</p>
<p>Answers to the exercises are available <a target="_blank" rel="nofollow" href="http://r-exercises.com/2017/03/09/spatial-analysis-with-ggmap-solutions-part-1/">here</a>.If you obtained a different (correct) answer than those listed on the solutions page, please feel free to post your answer as a comment on that page.</p>
<p>Please install and load the package <code> ggmap </code> before starting the exercises.</p>
<p><strong>Exercise 1</strong><br>
Get a basemap for United Kingdom from Google Maps API and plot the map. Keep the zoom level in such a way that entire UK is visible in the map.</p>
<p><strong>Exercise 2</strong><br>
Repeat Exercise 1 to get a Stamen map for United Kingdom. Keep the <code>maptype</code> as <code>toner</code>.</p>
<p><strong>Exercise 3</strong><br>
Consider the following football clubs currently playing in the English Premier League,<br>
Arsenal FC, Manchester City FC, Manchester United FC, Liverpool FC, Chelsea FC and Tottenham Hotspur FC. Please locate these clubs on the basemap obtained in Exercise 1 as red points.</p>
<p><strong>Exercise 4</strong><br>
Consider the geolocation <code>(-0.119543, 51.50332)</code>. Find out an address on the map that corresponds to this location..</p>
<p><strong>Exercise 5</strong><br>
Get a basemap for London from Google Maps API and plot it. Choose an appropriate Zoom Level.</p>
<p><strong>Exercise 6</strong><br>
Consider the following London based Football clubs: Arsenal FC, Tottenham Hotspur FC,<br>
Chelsea FC, West Ham FC and Crystal Palace FC. Like in Exercise 4, plot these clubs on the London map generated in Exercise 5. Use different colors and shape for each club.</p>
<p><strong>Exercise 7</strong><br>
Calculate the distance(while driving) from Emirates Stadium, London to Wembley, London in terms of kilometers and time taken (minutes).</p>
<p><strong>Exercise 8</strong><br>
Calculate the maximum zoom level which can be used to fetch a basemap such that both Emirates Stadium and Wembley are included in the map.</p>
<p><strong>Exercise 9</strong><br>
Get a basemap around Wembley at a zoom level 12 from Google Maps API. Keep the <code>maptype </code> as <code>roadmap</code>.</p>
<p><strong>Exercise 10</strong><br>
Draw the driving route from Emirates Stadium, London to Wembley, London on the<br>
basemap obtained in Example 9. Keep the color of the route as red.</p>
<div>
<h3>Related exercise sets:</h3>
<ol>
<li><a title="Working with Shapefiles in R Exercises" target="_blank" rel="nofollow" href="http://r-exercises.com/2017/01/03/working-with-shapefiles-in-r-exercises/">Working with Shapefiles in R Exercises </a></li>
<li><a title="Descriptive Analytics-Part 5: Data Visualisation (Spatial data)" target="_blank" rel="nofollow" href="http://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="Lattice exercises – part 2" target="_blank" rel="nofollow" href="http://r-exercises.com/2016/05/24/lattice-exercises-part-2/">Lattice exercises – part 2 </a></li>
<li><a target="_blank" rel="nofollow" href="http://r-exercises.com/start-here-to-learn-r/">Explore all our (>1000) R exercises</a></li>
<li><a target="_blank" rel="nofollow" href="http://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://r-exercises.com/2017/03/09/spatial-analysis-with-ggmap-exercises-part-1/?utm_source=rss&utm_medium=rss&utm_campaign=spatial-analysis-with-ggmap-exercises-part-1"> 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/cz_M4rdIHgM"></a></div>