2014-10-23 4 views
0

Есть ли ограничение на узлы санки? Я пытаюсь создать график с большим количеством узлов, и следующий код не может создать график (но не дает мне предупреждения об ошибке).R 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 <- 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 
+0

"Просмотр в браузере" => "Консоль JavaScript" => 'Uncaught TypeError: Не удается прочитать свойство 'sourceLinks' из undefined' – hrbrmstr

+0

, ИС библиотека установить пустой, вероятно, потому, что HTTP: //timelyportfolio.github .io/rCharts_d3_sankey/libraries/widgets/d3_sankey возвращает 404. – keegan

+0

404 не проблема. Там просто нет index.html. Я займусь этим. – timelyportfolio

ответ

1

См. http://timelyportfolio.github.io/rCharts_d3_sankey/example_build_network_sankey.html. На данный момент исходный и целевой столбцы эггелиста должны быть характерными. Также измените значение lapply на sapply.

Я ожидаю, что итоговая диаграмма все еще не то, что вы хотите, но, по крайней мере, она появляется, поэтому, возможно, вы захотите посмотреть на упомянутый выше link, чтобы убедиться, что ваша сеть соответствует ожиданиям 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 
Смежные вопросы