The union of two or more graphs are created. The graphs may have identical or overlapping vertex sets.
Usage
# S3 method for class 'igraph'
union(
...,
byname = "auto",
graph.attr.comb = igraph_opt("graph.attr.comb"),
vertex.attr.comb = "rename",
edge.attr.comb = "rename"
)Arguments
- ...
Graph objects or lists of graph objects.
- byname
A Logical, or the character scalar
auto. Whether to perform the operation based on symbolic vertex names. If it isauto, that meansTRUEif all graphs are named andFALSEotherwise. A warning is generated ifautoand some (but not all) graphs are named.- graph.attr.comb, vertex.attr.comb, edge.attr.comb
Specification for combining clashing graph, vertex and edge attributes.
vertex.attr.combandedge.attr.combdefault to"rename";graph.attr.combdefaults to thegraph.attr.combigraph option ("rename"unless changed viaigraph_options())."rename"preserves the historical behaviour of appending_1,_2, ... suffixes. See igraph-attribute-combination for the available combiners.
Details
union() creates the union of two or more graphs. Edges which are
included in at least one graph will be part of the new graph. This function
can be also used via the %u% operator.
If the byname argument is TRUE (or auto and all graphs
are named), then the operation is performed on symbolic vertex names instead
of the internal numeric vertex IDs.
union() keeps the attributes of all graphs. All graph, vertex and
edge attributes are copied to the result. By default, if an attribute is
present in multiple graphs and would result in a name clash, that attribute
is renamed by adding suffixes: _1, _2, etc. Pass graph.attr.comb,
vertex.attr.comb or edge.attr.comb to combine clashing attributes
instead, e.g. by summing or by taking the first non-NA value. See
igraph-attribute-combination for the available combiners.
The name vertex attribute is treated specially if the operation is
performed based on symbolic vertex names. In this case name must be
present in all graphs, and it is not renamed in the result graph.
An error is generated if some input graphs are directed and others are undirected.
See also
Other functions for manipulating graph structure:
+.igraph(),
add_edges(),
add_vertices(),
complementer(),
compose(),
connect(),
contract(),
delete_edges(),
delete_vertices(),
difference(),
difference.igraph(),
disjoint_union(),
edge(),
igraph-minus,
intersection(),
intersection.igraph(),
path(),
permute(),
rep.igraph(),
reverse_edges(),
simplify(),
transitive_closure(),
union(),
vertex()
Author
Gabor Csardi csardi.gabor@gmail.com
Examples
## Union of two social networks with overlapping sets of actors
net1 <- graph_from_literal(
D - A:B:F:G, A - C - F - A, B - E - G - B, A - B, F - G,
H - F:G, H - I - J
)
net2 <- graph_from_literal(D - A:F:Y, B - A - X - F - H - Z, F - Y)
print_all(net1 %u% net2)
#> ── <igraph> ───────────────────────────────────────────────────────── 595bb76 ──
#> ℹ undirected · named
#> ℹ 13 vertices · 21 edges
#>
#> ── Attributes ──────────────────────────────────────────────────────────────────
#> → vertex: name <chr>
#>
#> ── Vertex attributes ───────────────────────────────────────────────────────────
#> name
#> [1] D
#> [2] A
#> [3] B
#> [4] F
#> [5] G
#> [6] C
#> [7] E
#> [8] H
#> [9] I
#> [10] J
#> [11] Y
#> [12] X
#> [13] Z
#>
#> ── Edges (vertex names) ────────────────────────────────────────────────────────
#> [1] I ─ J H ─ Z H ─ I G ─ H G ─ E F ─ X F ─ Y F ─ H F ─ C F ─ G
#> [11] B ─ E B ─ G A ─ X A ─ C A ─ F A ─ B D ─ Y D ─ G D ─ F D ─ B
#> [21] D ─ A
