I am working on network data and want to visualize it using sankeyNetwork() from the 
networkD3 does not have any built-in legend creation options, however, if you want to make a legend yourself, you'll probably want to use a consistent set of colors so that you can use them with whatever you use to make a legend. You can do that like this...
colourScale <-
'd3.scaleOrdinal()
.domain(["A", "B", "C", "D"])
.range(["red", "blue", "green", "yellow"])'
sankeyNetwork(Links = data,
Nodes = nodes,
Source = "IDsource",
Target = "IDtarget",
Value = "value",
NodeID = "name",
sinksRight=FALSE,
nodeWidth=40,
fontSize=13,
nodePadding=20,
LinkGroup = 'group',
NodeGroup = NULL,
colourScale = colourScale)

