Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sankey: any way to force the order of nodes? #153

Closed
daattali opened this issue Sep 23, 2016 · 1 comment
Closed

sankey: any way to force the order of nodes? #153

daattali opened this issue Sep 23, 2016 · 1 comment

Comments

@daattali
Copy link

When creating a sankey network, sometimes it's useful to be able to have the nodes in a specific order, and there doesn't seem to be a good way of knowing what order they'll appear in.

Example:

links <- data.frame(source = c(0, 1, 0, 1), target = c(2, 2, 3, 3), value = c(1, 2, 3, 4))
nodes <- data.frame(name = c("a", "b", "c", "d"))
networkD3::sankeyNetwork(links, nodes, 'source', 'target', 'value', 'name')

(a is above b)

vs

links <- data.frame(source = c(0, 1, 0, 1), target = c(2, 2, 3, 3), value = c(1, 5, 3, 4))
nodes <- data.frame(name = c("a", "b", "c", "d"))
networkD3::sankeyNetwork(links, nodes, 'source', 'target', 'value', 'name')

(the only difference is that the value "2" changed to "5" and now b is above a)

fbreitwieser added a commit to fbreitwieser/d3-sankey that referenced this issue Oct 19, 2016
- has several modifications from networkD3 sankey.js
- included fixes and features from unmerged pull requests:
- d3/d3-plugins#124: Fix nodesByBreadth to have proper ordering
- - d3/d3-plugins#120: Added 'l-bezier' link type
- d3/d3-plugins#74: Sort sankey target links by descending slope
- d3#4: Add horizontal alignment option to Sankey layout
- added option numberFormat, default being ",.5g" (see , fixes
christophergandrud/networkD3#147)
- added option NodePosX, fixes christophergandrud/networkD3#108
- added option to force node ordering to be alphabetical along a path
(only works well with trees with one parent for each node, but might fix
christophergandrud/networkD3#153)
fbreitwieser added a commit to fbreitwieser/sankeyD3 that referenced this issue Oct 19, 2016
Changelog:
 - ported to D3 v4
 - based on https://github.com/d3/d3-sankey
     - added several modifications from networkD3 sankey.js
     - included fixes and features from unmerged pull requests:
       - d3/d3-plugins#124: Fix nodesByBreadth to have proper ordering
       - d3/d3-plugins#120: Added 'l-bezier' link type
       - d3/d3-plugins#74: Sort sankey target links by descending slope
       - d3/d3-sankey#4: Add horizontal alignment option to Sankey layout
 - added option numberFormat, default being ",.5g" (see , fixesristophergandrud/networkD3#147)
 - added option NodePosX, fixes christophergandrud/networkD3#108
 - added option to force node ordering to be alphabetical along a path (only works well with trees with one parent for each node, but might fix christophergandrud/networkD3#153)
@cjyetman
Copy link
Collaborator

If you set iterations = 0 in sankeyNetwork(), you will effectively disable the algorithm which automatically determines the node placement (which is the primary purpose of the sankeyNetwork() function), and the nodes will be placed in the order that they appear in the Nodes dataframe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants