Hi I am creating a sankey diagram to show migration. One aspect I am facing issues with is how to deal with scenarios when status doesn't change i.e. migration doesn't happen. In such scenarios, the sankey is circling back to same source, creating a circle rather than using a 'source- target' layout where both source destination is separate. I'd like to see something like
instead of following which I'm seeing now
Following is a reproducible example- I appreciate any assistance with this
library(networkD3)
library(dplyr)
links<-data.frame(
source=c('One','Two','Two','Three','Three','Four','Four','Five','Five','Six'),
target=c('Two','Two','Three','Three','Four','Four','Five','Five','Six','Seven'),
value=c(78,108,27,14,31,38,17,76,10,89)
)
nodes <- data.frame(
name=c(as.character(links$source),
as.character(links$target)) %>% unique()
)
links$IDsource <- match(links$source, nodes$name)-1
links$IDtarget <- match(links$target, nodes$name)-1
sankeyNetwork(Links = links, Nodes = nodes,
Source = "IDsource", Target = "IDtarget",
Value = "value", NodeID = "name",
fontSize = 20)