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

Add custom x-positions for nodes in Sankey plot #108

Closed
adrientaudiere opened this issue Mar 15, 2016 · 8 comments
Closed

Add custom x-positions for nodes in Sankey plot #108

adrientaudiere opened this issue Mar 15, 2016 · 8 comments

Comments

@adrientaudiere
Copy link

Hi,

First, thanks for you work on this very useful package. Is it possible to add a custom x-positions argument for nodes in Sankey plot? I want to use it with taxonomic data in combination with the phyloseq package (bioconductor) but I need to choose the position of nodes for this.

I am not comfortable with javascript but it seems relatively easy to allow this (e.g. http://stackoverflow.com/questions/21539265/d3-sankey-charts-manually-position-node-along-x-axis).

Thanks again,

@flopesdematos
Copy link

Hi,

I am also interested in the possibility of customize the nodes x-position in the Sankey plot.

Thank you.

All the best,
Fábio

@smartinsightsfromdata
Copy link

+1 I would love this as well.

@akraemer007
Copy link

Would Love to see this as well. Here is my specific use-case:

Ideally, I'd love a chart that looks like this so "Opted-Out" and "Invited" are inline (without the small bar going from oped out to activated):
image

name <- c('Enrolled', 'Opted-Out', 'Invited', 'Activated')
nodes <- data.frame(name)

source <- c(0, 0, 2, 1) 
target <- c(1, 2, 3, 3) 
value <- c(20, 80, 60, 1) 
links <- data.frame(source, target, value)
sankeyNetwork(Links = links, Nodes = nodes, Source = "source",
              Target = "target", Value = "value", NodeID = "name",
              units = "TWh", fontSize = 12, nodeWidth = 30)

If I set the fourth value of value to 0 I get this:
image

name <- c('Enrolled', 'Opted-Out', 'Invited', 'Activated')
nodes <- data.frame(name)

source <- c(0, 0, 2, 1) 
target <- c(1, 2, 3, 3) 
value <- c(20, 80, 60, 0) 
links <- data.frame(source, target, value)
sankeyNetwork(Links = links, Nodes = nodes, Source = "source",
              Target = "target", Value = "value", NodeID = "name",
              units = "TWh", fontSize = 12, nodeWidth = 30)

If I make the links data.frame only 3 rows long I get this:
image

name <- c('Enrolled', 'Opted-Out', 'Invited', 'Activated')
nodes <- data.frame(name)

source <- c(0, 0, 2) 
target <- c(1, 2, 3) 
value <- c(20, 80, 60) 
links <- data.frame(source, target, value)
sankeyNetwork(Links = links, Nodes = nodes, Source = "source",
              Target = "target", Value = "value", NodeID = "name",
              units = "TWh", fontSize = 12, nodeWidth = 30)

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)
@NevilHopley
Copy link

I have been using the sankeyD3 package to create SankeyNetworks and the 'NodePosX' feature isn't working for me yet. I tried to edit the above example from akraemer007 to include the X positions of the nodes, but it's still not working in the way that he had originally wanted. Am I missing something or is there a bug in the package for this feature?
Thank you
Nevil

library(sankeyD3)
name <- c('Enrolled', 'Opted-Out', 'Invited', 'Activated')
xpos <- c(0, 1, 1, 2)
nodes <- data.frame(name, xpos)

source <- c(0, 0, 2, 1) 
target <- c(1, 2, 3, 3) 
value <- c(20, 80, 60, 0) 
links <- data.frame(source, target, value)
sankeyNetwork(Links = links, Nodes = nodes, Source = "source",
              Target = "target", Value = "value", NodeID = "name",NodePosX = "xpos",
              units = "TWh", fontSize = 12, nodeWidth = 30)

@cjyetman
Copy link
Collaborator

The NodePosX parameter was never implemented here in networkD3. You may want to use sankeyD3.

@NevilHopley
Copy link

I thought I was. The code I posted was using the sankeyD3 package downloaded from GitHub, using the instructions from here. However, the code doesn't work in the example that I posted.

@cjyetman
Copy link
Collaborator

Better to ask over there then. This is the repo for networkD3.

@adrientaudiere
Copy link
Author

Note that @SchmidtPaul give an answer here.

@cjyetman cjyetman closed this as not planned Won't fix, can't repro, duplicate, stale Mar 29, 2024
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

6 participants