ggnetmap {netmap} | R Documentation |
Fortify a network over a map
Description
Link a network
or igraph
and a sf
object in a
data.frame
for subsequent representation on a plot using ggplot2
.
Usage
ggnetmap(
n,
m,
lkp = NULL,
m_name = NULL,
n_name = "vertex.names",
scale = FALSE,
...
)
Arguments
n |
A |
m |
A |
lkp |
An optional lookup table. |
m_name |
Optional |
n_name |
Optional |
scale |
Whether coordinates should be scaled (defaults to FALSE since the
network should be overlayed with the non-scaled |
... |
Additional parameters passed to |
Details
Using a network
or igraph
and a sf
object as inputs,
with an optional lookup table (a data.frame
) in case the IDs don't
match, produces a data.frame
that can be used with ggnetwork
's
geom_edges
and geom_nodes
functions to represent the network as overlayed on a sf
object in a
ggplot2
graph. Only vertices with a corresponding feature in the
sf
object are included.
Value
A data frame, produced by fortify
, which can be
used as data source in ggplot2
graphs.
Examples
net=network::network(matrix(c(0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0), nrow=4, byrow=TRUE))
network::set.vertex.attribute(net, "name", value=c("a", "b", "c", "d"))
wkb = structure(list("01010000204071000000000000801A064100000000AC5C1641",
"01010000204071000000000000801A084100000000AC5C1441",
"01010000204071000000000000801A044100000000AC5C1241",
"01010000204071000000000000801A024100000000AC5C1841"), class = "WKB")
map=sf::st_sf(id=c("a1", "b2", "c3", "d4"), sf::st_as_sfc(wkb, EWKB=TRUE))
lkptbl=data.frame(id=c("a1", "b2", "c3", "d4"), name=c("a", "b", "c", "d"))
ggnetmap(net, map, lkptbl, "id", "name")