How to create a Sankey Diagram? (maybe using D3.js?)

Hello,

I need your help in order to create a Sankey Diagram like:

  • https://bl.ocks.org/mbostock/ca9a0bb7ba204d12974bca90acc507c0
  • https://bl.ocks.org/wvengen/cab9b01816490edb7083

I have KNIME 3.4.0 on Windows and Mac, and I'm using "Generic JavaScript View" and I haven't had luck.

Does anyone has an example file?

Thanks!

Any ideas?

Hi Juan I read your post and I was pluzzed in how to plot this on Knime, I read this post "From D3 example to interactive KNIME view in 10 minutes" which uses the same code of this website http://bl.ocks.org/oyyd/859fafc8122977a3afd6.

I managed to load the json data (the energy one) and change the code to import the file. I think the problem is that the sankey code is calling a function called d3.sankey() which is in a library: https://github.com/d3/d3-sankey/releases/tag/v0.7.1. For that reason I was NOT able to plot the Sankey. 

Please find attached the workflow if helps.

 

Maybe one other thing:

we have a node for it on our roadmap. I added your thread as a +1 to the request :-)

Cheers, Iris 

2 Likes

Thank you mauuuuu5 and Iris for your replies.

I also wasn't able to use a library from the Internet.
I mean to use another library than the ones on the Node (D3, JSFreeChart, jQuery...)

Maybe there is something I'm missing... but if the JS is outside those included-Dependencies... it doesn't work.

Thank you mauuuuu5 for trying.

Will wait for Iris to include it, or maybe can you post some insights on what are we doing wrong?

Thanks!

Hi juanbretti I managed to make a Sankey Diagram, but using an R package called networkD3. The plot shows immediately when the nodes finishes to execute and prompts a new browser window.

I do not know how to make that HTML object as an “ordinary” R plot.

Please find the workflow attachedSankey.knwf (17.7 KB)

Hope it helps

1 Like

Thank you very much for the implementation of the R code.
Works very easily. Not the fastest, but works.
Thanks!

Just for future reference, I leave copy in the post of the R code you had used:

library(networkD3)
library(tidyverse)

nodes <- tibble(`name`=c("A","B", "C", "D"))
links <- tribble(
    ~`source`, ~`target`, ~`value`,
    0, 1, 10,
    0, 2, 20,
    1, 3, 30,
    2, 3, 40)
    
sankeyNetwork(Links = links, Nodes = nodes,
              Source = "source", Target = "target",
              Value = "value", NodeID = "name",
              fontSize= 12, nodeWidth = 30)
3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.