【发布时间】:2022-10-18 15:36:47
【问题描述】:
我在 RStudio 中运行下面的代码,并想用 plotly 创建 sankey 图表。代码运行没有错误。但不显示桑基图。这里有什么问题?
library("plotly")
a = read.csv('cleanSankey.csv', header=TRUE, sep=',')
node_names <- unique(c(as.character(a$source), as.character(a$target)))
nodes <- data.frame(name = node_names)
links <- data.frame(source = match(a$source, node_names) - 1,
target = match(a$target, node_names) - 1,
value = a$value)
nodes_with_position <- data.frame(
"id" = names,
"label" = node_names,
"x" = c(0, 0.1, 0.2, 0.3,0.4,0.5,0.6,0.7),
"y" = c(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7)
)
#Plot
plot_ly(type='sankey',
orientation = "h",
node = list(
label = node_names,
x = nodes_with_position$x,
y = nodes_with_position$y,
color = "grey",
pad = 15,
thinkness = 20,
line = list(color = "grey", width = 0.5)),
link = list(
source = links$source,
target = links$target,
value = links$value))
sankey 被绘制,但是第二层的节点转到最后一层。如何固定节点位置?
【问题讨论】:
标签: r plotly sankey-diagram