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 SpatialPolygonsDataFrame or sf.

ID.area

character vector of geographic identifiers.

nb

optional argument with the neighbours list of class nb. If NULL (default), this object is computed from the carto argument.

plot

logical value (default FALSE), if TRUE then the computed neighbourhood graph is ploted.

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:

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.3 Index]