Description Usage Arguments Value Examples
View source: R/polygonNeighbors.R
Find the neighboring regions of each region in a shapefile. Outputs a dataframe with each region and optionally a matrix and plot of adjacencies.
1 | polygonNeighbors(shp, id = NULL, nb.matrix = FALSE, plot = FALSE)
|
shp |
A |
id |
The name of the variable in |
nb.matrix |
Whether to output the adjacency matrix as well. |
plot |
Whether to plot the adjacencies (for checking). |
Returns a list
with a data.frame
of each adjacency and
optionally the adjacency matrix and/or a plot of the adjacencies.
1 2 3 4 5 6 7 8 | # Get a shapefile of US States:
file <- "http://www2.census.gov/geo/tiger/GENZ2015/shp/cb_2015_us_state_20m.zip"
download.file(file, "states.zip")
unzip("states.zip")
shp <- rgdal::readOGR(".", "cb_2015_us_state_20m")
shp <- shp[!(shp@data$STATEFP %in% c("02", "15", "72")),] # Contiguous US
shp <- sp::spTransform(shp, sp::CRS("+init=epsg:26978"))
state.adj <- polygonNeighbors(shp, id = "NAME", nb.matrix = TRUE, plot = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.