0

我想使用 DiagrammeR 以编程方式设置任意边缘属性。

从帮助中,这很好用:

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

但如果我用这个替换最后一部分,它就不起作用:

x="color"

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

相反,边缘得到一个名为“x”的属性,而不是一个名为“color”的属性。有什么想法吗?

4

0 回答 0