1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
% Copyright 2001-5 by Roger S. Bivand
\name{plot.nb}
\alias{plot.nb}
\alias{plot.listw}
\title{Plot a neighbours list}
\description{
A function to plot a neighbours list given point coordinates to represent the region in two dimensions; \code{plot.listw} is a wrapper that passes its neighbours component to \code{plot.nb}.
}
\usage{
\method{plot}{nb}(x, coords, col="black", points=TRUE, add=FALSE, arrows=FALSE,
length=0.1, xlim=NULL, ylim=NULL, ...)
\method{plot}{listw}(x, coords, col="black", points=TRUE, add=FALSE, arrows=FALSE,
length=0.1, xlim=NULL, ylim=NULL, ...)
}
\arguments{
\item{x}{an object of class \code{nb} or (for \code{plot.listw}) class \code{listw}}
\item{coords}{matrix of region point coordinates, a \code{Spatial} object (points or polygons), or an \code{sfc} object (points or polygons)}
\item{col}{plotting colour}
\item{points}{(logical) add points to plot}
\item{add}{(logical) add to existing plot}
\item{arrows}{(logical) draw arrowheads for asymmetric neighbours}
\item{length}{length in plot inches of arrow heads drawn for asymmetric
neighbours lists}
\item{xlim, ylim}{plot window bounds}
\item{...}{further graphical parameters as in \code{par(..)}}
}
\author{Roger Bivand \email{Roger.Bivand@nhh.no}}
\seealso{\code{\link{summary.nb}}}
\examples{
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])
plot(col.gal.nb, st_geometry(columbus))
title(main="GAL order 1 links with first nearest neighbours in red", cex.main=0.6)
plot(col.gal.nb, as(columbus, "Spatial"))
title(main="GAL order 1 links with first nearest neighbours in red", cex.main=0.6)
coords <- st_centroid(st_geometry(columbus), of_largest_polygon=TRUE)
col.knn <- knearneigh(coords, k=1)
plot(knn2nb(col.knn), coords, add=TRUE, col="red", length=0.08)
}
\keyword{spatial}
|