I am using the sankeyNetwork function to create a diagram of very simple flow data. Even using multiple iterations, the resulting diagram has obviously unnecessary crossovers.
I ran this code in R Studio 2023.06.2+561 with R version 4.3.1 (2023-06-16).
library(networkD3)
source<-c(0,1,2,0)
target<-c(3,3,4,4)
value<-c(13320, 274, 10950, 96000)
links<-data.frame(source, target, value)
nodes<-data.frame(names=c('Solar', 'Wind', 'Natural Gas', 'Electricity', 'Hydrogen'))
p <- sankeyNetwork(Links = links, Nodes = nodes, Source = "source",
Target = "target", Value = "value", NodeID = "names", iterations=32,
units = "TWh", fontSize = 12, nodeWidth = 30, sinksRight = FALSE)
The resulting Sankey Diagram has an obviously avoidable crossing: if "Wind" were above "Solar" then there would be no crossings. I've tried 1000 iterations and it doesn't do anything - which has me wondering if the issue is the platform or R Studio -- since 1000 iterations should be slower than 1.
I can't explain why exactly d3-sankey doesn't avoid that crossover, but if you change the order of your data (and don't bother messing with the iterations) you can avoid it...