add_vertices: Add vertices to a graph

Description Usage Arguments Value See Also Examples

View source: R/interface.R

Description

If attributes are supplied, and they are not present in the graph, their values for the original vertices of the graph are set to NA.

Usage

1

Arguments

graph

The input graph.

nv

The number of vertices to add.

...

Additional arguments, they must be named, and they will be added as vertex attributes, for the newly added vertices. See also details below.

attr

A named list, its elements will be added as vertex attributes, for the newly added vertices. See also details below.

Value

The graph, with the vertices (and attributes) added.

See Also

Other functions for manipulating graph structure: +.igraph(), add_edges(), delete_edges(), delete_vertices(), edge(), igraph-minus, path(), vertex()

Examples

1
2
3
4
5
6
7
g <- make_empty_graph() %>%
  add_vertices(3, color = "red") %>%
  add_vertices(2, color = "green") %>%
  add_edges(c(1,2, 2,3, 3,4, 4,5))
g
V(g)[[]]
plot(g)

Example output

Attaching package: 'igraph'

The following objects are masked from 'package:stats':

    decompose, spectrum

The following object is masked from 'package:base':

    union

IGRAPH D--- 5 4 -- 
+ attr: color (v/c)
+ edges:
[1] 1->2 2->3 3->4 4->5
+ 5/5 vertices:
  color
1   red
2   red
3   red
4 green
5 green

igraph documentation built on March 19, 2020, 5:13 p.m.

Related to add_vertices in igraph...