How to sort source and/or target nodes in a sankey diagram within a shiny app?

你说的曾经没有我的故事 提交于 2019-12-05 18:05:34
jmjr

Setting iterations = 0 inside sankeyNetwork() did the trick. Now nodes are plotted the same order as in the nodes dataframe.

library("networkD3")

myDf <- list(
    nodes=data.frame(name=c( "A", "B", "C", "D", "E",
                             "V", "W", "X", "Y", "Z")),
    links=data.frame(source=as.integer(c(0, 1, 2, 3, 3, 4, 4)),
                     target=as.integer(c(7, 6, 7, 8, 7, 5, 9)),
                     value =           c(1, 4, 1, 5, 1, 5, 3)
    )
)

sankeyNetwork(Links = myDf$links, Nodes = myDf$nodes, Source = "source",
              Target = "target", Value = "value", NodeID = "name",
              units = "TWh", fontSize = 25, nodeWidth = 30, 
              fontFamily = "sans-serif", iterations = 0)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!