set_edge_attrs: Set edge attribute values

Description Usage Arguments Value See Also Examples

View source: R/set_edge_attrs.R

Description

From a graph object of class dgr_graph, set edge attribute values for one or more edges.

Usage

1
set_edge_attrs(graph, edge_attr, values, from = NULL, to = NULL)

Arguments

graph

A graph object of class dgr_graph.

edge_attr

The name of the attribute to set.

values

The values to be set for the chosen attribute for the chosen edges.

from

An optional vector of node IDs from which the edge is outgoing for filtering list of nodes with outgoing edges in the graph.

to

An optional vector of node IDs from which the edge is incoming for filtering list of nodes with incoming edges in the graph.

Value

A graph object of class dgr_graph.

See Also

Other Edge creation and removal: add_edge_clone(), add_edge_df(), add_edges_from_table(), add_edges_w_string(), add_edge(), add_forward_edges_ws(), add_reverse_edges_ws(), copy_edge_attrs(), create_edge_df(), delete_edges_ws(), delete_edge(), delete_loop_edges_ws(), drop_edge_attrs(), edge_data(), join_edge_attrs(), mutate_edge_attrs_ws(), mutate_edge_attrs(), recode_edge_attrs(), rename_edge_attrs(), rescale_edge_attrs(), rev_edge_dir_ws(), rev_edge_dir(), set_edge_attr_to_display(), set_edge_attrs_ws()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Create a simple graph
ndf <-
  create_node_df(
    n = 4,
    type = "basic",
    label = TRUE,
    value = c(3.5, 2.6, 9.4, 2.7))

edf <-
  create_edge_df(
    from = c(1, 2, 3),
    to = c(4, 3, 1),
    rel = "leading_to")

graph <-
  create_graph(
    nodes_df = ndf,
    edges_df = edf)

# Set attribute `color = "green"`
# for edges `1`->`4` and `3`->`1`
# in the graph
graph <-
  graph %>%
  set_edge_attrs(
    edge_attr = color,
    values = "green",
    from = c(1, 3),
    to = c(4, 1))

# Set attribute `color = "blue"`
# for all edges in the graph
graph <-
  graph %>%
  set_edge_attrs(
    edge_attr = color,
    values = "blue")

# Set attribute `color = "pink"`
# for all edges in graph outbound
# from node with ID value `1`
graph <-
  graph %>%
  set_edge_attrs(
    edge_attr = color,
    values = "pink",
    from = 1)

# Set attribute `color = "black"`
# for all edges in graph inbound
# to node with ID `1`
graph <-
  graph %>%
  set_edge_attrs(
    edge_attr = color,
    values = "black",
    to = 1)

DiagrammeR documentation built on July 2, 2020, 3:19 a.m.