I wish to use create a Sankey diagram in R
with the sankeyNetwork()
function from networkD3
where I want to control in what "columns" nodes are located. Consider the following code
library(networkD3)
links <- data.frame(source=c("1_a", "1_b", "1_c", "2_b", "2_d"),
target=c("2_a", "2_b", "2_c", "3_a", "3_b"),
value=c(3,2,5,4,7))
nodes <- data.frame(name=c("1_a", "1_b", "1_c", "2_b", "2_d", "2_a",
"2_c", "3_a", "3_b"))
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")
This code produces the following plot:
However, I wish to align the nodes such that the first column contains "1_a", "1_b", "1_c", the second column "2_a", "2_b", "2_c" and "2_d" and the third "3_a" and "3_b". Adding sinksRight=FALSE
does not help as it produces the following plot:
Is it possible to achieve the desired output?