【发布时间】:2014-10-23 19:46:26
【问题描述】:
桑基图有节点限制吗?我正在尝试创建一个包含很多节点的图,但以下代码无法生成图(但没有给出错误警告)。
知道这里发生了什么吗?
# 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
【问题讨论】:
-
"在浏览器中查看" => "javascript 控制台" =>
Uncaught TypeError: Cannot read property 'sourceLinks' of undefined -
你设置的js库是空的,可能是因为timelyportfolio.github.io/rCharts_d3_sankey/libraries/widgets/…返回了404。
-
404 不是问题。那里没有 index.html。我会调查一下。
标签: r igraph rcharts sankey-diagram