christophergandrud / networkD3

D3 JavaScript Network Graphs from R
http://christophergandrud.github.io/networkD3
650 stars 269 forks source link

Sanky diagram with cycle - loops #244

Closed paulrougieux closed 6 years ago

paulrougieux commented 6 years ago

Links between Sankey nodes are always uni-directional, they flow from left to right but it is not possible to link back to a previous node. For example with three nodes linked in this way: A -> B -> C It is not possible to loop back from C to A. Would it be possible to introduce Sankey diagrams with cycle or loops as discussed here: https://github.com/d3/d3-plugins/issues/1

cjyetman commented 6 years ago

This has been possible since #79 was merged.

library(networkD3)

links <- read.csv(header = TRUE, as.is = TRUE, text = "
source,target,value
0,1,1
1,2,1
2,0,1
")

nodes <- read.csv(header = TRUE, as.is = TRUE, text = "
name
A
B
C
")

sankeyNetwork(Links = links, Nodes = nodes, Source = "source",
              Target = "target", Value = "value", NodeID = "name")

sankey

paulrougieux commented 6 years ago

Thank you @cjyetman for the example.