DiagrammeR (version 0.9.0)

set_edge_attrs: Set edge attributes

Description

From a graph object of class dgr_graph or an edge data frame, set edge attribute properties for one or more edges

Usage

set_edge_attrs(x, edge_attr, values, from = NULL, to = NULL)

Arguments

x

either a graph object of class dgr_graph or an edge data frame.

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

either a graph object of class dgr_graph or an edge data frame, depending on what type of object was supplied to x.

Examples

Run this code
# NOT RUN {
# 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` using the graph object
graph <-
  set_edge_attrs(
    x = graph,
    edge_attr = "color",
    values = "green",
    from = c(1, 3),
    to = c(4, 1))

# Set attribute `color = "green"` for edges
# `1`->`4` and `3`->`1` using the edge
# data frame
edges <-
  set_edge_attrs(
    x = edf,
    edge_attr = "color",
    values = "green",
    from = c(1, 3),
    to = c(4, 1))

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

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

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

Run the code above in your browser using DataCamp Workspace