+.igraph {igraph}R Documentation

Add vertices, edges or another graph to a graph

Description

Add vertices, edges or another graph to a graph

Usage

## S3 method for class 'igraph'
e1 + e2

Arguments

e1

First argument, probably an igraph graph, but see details below.

e2

Second argument, see details below.

Details

The plus operator can be used to add vertices or edges to graph. The actual operation that is performed depends on the type of the right hand side argument.

It is important to note that, although the plus operator is commutative, i.e. is possible to write

  graph <- "foo" + make_empty_graph()

it is not associative, e.g.

  graph <- "foo" + "bar" + make_empty_graph()

results a syntax error, unless parentheses are used:

  graph <- "foo" + ( "bar" + make_empty_graph() )

For clarity, we suggest to always put the graph object on the left hand side of the operator:

  graph <- make_empty_graph() + "foo" + "bar"

See Also

Other functions for manipulating graph structure: 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(), union(), union.igraph(), vertex()

Examples

# 10 vertices named a,b,c,... and no edges
g <- make_empty_graph() + vertices(letters[1:10])

# Add edges to make it a ring
g <- g + path(letters[1:10], letters[1], color = "grey")

# Add some extra random edges
g <- g + edges(sample(V(g), 10, replace = TRUE), color = "red")
g$layout <- layout_in_circle
plot(g)

[Package igraph version 2.0.3 Index]