Closed ajwilk closed 2 years ago
Definitely not directly, but if you add some custom JavaScript, open the htmlwidget output in your browser, and inspect the console in your browser, you could get something like this...
library(networkD3)
library(htmlwidgets)
URL <- paste0('https://cdn.rawgit.com/christophergandrud/networkD3/',
'master/JSONdata/energy.json')
energy <- jsonlite::fromJSON(URL)
p <- sankeyNetwork(Links = energy$links, Nodes = energy$nodes, Source = 'source',
Target = 'target', Value = 'value', NodeID = 'name',
units = 'TWh', fontSize = 12, nodeWidth = 30)
customJS <- 'function() { console.log(this.sankey.nodes().map(d => [d.name, d.x, d.y])); }'
onRender(p, customJS)
thanks so much @cjyetman! I should be able to work with this.
Hi there, Thanks for a great package. How can I extract the optimized position or order of the nodes from the sankeyNetwork? It seems that node position is calculated in JS during creation of the widget and isn't returned in a
sankeyNetwork
object.My goal is to create an alluvial plot via the
ggalluvial
package but I can't find any package in R that optimizes the positions of nodes to minimize flow crossings for either alluvial or Sankey networks. So my idea is to havesankeyNetwork
do that heavy lifting for me and then pass the node positionsggalluvial
to make my alluvial plot.Thanks!