[R-sig-Geo] How to check a large neighbourhood matrix?

Roger Bivand Roger.Bivand at nhh.no
Thu Mar 27 20:37:53 CET 2008


On Thu, 27 Mar 2008, Danlin Yu wrote:

> Oscar:
>
> If you produced the nb list in R, you can always summarize the nb list
> to see whether there are units that don't have neighbors.
>
> For instance:
> #loading spdep
> library(spdep)
>
> #you have read a shapefile of postal code areas:
>
> post<-read.shape("../yourshapefile.shp")
>
> #since it is a polygon shapefile, a Map2poly and poly2nb function shall
> do the trick (Roger will have better ideas than my naive ones)
>
> post.nb<-poly2nb(Map2poly(post))

I think that Oscar had got this far using the prefered sp object:

SPDF <- readShapePoly()

nb <- poly2nb(SPDF)

but had needed to use the snap= argument to poly2nb() to overcome slivers 
in his polygons.

>
> #then you summarize the nb list:
>
> summary(post.nb)
>

This helps, because it says which have no neighbours. It will indicate how 
to "zoom" in on the plot for the locations of the polygons. To actually 
"zoom", use xlim= and ylim= in the plot method for nb objects.

If you want real control, consider writeOGR(SPDF, ..., driver="KML") in 
the rgdal package, and equivalently writeOGR() of the 
SpatialLinesDataFrame output by nb2lines(), and zoom to your satisfaction 
in GE using KML files.

Roger

> The summary command will give you the characteristics of the neighbor
> list object, including Number of regions, Number of nonzero links,
> Percentage nonzero weights, Average number of links, regions that have
> no links (which shall give you the idea whether or not some postal code
> areas are connected) and the most and least connected regions
>
> Hope this helps.
>
> Regards,
> Dr. Danlin Yu
>
> Oscar Breugelmans wrote:
>> Dear all,
>>
>> I am working on a neighbourhood matrix of the postal code areas in the
>> Netherlands. Reading the shapefile and producing the matrix is no problem
>> (after some help from Roger), but I am not completely confident that all
>> neighbours are recognized because there are a few polygon boundaries that
>> are topologically unclean. I have checked the shapefile as closely as
>> possible, but with 4000 postal code areas this is a hell of a job.
>> Plotting the matrix in R (using plot.nb) is also not an option because with
>> so many areas the individual connections are no longer visible. Thus, I
>> would like to zoom in on parts of the graph to check whether all neighbours
>> are defined correctly. I searched the web for methods to zoom in and out of
>> a graph in R, but couldn't find anything.
>> Does anyone know if there are ways to do this?
>>
>> Oscar
>> ____________________________________________________________________________
>>
>> DISCLAIMER:  http://www.rivm.nl/disclaimer.htm\ ...{{dropped:2}}
>>
>> _______________________________________________
>> 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