Pages Menu
Categories Menu

Posted by on Dec 9, 2013 in R Spatial, Resources, Spatial Analysis | 12 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.


[iframe src=”” width=”100%” height=”1500″]


  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.


  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…

Post a Reply

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