Skip to content

Plotting shapefiles in R

5 messages · Ester Polaina Lacambra, celso at stephan.mus.br, Roger Bivand +2 more

#
Try this:

## read polygon SHP
library(shapefiles)
poli<-read.shapefile("your shp file name")
poli<-convert.to.simple(poli$shp)
poli<-poli[,-1]
plot(poli)
#
On Wed, 11 Jan 2012, celso at stephan.mus.br wrote:

            
Please note that the shapefiles package has not been revised since 2006, 
and does not use sp classes, so you are completely stuck with the import 
data representation of that package. See the "Spatial" task view on CRAN 
for better supported alternatives.

Roger

  
    
#
Roger didn't say it (but he wrote the book on it), but an alternative
would be something like:
library(sp)
library(rgdall)
poli<-readOGR("directory","shapefilename without .shp")
class(poli) # SpatialPolygonsDataFrame
proj4string(poli) # projection information
spplot(poli)

One advantage is that by using sp classes, this approach allows you to
reproject via spTransform(), colorize polygons by values of an
attribute in the dataframe in spplot(), and actually do more things
with the spatial data.

Tom 2
1 day later
#
Dear Ester,

  This is a simple, yet effective, approach:
 
  library(maptools)
  myshp<-readShapePoly("path_to_your_shapefile")
  plot(myshp)

  Hope it helps,

  Thiago.
--- On Wed, 11/1/12, Ester Polaina Lacambra <e.polaina at gmail.com> wrote: