我想使用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))
相反,边缘会得到一个名为&#34; x&#34;而不是名为&#34; color&#34;的属性。有什么想法吗?