简体   繁体   English

R sankey图节点限制?

[英]R sankey plot node limit?

Is there a node limit to sankey plots? sankey图是否有节点限制? 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

See http://timelyportfolio.github.io/rCharts_d3_sankey/example_build_network_sankey.html . 参见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 . 同样,将lapply更改为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。

# 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM