spatial_node_types | R Documentation |
These functions are a collection of node type queries that are commonly
used in spatial network analysis, and form a spatial extension to
node type queries
in tidygraph.
node_is_pseudo()
node_is_dangling()
Just as with all query functions in tidygraph, these functions
are meant to be called inside tidygraph verbs such as
mutate
or filter
, where
the network that is currently being worked on is known and thus not needed
as an argument to the function. If you want to use an algorithm outside of
the tidygraph framework you can use with_graph
to
set the context temporarily while the algorithm is being evaluated.
A logical vector of the same length as the number of nodes in the network, indicating if each node is of the type in question.
node_is_pseudo()
: Pseudo nodes in directed networks are those
nodes with only one incoming and one outgoing edge. In undirected networks
pseudo nodes are those nodes with only two incident edges, i.e. nodes of
degree 2.
node_is_dangling()
: Dangling nodes are nodes with only one
incident edge, i.e. nodes of degree 1.
library(sf, quietly = TRUE)
library(tidygraph, quietly = TRUE)
# Create a network.
net = as_sfnetwork(mozart, "mst", directed = FALSE)
# Use query function in a filter call.
pseudos = net |>
activate(nodes) |>
filter(node_is_pseudo())
danglers = net |>
activate(nodes) |>
filter(node_is_dangling())
oldpar = par(no.readonly = TRUE)
par(mar = c(1,1,1,1), mfrow = c(1,2))
plot(net, main = "Pseudo nodes")
plot(st_geometry(pseudos), pch = 20, cex = 1.2, col = "orange", add = TRUE)
plot(net, main = "Dangling nodes")
plot(st_geometry(danglers), pch = 20, cex = 1.2, col = "orange", add = TRUE)
par(oldpar)
# Use query function in a mutate call.
net |>
activate(nodes) |>
mutate(pseudo = node_is_pseudo(), dangling = node_is_dangling())
# Use query function directly.
danglers = with_graph(net, node_is_dangling())
head(danglers)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.