Search code examples
rsankey-diagramnetworkd3

Sankey plot with bands/links that can change width in R?


Is it possible to make a sankey plot that looks like this in R? Example of required functionality

I've played around with the networkD3 package, which works great if the sum of input = sum of output for each node, but I need a solution which supports bands/links that change in size between time periods.

As far as I can work out, networkD3 does not allow me to do this because you must specify the links with a single value (links have a fixed width/value).

Is there anything out there, preferably for R, that can do this?


Solution

  • library(networkD3)
    
    links <- read.csv(header = T, text = "
    source,target,value
    0,1,50
    0,2,50
    1,3,50
    2,4,25
    3,5,75
    4,5,25
    ")
    
    nodes <- data.frame(name = c("A", "A", "B", "A", "B", "A"))
    
    sankeyNetwork(links, nodes, "source", "target", "value", "name")
    

    enter image description here