0

Is there a node limit to sankey plots? I am trying to create a plot with a lot of nodes and the following code fails to produce a plot (but gives me no error warning).

Any idea what is happening here?

# sankey chart using d3 plugin for rCharts and the igraph library

require(rCharts)
require(igraph)

# these are our vertices/nodes/end points/stages/categories/classes/whatever
nodes = c(1:36)

# the chart is basically a graph

pairs=c()
for (j in seq(1,36,by=4)) pairs=c(pairs,j,j+1,j+1,j+2,j+2,j+3)
pairs
g <- graph(pairs)
plot(g)
E(g)
E(g)$weights <- rep(c(16667,500,100),9)
length(E(g)$weights)

# convert to data frame with appropriate node names
edgelist <- get.data.frame(g)

# name columns as what is expected by plugin
colnames(edgelist) <- c("source", "target", "value")
edgelist

edgelist$source <- lapply(edgelist$source, FUN = function(x) {nodes[x]})
edgelist$target <- lapply(edgelist$target, FUN = function(x) {nodes[x]})
edgelist

# now we plot
sankeyPlot <- rCharts$new()
sankeyPlot$setLib('http://timelyportfolio.github.io/rCharts_d3_sankey/libraries/widgets/d3_sankey')
sankeyPlot$set(
data = edgelist,
nodeWidth = 15,
nodePadding = 15,
layout = 32,
width = 960,
height = 500
)
sankeyPlot
vashts85
  • 1,069
  • 3
  • 14
  • 28
  • "View in browser" => "javascript console" => `Uncaught TypeError: Cannot read property 'sourceLinks' of undefined` – hrbrmstr Oct 23 '14 at 19:57
  • The js library you set is empty, likely because http://timelyportfolio.github.io/rCharts_d3_sankey/libraries/widgets/d3_sankey returns a 404. – keegan Oct 23 '14 at 20:20
  • 404 is not the problem. There just isn't an index.html there. I'll look into this. – timelyportfolio Oct 24 '14 at 14:15

1 Answers1

1

See http://timelyportfolio.github.io/rCharts_d3_sankey/example_build_network_sankey.html. As of now the source and target columns of the edgelist must be character. Also, change the lapply to sapply.

I expect the resulting chart is still not what you want, but at least it shows up, so might want to look at the link mentioned above to make sure your network is as expected for a proper Sankey.

# sankey chart using d3 plugin for rCharts and the igraph library

require(rCharts)
require(igraph)

# these are our vertices/nodes/end points/stages/categories/classes/whatever
nodes = c(1:36)

# the chart is basically a graph

pairs=c()
for (j in seq(1,36,by=4)) pairs=c(pairs,j,j+1,j+1,j+2,j+2,j+3)
pairs
g <- graph(pairs)
plot(g)
E(g)
E(g)$weights <- rep(c(16667,500,100),9)
length(E(g)$weights)

# convert to data frame with appropriate node names
edgelist <- get.data.frame(g)

# name columns as what is expected by plugin
colnames(edgelist) <- c("source", "target", "value")
edgelist

edgelist$source <- sapply(edgelist$source, FUN = function(x) {as.character(nodes[x])})
edgelist$target <- sapply(edgelist$target, FUN = function(x) {as.character(nodes[x])})
edgelist

# now we plot
sankeyPlot <- rCharts$new()
sankeyPlot$setLib('http://timelyportfolio.github.io/rCharts_d3_sankey/libraries/widgets/d3_sankey')
sankeyPlot$set(
  data = edgelist,
  nodeWidth = 15,
  nodePadding = 15,
  layout = 32,
  width = 960,
  height = 800
)
sankeyPlot
timelyportfolio
  • 6,479
  • 30
  • 33