This page follows the graph #321 that describes how to make an interactive Sankey diagram with the networkD3 library. Now that you know what kind of input allows to work with this library, you probably want to control the color of your nodes and connection. This is a bit tricky since you have to call it in Javascript, as described in the code below.


1 – Custom color of individual nodes

The first step is to create a colour links Javascript object. For each node I attribute one color. Then I can call this object in the colourScale argument of networkD3.



2 – Set color for groups of nodes

Sometimes you want to color nodes following their attribution to a group. Usually this information is stored in a column of the node data frame. You can use this information to create a JavaScript color attribution object and call it using the Nodegroup argument.



3 – Set color of connection

Following the same principle, you can control the color of each flows of your diagram:







Make a search