Skip to contents

Set multiple vertex attributes

Usage

set_vertex_attrs(graph, ..., index = V(graph))

Arguments

graph

The graph.

...

<dynamic-dots> Named arguments, where the names are the attributes

index

An optional vertex sequence to set the attributes of a subset of vertices.

Value

The graph, with the vertex attributes added or set.

vcount()

Examples

g <- make_ring(10)
set_vertex_attrs(g, color = "blue", size = 10, name = LETTERS[1:10])
#> ── <igraph> Ring graph ────────────────────────────────────────────── a7953c2 ──
#>  undirected · named
#>  10 vertices · 10 edges
#> 
#> ── Attributes ──────────────────────────────────────────────────────────────────
#> → graph:  name <chr>, mutual <lgl>, circular <lgl>
#> → vertex: color <chr>, size <dbl>, name <chr>
#> 
#> ── Edges (vertex names) ────────────────────────────────────────────────────────
#>  [1] A ─ B  B ─ C  C ─ D  D ─ E  E ─ F  F ─ G  G ─ H  H ─ I  I ─ J  A ─ J 
# use splicing if suplying a list
x <- list(color = "red", name = LETTERS[1:10])
set_vertex_attrs(g, !!!x)
#> ── <igraph> Ring graph ────────────────────────────────────────────── a7953c2 ──
#>  undirected · named
#>  10 vertices · 10 edges
#> 
#> ── Attributes ──────────────────────────────────────────────────────────────────
#> → graph:  name <chr>, mutual <lgl>, circular <lgl>
#> → vertex: color <chr>, name <chr>
#> 
#> ── Edges (vertex names) ────────────────────────────────────────────────────────
#>  [1] A ─ B  B ─ C  C ─ D  D ─ E  E ─ F  F ─ G  G ─ H  H ─ I  I ─ J  A ─ J 
# to set an attribute named "index" use `:=`
set_vertex_attrs(g, color = "blue", index := 10, name = LETTERS[1:10])
#> ── <igraph> Ring graph ────────────────────────────────────────────── a7953c2 ──
#>  undirected · named
#>  10 vertices · 10 edges
#> 
#> ── Attributes ──────────────────────────────────────────────────────────────────
#> → graph:  name <chr>, mutual <lgl>, circular <lgl>
#> → vertex: color <chr>, index <dbl>, name <chr>
#> 
#> ── Edges (vertex names) ────────────────────────────────────────────────────────
#>  [1] A ─ B  B ─ C  C ─ D  D ─ E  E ─ F  F ─ G  G ─ H  H ─ I  I ─ J  A ─ J