Welcome to Spatial Data in R! This first set of tutorials (in three parts) is designed to provide an introduction to the two types of spatial data you will encounter in R: vector data and raster data. By the end of this tutorial, you should have a good sense of how R thinks about spatial data, and how to import and export spatial datasets you may get from other programs or sources.

1. Updating R and Getting RStudio

2. Library installation

Next, we need to install some libraries. In this tutorial, we will work with three libraries:

On Windows:

Just run: install.packages(c("sp", "raster", "rgdal"))

On Mac:

  1. Download GDAL complete

  2. Doubleclick and install the .dmg file as you are used to on a Mac

  3. Make sure you have R Version 3.2.3 installed – if not update it.

  4. Download the rgdal package from CRAN.

  5. Place the downloaded rgdal_1.0-4.tgz in your Desktop folder

  6. Run install.packages("~/Desktop/rgdal1.0-4.tgz", repos=NULL)

  7. Install raster and sp by running: install.packages(c("sp","raster"))

3. Checking your installation

If everything went well, the following three commands should run without problem!

library (sp)
library (rgdal)
library (raster)

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.