0

I want to programmatically set arbitrary edge attributes using DiagrammeR.

From the help, this works fine:

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))

but if I replace the last part with this, it doesn't work:

x="color"

graph <-
  graph %>%
  set_edge_attrs(
    edge_attr = x,
    values = "green",
    from = c(1, 3),
    to = c(4, 1))

Instead, the edges get an attribute called "x" rather than an attribute called "color". Any thoughts?

Steve Powell
  • 1,646
  • 16
  • 26

0 Answers0