[R-sig-Geo] plotting only one shape from shapefile
Roger Bivand
Roger.Bivand at nhh.no
Mon Jan 22 09:10:43 CET 2007
On Mon, 22 Jan 2007, Gasper Cankar wrote:
> Hello!
>
> I know this must be a very simple thing to do yet after one week of
> trying and going through the archives I don't find the answer. I'm
> either looking at the wrong places or I'm cursed;)
Using sp classes gives this kind of control, see example below.
>
> I imported our country's shapefile with 12 regions and I can draw the
> shape, but I'd like to extract (and draw) only one region from whole
> shape.
>
>
> #This is original shapefile:
> slo <- read.shape(file="d://D_E_L_O/slika_slo/slo.shp")
> Shapefile type: Polygon, (5), # of Shapes: 12
>
> # and plotting (simplified)
> slomap <- Map2poly(slo)
> plot(slomap)
>
> How do I plot only one of the shapes? How do I extract it as separate object?
>
library(maptools)
xx <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1],
IDvar="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))
names(xx)
xxx <- xx[xx$NAME == "Dare",]
opar <- par(mfrow=c(2,1), mar=c(0,0,0,0))
plot(xx, col=c(2,3)[as.integer(xx$NAME == "Dare")+1])
plot(xxx, col=3)
par(opar)
That is, SpatialPolygonDataFrame objects have a "[" method to be used for
subsetting, and readShapePoly() creates a SpatialPolygonDataFrame object -
like readOGR() in rgdal.
Roger
> Thank everyone in advance for any help.
>
> Ga¹per
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list