Within the R environment, is there any way to add gradients to links with user-specified colors within the networkD3::sankeyNetwork functions?
This repo expands on the functions of networkD3::sankeyNetwork, but it only seems to allow for the linkGradient
parameter when the LinkGroup
parameter isn't used, i.e. you can only use the gradient when all links are the same color. Unfortunately, I require LinkGroup
to specify a different color for each link.
Here's a reproducible example of a Sankey diagram with user-specified colors for the links, but without the gradient that I'm trying to impose.
source = as.numeric(c("0", "0", "0", "0"))
target = as.numeric(c("1", "2", "3", "4"))
value = as.numeric(c("40", "10", "5", "20"))
group = c("red", "yellow", "green", "blue")
node = as.numeric(c("0", "1", "2", "3", "4"))
name = c("source", "red", "yellow", "green", "blue")
links = data.frame(source, target, value, group)
nodes = data.frame(node, name)
networkD3::sankeyNetwork(Links = links, Nodes = nodes,
Source = 'source',
Target = 'target',
Value = 'value',
NodeID = 'name',
units = 'UOM',
LinkGroup = 'group',
colourScale = JS('d3.scaleOrdinal()
.domain(["miRNA","red", "yellow", "green", "blue"])
.range(["black", "red", "yellow","green","blue"])'))
Edit: Yes, there is a java option here, but I'm looking for a solution within the R environment, i.e. via R, not java. Further, that solution doesn't work well with heavily curved links. The aforementioned repo provides a much smoother gradient with curved lines. I don't know how to modify from there to allow for multiple colored links with a gradient.