if (requireNamespace("sf", quietly = TRUE)) {
if (requireNamespace("spdep", quietly = TRUE)) {
library(spdep)
nc.sids <- sf::st_read(system.file("shapes/sids.gpkg", package="spData")[1])
row.names(nc.sids) <- as.character(nc.sids$FIPS)
rn <- row.names(nc.sids)
ncCC89_nb <- read.gal(system.file("weights/ncCC89.gal", package="spData")[1],
region.id=rn)
ncCR85_nb <- read.gal(system.file("weights/ncCR85.gal", package="spData")[1],
region.id=rn)
plot(sf::st_geometry(nc.sids), border="grey")
plot(ncCR85_nb, sf::st_geometry(nc.sids), add=TRUE, col="blue")
plot(sf::st_geometry(nc.sids), border="grey")
plot(ncCC89_nb, sf::st_geometry(nc.sids), add=TRUE, col="blue")
}
}
Run the code above in your browser using DataLab