spdep (version 1.1-3)

plot.nb: Plot a neighbours list

Description

A function to plot a neighbours list given point coordinates to represent the region in two dimensions; plot.listw is a wrapper that passes its neighbours component to plot.nb.

Usage

# S3 method for nb
plot(x, coords, col="black", points=TRUE, add=FALSE, arrows=FALSE,
 length=0.1, xlim=NULL, ylim=NULL, ...)
# S3 method for listw
plot(x, coords, col="black", points=TRUE, add=FALSE, arrows=FALSE,
 length=0.1, xlim=NULL, ylim=NULL, ...)

Arguments

x

an object of class nb or (for plot.listw) class listw

coords

matrix of region point coordinates, or an sfc points object

col

plotting colour

points

(logical) add points to plot

add

(logical) add to existing plot

arrows

(logical) draw arrowheads for asymmetric neighbours

length

length in plot inches of arrow heads drawn for asymmetric neighbours lists

xlim, ylim

plot window bounds

...

further graphical parameters as in par(..)

See Also

summary.nb

Examples

Run this code
# NOT RUN {
columbus <- st_read(system.file("shapes/columbus.shp", package="spData")[1], quiet=TRUE)
col.gal.nb <- read.gal(system.file("weights/columbus.gal", package="spData")[1])
coords <- st_centroid(st_geometry(columbus), of_largest_polygon=TRUE)
plot(col.gal.nb, coords)
title(main="GAL order 1 links with first nearest neighbours in red", cex.main=0.6)
col.knn <- knearneigh(coords, k=1)
plot(knn2nb(col.knn), coords, add=TRUE, col="red", length=0.08)
# }

Run the code above in your browser using DataCamp Workspace