让我们创建一个非常简单的图表:
niv <- c("A","B","C","D","E")
from <- c("A","A","A","E","B","C","D")
to <- c("B","C","D","B","C","A","E")
arr <- c(rep("normal",6), "inv")
temp <- data.table(from=factor(from, levels=niv),
to=factor(to,levels=niv))
nodes <- create_node_df(n=length(niv), label=niv,
width=0.3)
edges <- create_edge_df(from = temp$from,
to = temp$to, rel = "leading_to", label=temp$from,
arrowhead=arr, penwidth=3, color="blue")
graph <- create_graph(nodes_df=nodes,edges_df=edges)
render_graph(graph)
该图显示了从一个节点到另一个节点的边缘 通常人们用箭头涂上那些边缘,但我想画一些带有相反符号的东西。
我发现通过使用参数 arrowhead =&#34; inv&#34; ,我可以将箭头改为尾巴。 (在我的例子中,从D到E的边有一个尾)。
但是有一个问题,尾巴被涂错了。我想在边缘的开头绘制它(箭头)。
如何更改?
有一个参数rel =&#34; leading_to&#34;但我还没能找到它能得到的其他价值 还有一个参数&#34; dir&#34;但我也不知道如何使用它。
感谢。
一个额外的问题是:如何阻止Diagrammer在边缘上方写标签?我希望他们不会重叠。
答案 0 :(得分:1)
您可以将目录切换为“后退”:
library(DiagrammeR)
library(data.table)
niv <- c("A","B","C","D","E")
from <- c("A","A","A","E","B","C","D")
to <- c("B","C","D","B","C","A","E")
temp <- data.table(from=factor(from, levels=niv),
to=factor(to,levels=niv))
nodes <- create_node_df(n=length(niv), label=niv,
width=0.3)
edges <- create_edge_df(from = temp$from,
to = temp$to, dir = "back", label=temp$from,
arrowtail="inv", penwidth=3, color="blue")
graph <- create_graph(nodes_df=nodes,edges_df=edges)
render_graph(graph)