2

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.

CJ Yetman
  • 8,373
  • 2
  • 24
  • 56
Amir.S
  • 719
  • 8
  • 15

1 Answers1

9

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... directed forceNetwork with arrows

CJ Yetman
  • 8,373
  • 2
  • 24
  • 56
  • 1
    Many Thanks , do you know any other package in R for drawing interactive directed graphs ? – Amir.S Feb 10 '17 at 06:28
  • igraph is the most comprehensive network analysis and visualization package that I know of http://igraph.org – CJ Yetman Feb 10 '17 at 09:27
  • 2
    Yeah , Thanks , I used it before , but the results(graphs) are not interactive. – Amir.S Feb 10 '17 at 11:31
  • 1
    Just found the visNetwork package. That might work for you. – CJ Yetman Feb 14 '17 at 08:16
  • 2
    I'm working on a new branch of networkD3 that will add arrows to the link lines. You can test it out by installing from github with... `devtools::install_github('cjyetman/networkD3', ref = 'directed_arrows')`. Then add `arrow = TRUE` to the `forceNetwork()` call and it should use arrows. I'd be interested in your feedback. – CJ Yetman Feb 15 '17 at 16:16
  • @Amir.S please see the update to my answer. We'd be happy to get your feedback on the implementation of this feature which you were looking for. – CJ Yetman Mar 16 '17 at 23:27
  • Thank you very much , looks very great. I'll be back soon with testing it. thanks alot , sorry for my late answer. – Amir.S Mar 30 '17 at 12:07
  • @CJYetman Is it possible to place labels near to each edge (a directed weighted graph like in igraph)? – peer Jan 18 '18 at 22:34
  • @peer sorry, not sure what you mean. may you should open a new question with greater detail? – CJ Yetman Jan 19 '18 at 00:07