connect_subgraphs {bigDM}  R Documentation 
Merge disjoint connected subgraphs
Description
The function returns a neighbour list of class nb
and its associated spatial adjacency matrix
computed by merging disjoint connected subgraphs through its nearest polygon centroids.
Usage
connect_subgraphs(carto, ID.area = NULL, nb = NULL, plot = FALSE)
Arguments
carto 
object of class 
ID.area 
character vector of geographic identifiers. 
nb 
optional argument with the neighbours list of class 
plot 
logical value (default 
Details
This function first calls the add_neighbour
function to search for isolated areas.
Value
This function returns a list with the following two elements:

nb
: the modified neighbours list 
W
: associated spatial adjacency matrix of classCsparseMatrix
Examples
library(spdep)
## Load the Spain colorectal cancer mortality data ##
data(Carto_SpainMUN)
## Select the polygons (municipalities) of the 'Comunidad Valenciana' region ##
carto < Carto_SpainMUN[Carto_SpainMUN$region=="Comunidad Valenciana",]
carto.nb < poly2nb(carto)
n.comp.nb(carto.nb)$nc # 2 disjoint connected subgraphs
## Plot the spatial polygons and its neighbourhood graph
op < par(mfrow=c(1,2), pty="s")
plot(carto$geometry, main="Original neighbourhood graph")
plot(carto.nb, st_centroid(st_geometry(carto), of_largest_polygon=TRUE),
pch=19, cex=0.5, col="red", add=TRUE)
## Use the 'connect_subgraphs' function ##
carto.mod < connect_subgraphs(carto=carto, ID.area="ID", nb=carto.nb, plot=TRUE)
title(main="Modified neighbourhood graph")
n.comp.nb(carto.mod$nb)$nc==1
par(op)
[Package bigDM version 0.5.4 Index]