networkD3
networkD3 copied to clipboard
Add custom x-positions for nodes in Sankey plot
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,
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
+1 I would love this as well.
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):
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:
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:
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)
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)
The NodePosX
parameter was never implemented here in networkD3
. You may want to use sankeyD3.
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.
Better to ask over there then. This is the repo for networkD3.
Note that @SchmidtPaul give an answer here.