# Create a simple graph
nodes <-
create_nodes(
nodes = c("a", "b", "c", "d"),
type = "letter",
label = TRUE,
value = c(3.5, 2.6, 9.4, 2.7))
edges <-
create_edges(
from = c("a", "b", "c"),
to = c("d", "c", "a"),
rel = "leading_to")
graph <-
create_graph(
nodes_df = nodes,
edges_df = edges)
# Set attribute `color = "green"` for edges
# `a` -> `d` and `c` -> `a` using the graph object
graph <-
set_edge_attrs(
x = graph,
edge_attr = "color",
values = "green",
from = c("a", "c"),
to = c("d", "a"))
# Set attribute `color = "green"` for edges
# `a` -> `d` and `c` -> `a` using the edge
# data frame
edges <-
set_edge_attrs(
x = edges,
edge_attr = "color",
values = "green",
from = c("a", "c"),
to = c("d", "a"))
# 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 `a`
graph <-
set_edge_attrs(
x = graph,
edge_attr = "color",
values = "pink",
from = "a")
# Set attribute `color = "black"` for all edges in
# graph inbound to `a`
graph <-
set_edge_attrs(
x = graph,
edge_attr = "color",
values = "black",
to = "a")
Run the code above in your browser using DataLab