0

让我们创建一个非常简单的图表:

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="inv"我可以将箭头改为尾巴。(在我的例子中,从 D 到 E 的边有一条尾巴)。

但是有一个问题,尾巴画错了。我想在边缘的开始处画它(箭头)。

我怎样才能改变它?

有一个参数 rel = "leading_to" 但我无法找到它可以获得的其他值。
还有一个参数“dir”,但我也不知道如何使用它。

谢谢。

一个额外的问题是:如何防止 Diagrammer 在边缘上方写标签?我希望它们不要重叠。

4

1 回答 1

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)
于 2017-12-08T21:20:28.220 回答