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


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


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?


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

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: 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 


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?


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.

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


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)

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