Hi folks, After using spdep to construct a neighbor list from a SpatialPolygons object, I plotted the neighbor list and noted that I needed one more link that wasn't caught by the poly2nb command. I found the edit.nb() function and can successfully use the interactive graphical interface to add the link, but would like to know if there is an alternative method for adding a link between two regions. What would I need to do to directly edit the neighbor list object to include an additional link between regions 23 and 31?
> # Create a SpatialPolygons object from a SpatialPolygonsDataFrame object, this > # helps set up for creating a neighbor list via commands from spdep package > > CITY.polys <- as.SpatialPolygons.PolygonsList([EMAIL PROTECTED], + proj4string=CRS(projection.details)) > > # Create a neighbor list based on shared boundary. We need this to facilitate > # creating a weights matrix when we go to do spatial regression models. > > CITY.nb <- poly2nb(CITY.polys, row.names = NULL, snap=sqrt(.Machine$double.eps), queen=TRUE) > > # Capture coordinates of ZCTA centroids into a matrix we can use in plotting > # the neighbor list. > > coords.mat <- cbind(CITY.ZCTA.data$centroid.x, CITY.ZCTA.data$centroid.y) > > # Plot the neighbor list (reveals we need to add 1 more link) > > plot(CITY.ZCTA.data, col="grey", border="black", axes=FALSE, asp=1, yaxs="i") > title(main="Neighbor List Links", adj= 0, cex.sub=.75) > plot(CITY.nb, coords.mat, add=TRUE, col="black", lwd=2) > > # Add 1 link to neighbor list. This requires interaction with the graphics > # on screen. > > CITY.nb <- edit.nb(CITY.nb, coords.mat, polys=CITY.polys) Identifying contiguity for deletion ... No contiguity between chosen points Add contiguity? (y/n) y added contiguity between point 23 and 31 Options: quit[q] refresh[r] continue[c] q > > # Plot the revised neighbor list (now everything looks right) > > plot(CITY.ZCTA.data, col="grey", border="black", axes=FALSE, asp=1, yaxs="i") > title(main="Neighbor List Links", adj= 0, cex.sub=.75) > plot(CITY.nb, coords.mat, add=TRUE, col="black", lwd=2) Steven J. Pierce E-mail: [EMAIL PROTECTED] _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo