How to plot a directed Graph in R with networkD3?

99封情书 提交于 2019-12-04 17:11:45

The forceNetwork() function of the networkD3 package does not draw arrows on the links for directed graphs. I can say that quite definitively because I am one of the currently active developers working on the package and I know the function and its options very well. You can also run ?networkD3::forceNetwork in your R console to see the help file and all of the possible options for the forceNetwork() function.

UPDATE (2017.03.20)

This feature (plotting arrows for a directed graph) is now part of the official CRAN release version of networkD3. Once installed, you can plot a directed forceNetwork with arrows with...

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)

and it should look like...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!