如何使用 networkD3 在 R 中绘制有向图?

How to plot a directed Graph in R with networkD3?

当我使用 NetworkD3 绘制有向图时,边没有方向,我该如何解决? 一个例子:

library(networkD3)
data(MisLinks)
data(MisNodes)
forceNetwork(Links = MisLinks, Nodes = MisNodes,
         Source = "source", Target = "target",
         Value = "value", NodeID = "name",
         Group = "group", opacity = 0.8)

我希望结果是有向的 这是有向图的定义:

"A directed graph is graph, i.e., a set of objects (called vertices or nodes) that are connected together, where all the edges are directed from one vertex to another. A directed graph is sometimes called a digraph or a directed network."

我希望边缘像箭头一样,在 networkD3 中如何实现,希望清楚。

谢谢。

networkD3 包的 forceNetwork() 函数不会在有向图的链接上绘制箭头。我可以非常肯定地说,因为我是目前活跃的开发人员之一,并且我非常了解该功能及其选项。您还可以在 R 控制台中 运行 ?networkD3::forceNetwork 查看帮助文件和 forceNetwork() 函数的所有可能选项。

更新 (2017.03.20)

此功能(为有向图绘制箭头)现在是 networkD3 官方 CRAN 发布版本的一部分。安装后,您可以绘制带有箭头的定向力网络...

library(networkD3)
URL <- paste0("https://cdn.rawgit.com/christophergandrud/networkD3/",
              "master/JSONdata/miserables.json")
MisJson <- jsonlite::fromJSON(URL)
ValjeanInds <- which(MisJson$links == 11, arr = TRUE)[, 1]
ValjeanCols <- ifelse(1:nrow(MisJson$links) %in% ValjeanInds, "#bf3eff", "#666")

forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source", Target = "target", 
             Value = "value", NodeID = "name", Group = "group", opacity = 0.8, 
             linkColour = ValjeanCols, arrows = TRUE, zoom = TRUE)

它应该看起来像...