ESRI shape files can easily be imported into R by using the function readOGR()
from the rgdal
package.
library(rgdal)
shp <- readORG(dsn = "/path/to/your/file", layer = "filename")
It is important to know, that the dsn
must not end with /
and the layer
does not allow the file ending (e.g. .shp
)
Another possible way of importing shapefiles is via the raster
library and the shapefile
function:
library(raster)
shp <- shapefile("path/to/your/file.shp")
Note how the path definition is different from the rgdal import statement.
tmap
package provides a nice wrapper for the rgdal::readORG
function.
library(tmap)
sph <- read_shape("path/to/your/file.shp")