问题
when I am ploting a directed graph with NetworkD3 , The edges are not directed , how can I fix it ? an Example :
library(networkD3)
data(MisLinks)
data(MisNodes)
forceNetwork(Links = MisLinks, Nodes = MisNodes,
Source = "source", Target = "target",
Value = "value", NodeID = "name",
Group = "group", opacity = 0.8)
I want the result to be directed This is the definetion of directed Graph:
"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."
I want the edges be like arrows , how can i do it in networkD3 , I hope it's clear.
Thx.
回答1:
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...
来源:https://stackoverflow.com/questions/42051274/how-to-plot-a-directed-graph-in-r-with-networkd3