+.igraph

0th

Percentile

Add vertices, edges or another graph to a graph

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.

  • If is is another igraph graph object and they are both named graphs, then the union of the two graphs are calculated, seeunion.
  • If it is another igraph graph object, but either of the two are not named, then the disjoint union of the two graphs is calculated, seedisjoint_union.
  • If it is a numeric scalar, then the specified number of vertices are added to the graph.
  • If it is a character scalar or vector, then it is interpreted as the names of the vertices to add to the graph.
  • If it is an object created with thevertexorverticesfunction, then new vertices are added to the graph. This form is appropriate when one wants to add some vertex attributes as well. The operands of theverticesfunction specifies the number of vertices to add and their attributes as well.

    The unnamed arguments ofverticesare concatenated and used as thenamevertex attribute (i.e. vertex names), the named arguments will be added as additional vertex attributes. Examples:g <- g + vertex(shape="circle", color= "red") g <- g + vertex("foo", color="blue") g <- g + vertex("bar", "foobar") g <- g + vertices("bar2", "foobar2", color=1:2, shape="rectangle")vertexis just an alias tovertices, and it is provided for readability. The user should use it if a single vertex is added to the graph.

  • If it is an object created with theedgeoredgesfunction, then new edges will be added to the graph. The new edges and possibly their attributes can be specified as the arguments of theedgesfunction.

    The unnamed arguments ofedgesare concatenated and used as vertex ids of the end points of the new edges. The named arguments will be added as edge attributes.

    Examples:g <- make_empty_graph() + vertices(letters[1:10]) + vertices("foo", "bar", "bar2", "foobar2") g <- g + edge("a", "b") g <- g + edges("foo", "bar", "bar2", "foobar2") g <- g + edges(c("bar", "foo", "foobar2", "bar2"), color="red", weight=1:2)See more examples below.edgeis just an alias toedgesand it is provided for readability. The user should use it if a single edge is added to the graph.

  • If it is an object created with thepathfunction, then new edges that form a path are added. The edges and possibly their attributes are specified as the arguments to thepathfunction. The non-named arguments are concatenated and interpreted as the vertex ids along the path. The remaining arguments are added as edge attributes.

    Examples:g <- make_empty_graph() + vertices(letters[1:10]) g <- g + path("a", "b", "c", "d") g <- g + path("e", "f", "g", weight=1:2, color="red") g <- g + path(c("f", "c", "j", "d"), width=1:3, color="green")

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: -.igraph, igraph-minus; add.edges, add_edges; add.vertices, add_vertices; delete.edges, delete_edges; delete.vertices, delete_vertices; edge, edges; path; vertex, vertices

Aliases
  • +.igraph
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)
Documentation reproduced from package igraph, version 1.0.0, License: GPL (>= 2)

Community examples

Looks like there are no examples yet.