These functions find the vertices not farther than a given limit from
another fixed vertex, these are called the neighborhood of the vertex.
Note that ego()
and neighborhood()
,
ego_size()
and neighborhood_size()
,
make_ego_graph()
and make_neighborhood()_graph()
,
are synonyms (aliases).
Usage
connect(graph, order, mode = c("all", "out", "in", "total"))
ego_size(
graph,
order = 1,
nodes = V(graph),
mode = c("all", "out", "in"),
mindist = 0
)
neighborhood_size(
graph,
order = 1,
nodes = V(graph),
mode = c("all", "out", "in"),
mindist = 0
)
ego(
graph,
order = 1,
nodes = V(graph),
mode = c("all", "out", "in"),
mindist = 0
)
neighborhood(
graph,
order = 1,
nodes = V(graph),
mode = c("all", "out", "in"),
mindist = 0
)
make_ego_graph(
graph,
order = 1,
nodes = V(graph),
mode = c("all", "out", "in"),
mindist = 0
)
make_neighborhood_graph(
graph,
order = 1,
nodes = V(graph),
mode = c("all", "out", "in"),
mindist = 0
)
Arguments
- graph
The input graph.
- order
Integer giving the order of the neighborhood.
- mode
Character constant, it specifies how to use the direction of the edges if a directed graph is analyzed. For ‘out’ only the outgoing edges are followed, so all vertices reachable from the source vertex in at most
order
steps are counted. For ‘"in"’ all vertices from which the source vertex is reachable in at mostorder
steps are counted. ‘"all"’ ignores the direction of the edges. This argument is ignored for undirected graphs.- nodes
The vertices for which the calculation is performed.
- mindist
The minimum distance to include the vertex in the result.
Value
ego_size()
/neighborhood_size()
returns with an integer vector.ego()
/neighborhood()
(synonyms) returns A list ofigraph.vs
or a list of numeric vectors depending on the value ofigraph_opt("return.vs.es")
, see details for performance characteristics.make_ego_graph()
/make_neighborhood_graph()
returns with a list of graphs.connect()
returns with a new graph object.
Details
The neighborhood of a given order r
of a vertex v
includes all
vertices which are closer to v
than the order. I.e. order 0 is always
v
itself, order 1 is v
plus its immediate neighbors, order 2
is order 1 plus the immediate neighbors of the vertices in order 1, etc.
ego_size()
/neighborhood_size()
(synonyms) returns the size of the neighborhoods of the given order,
for each given vertex.
ego()
/neighborhood()
(synonyms) returns the vertices belonging to the neighborhoods of the given
order, for each given vertex.
make_ego_graph()
/make_neighborhood()_graph()
(synonyms) is creates (sub)graphs from all neighborhoods of
the given vertices with the given order parameter. This function preserves
the vertex, edge and graph attributes.
connect()
creates a new graph by connecting each vertex to
all other vertices in its neighborhood.
See also
Other functions for manipulating graph structure:
+.igraph()
,
add_edges()
,
add_vertices()
,
complementer()
,
compose()
,
contract()
,
delete_edges()
,
delete_vertices()
,
difference()
,
difference.igraph()
,
disjoint_union()
,
edge()
,
igraph-minus
,
intersection()
,
intersection.igraph()
,
path()
,
permute()
,
rep.igraph()
,
reverse_edges()
,
simplify()
,
union()
,
union.igraph()
,
vertex()
Other structural.properties:
bfs()
,
component_distribution()
,
constraint()
,
coreness()
,
degree()
,
dfs()
,
distance_table()
,
edge_density()
,
feedback_arc_set()
,
girth()
,
is_acyclic()
,
is_dag()
,
is_matching()
,
k_shortest_paths()
,
knn()
,
reciprocity()
,
subcomponent()
,
subgraph()
,
topo_sort()
,
transitivity()
,
unfold_tree()
,
which_multiple()
,
which_mutual()
Author
Gabor Csardi csardi.gabor@gmail.com, the first version was done by Vincent Matossian
Examples
g <- make_ring(10)
ego_size(g, order = 0, 1:3)
#> [1] 1 1 1
ego_size(g, order = 1, 1:3)
#> [1] 3 3 3
ego_size(g, order = 2, 1:3)
#> [1] 5 5 5
# neighborhood_size() is an alias of ego_size()
neighborhood_size(g, order = 0, 1:3)
#> [1] 1 1 1
neighborhood_size(g, order = 1, 1:3)
#> [1] 3 3 3
neighborhood_size(g, order = 2, 1:3)
#> [1] 5 5 5
ego(g, order = 0, 1:3)
#> [[1]]
#> + 1/10 vertex, from 809e4c0:
#> [1] 1
#>
#> [[2]]
#> + 1/10 vertex, from 809e4c0:
#> [1] 2
#>
#> [[3]]
#> + 1/10 vertex, from 809e4c0:
#> [1] 3
#>
ego(g, order = 1, 1:3)
#> [[1]]
#> + 3/10 vertices, from 809e4c0:
#> [1] 1 2 10
#>
#> [[2]]
#> + 3/10 vertices, from 809e4c0:
#> [1] 2 1 3
#>
#> [[3]]
#> + 3/10 vertices, from 809e4c0:
#> [1] 3 2 4
#>
ego(g, order = 2, 1:3)
#> [[1]]
#> + 5/10 vertices, from 809e4c0:
#> [1] 1 2 10 3 9
#>
#> [[2]]
#> + 5/10 vertices, from 809e4c0:
#> [1] 2 1 3 10 4
#>
#> [[3]]
#> + 5/10 vertices, from 809e4c0:
#> [1] 3 2 4 1 5
#>
# neighborhood() is an alias of ego()
neighborhood(g, order = 0, 1:3)
#> [[1]]
#> + 1/10 vertex, from 809e4c0:
#> [1] 1
#>
#> [[2]]
#> + 1/10 vertex, from 809e4c0:
#> [1] 2
#>
#> [[3]]
#> + 1/10 vertex, from 809e4c0:
#> [1] 3
#>
neighborhood(g, order = 1, 1:3)
#> [[1]]
#> + 3/10 vertices, from 809e4c0:
#> [1] 1 2 10
#>
#> [[2]]
#> + 3/10 vertices, from 809e4c0:
#> [1] 2 1 3
#>
#> [[3]]
#> + 3/10 vertices, from 809e4c0:
#> [1] 3 2 4
#>
neighborhood(g, order = 2, 1:3)
#> [[1]]
#> + 5/10 vertices, from 809e4c0:
#> [1] 1 2 10 3 9
#>
#> [[2]]
#> + 5/10 vertices, from 809e4c0:
#> [1] 2 1 3 10 4
#>
#> [[3]]
#> + 5/10 vertices, from 809e4c0:
#> [1] 3 2 4 1 5
#>
# attributes are preserved
V(g)$name <- c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j")
make_ego_graph(g, order = 2, 1:3)
#> [[1]]
#> IGRAPH 0376b5e UN-- 5 4 -- Ring graph
#> + attr: name (g/c), mutual (g/l), circular (g/l), name (v/c)
#> + edges from 0376b5e (vertex names):
#> [1] a--b b--c a--j i--j
#>
#> [[2]]
#> IGRAPH bd0d818 UN-- 5 4 -- Ring graph
#> + attr: name (g/c), mutual (g/l), circular (g/l), name (v/c)
#> + edges from bd0d818 (vertex names):
#> [1] a--b b--c c--d a--j
#>
#> [[3]]
#> IGRAPH c3b9952 UN-- 5 4 -- Ring graph
#> + attr: name (g/c), mutual (g/l), circular (g/l), name (v/c)
#> + edges from c3b9952 (vertex names):
#> [1] a--b b--c c--d d--e
#>
# make_neighborhood_graph() is an alias of make_ego_graph()
make_neighborhood_graph(g, order = 2, 1:3)
#> [[1]]
#> IGRAPH 61aaa17 UN-- 5 4 -- Ring graph
#> + attr: name (g/c), mutual (g/l), circular (g/l), name (v/c)
#> + edges from 61aaa17 (vertex names):
#> [1] a--b b--c a--j i--j
#>
#> [[2]]
#> IGRAPH 7a94148 UN-- 5 4 -- Ring graph
#> + attr: name (g/c), mutual (g/l), circular (g/l), name (v/c)
#> + edges from 7a94148 (vertex names):
#> [1] a--b b--c c--d a--j
#>
#> [[3]]
#> IGRAPH 687173a UN-- 5 4 -- Ring graph
#> + attr: name (g/c), mutual (g/l), circular (g/l), name (v/c)
#> + edges from 687173a (vertex names):
#> [1] a--b b--c c--d d--e
#>
# connecting to the neighborhood
g <- make_ring(10)
g <- connect(g, 2)