networkD3 icon indicating copy to clipboard operation
networkD3 copied to clipboard

Add custom x-positions for nodes in Sankey plot

Open adrientaudiere opened this issue 8 years ago • 7 comments

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,

adrientaudiere avatar Mar 15 '16 16:03 adrientaudiere

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

flopesdematos avatar Apr 08 '16 17:04 flopesdematos

+1 I would love this as well.

smartinsightsfromdata avatar Apr 18 '16 12:04 smartinsightsfromdata

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)

akraemer007 avatar Jul 06 '16 20:07 akraemer007

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)

NevilHopley avatar Jul 13 '18 12:07 NevilHopley

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

cjyetman avatar Jul 13 '18 12:07 cjyetman

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.

NevilHopley avatar Jul 13 '18 13:07 NevilHopley

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

cjyetman avatar Jul 13 '18 13:07 cjyetman

Note that @SchmidtPaul give an answer here.

adrientaudiere avatar Mar 29 '24 09:03 adrientaudiere