Pages Menu
Categories Menu

Posted by on Dec 9, 2013 in R Spatial, Resources, Spatial Analysis | 16 comments

Introduction to Spatial Data and ggplot2


For those starting out with spatial data in R, Robin Lovelace and I have prepared this tutorial (funded as part of the University of Leeds and UCL Talisman project). Here we introduce a range of analysis skills before demonstrating how you can deploy the powerful graphics capabilities of ggplot2 to visualise your results. There is also some “bonus” material at the end to show how you can use ggplot2 for descriptive statistics and so on. The tutorial covers:

-Introduction to ggplot2

-Map projections

-Adding Google and Stamen basemaps

-Clipping and joining spatial data

-Aggregating spatial data

-ggplot2 for descriptive statistics

Download the data you need from here.

This is a work in progress so we may add improvements as time goes on. We also have a few more tutorials in the pipeline that will be posted here in due course.


Share on Facebook
Bookmark this on Google Bookmarks
Share on reddit
Bookmark this on Digg
Share on StumbleUpon
Share on LinkedIn


  1. This is fantastic! I will be doing this over our semester break here at the University of Rochester.

    Thank you for this!

  2. Is there more here than just an introduction? The text seems to imply there is much more content, but all I can see is an introduction.

  3. Great tutorial! I am a fisheries student at the University of Alaska Fairbanks. I found this material highly relevant to my research.

    • Ditto from a fellow UAF alum (econ)! Great stuff.

  4. Thanks a lot! I’m an ecology student in New Zealand and I found this tutorial very useful.

  5. Hi there,
    neat tutorial, but I had many issues getting it to knit (as opposed to getting the code to run, which worked great). Was the .Rmd written to be capable of knitting on other machines?

  6. I would really like to run the tutorial, but it seems that the rgdal package is not yet available for the latest OS X? I am using OSX 10.9.4 and RStudio 0.98.1049.
    Any suggestions and help?

    • I’m having the same problem. I tried to track it down, but the issue is beyond my R skills currently. It seems that it might be possible to get the package in source mode, just not binary mode but I haven’t done anything like that yet.

    • If you are willing to use homebrew – – you can do a brew install rgdal to get the gdal library (this is my recommended/preferred route). You can also grab the binary OS X frameworks from here – Then, you should be able to do a source install of the rgdal package (install.packages("rgdal", type="source"). Hit me up on twitter – @hrbrmstr if you continue to have issues.

  7. james please mail me r code for excel file. shape file is not opening.please

  8. Very helpful tutorial. Thanks.
    I would like to go further and do some interpolations with point data using geostatistical methods.
    Some good hints would be very welcome.

  9. Has anyone else had trouble with fortify()? I cannot install gpclib, only rgeos. When I run fortify() R cannot find the function.

    Desperate to fix it and keep going as am getting alot out of the tutorial.

    Thank you!

  10. Hi, thanks a lot for this tutorial. It has helped me a lot in what I’m trying to do.
    Something is weird though, because I get the following error message when trying to plot the first London Sports Participation map: “Error in xyz %*% solve(M) : requires numeric/complex matrix/vector arguments”
    I tried looking up the error but don’t get anywhere really. Any explanation is very much appreciated!

    Thanks a lot!

  11. スーパーコピー 財布真心込めて最高 レベルのスーパーコピールイヴィトン偽物ブランド品をお届けしています。安全税関対策+ 素早い配送+随時の在庫補給+丁寧な対応+スーパーコピー販売業界最低価格に挑戦 !当店は業界最高品質に挑戦!全商品はプロの目にも分からないルイヴィトン 財布スーパーコピーです。

  12. 私にとっては、2015年年間カレンダーiwcの腕時計の最も印象的な要素の運動である。オメガスーパーコピー後に大44.2mmワイドケースと、広大なサファイアクリスタル窓を通して、あなたは近代的な機械の腕時計運動の自社製キャリバー52850 iwcの素晴らしい例であることを見ます。iwcの米国の運動のアーキテクチャの範囲内で種々の谷と山の深い見方を与えることは素晴らしい仕事をしました。と運動を取り上げた事例の多くは、大きなプラスである。


  1. Monthly Maps: November & December 2013 « geohackers - […] James Cheshire and Robin Lovelace have posted a fantastic (but demanding) tutorial on working with spatial data with ggplot2 …
  2. Coxcomb Plots and Spiecharts in R | - […] on how to create them in R, I think it’s well worth a look. He and I also recently …
  3. Maps with ggplot2: Getting Started ← sy.tpp - […] computing – to explore my new hometown London. James Cheshire and Robin Lovelace published a useful tutorial for mapping spatial …
  4. linear regression models: exploring possibilities | psybercity - […] […]
  5. First Post and Starting out with Spatial Statistics | yatescm - […] hand at spatial statistics before, but luckily for me, one of the authors of the book has written a …
  6. Mapping in R | So That's How You Do It - […] to grips with drawing maps showing data in R. There is a good tutorial here and extra information here and …
  7. Manhattan Rental Rates | Plotting Rental and Spatial Data | Recommended Texts - […] came across this post written by a James Cheshire that introduces people to the topic of spatial data using …

Post a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>