如何为多级桑基图中的节点分配级别?
How to assign levels to nodes in multi-level sankey diagram?
我正在尝试使用 R 构建交互式多级桑基图。我找不到如何将级别分配给节点的解决方案。例如,a1 节点应该在图表中的第二层而不是第五层。似乎包将最右边的位置分配给链中的最后一个节点,这在我的情况下不是可取的。
我尝试了 echarts4r
、networkD3
、ggvis
等不同的包,但似乎这些包不提供管理图中级别的功能。
如果你知道如何解决这个问题,请分享。
library('networkD3')
library('echarts4r')
library('googleVis')
sankey <- data.frame(
source = c("a", "a", "b", "c", "d", "c"),
target = c("b", "a1", "c", "d", "e", "e"),
value = ceiling(rnorm(6, 10, 1)),
stringsAsFactors = FALSE
)
# googleVis solution
plot(gvisSankey(sankey, from = 'source', to = 'target', weight = 'value'))
# echarts4r solution
sankey %>%
e_charts() %>%
e_sankey(source, target, value, focusNodeAdjacency = 'allEdges')
# networkD3 solution
nodes <- data.frame(name = c("a", "a1", "b", "c", "d", "e"))
links <- data.frame(
source = c(0, 0, 2, 3, 4, 3),
target = c(2, 1, 3, 4, 5, 5),
value = ceiling(rnorm(6, 10, 1))
)
sankeyNetwork(Links = links,
Nodes = nodes,
Source = "source",
Target = "target", Value = "value", NodeID = "name",
fontSize = 12, nodeWidth = 30, sinksRight = TRUE)
使用 networkd3,将 sinksRight = TRUE
更改为 sinksRight = FALSE
library('networkD3')
sankey <- data.frame(
source = c("a", "a", "b", "c", "d", "c"),
target = c("b", "a1", "c", "d", "e", "e"),
value = ceiling(rnorm(6, 10, 1)),
stringsAsFactors = FALSE
)
sankeyNetwork(Links = links,
Nodes = nodes,
Source = "source",
Target = "target", Value = "value", NodeID = "name",
fontSize = 12, nodeWidth = 30, sinksRight = FALSE)
我正在尝试使用 R 构建交互式多级桑基图。我找不到如何将级别分配给节点的解决方案。例如,a1 节点应该在图表中的第二层而不是第五层。似乎包将最右边的位置分配给链中的最后一个节点,这在我的情况下不是可取的。
我尝试了 echarts4r
、networkD3
、ggvis
等不同的包,但似乎这些包不提供管理图中级别的功能。
如果你知道如何解决这个问题,请分享。
library('networkD3')
library('echarts4r')
library('googleVis')
sankey <- data.frame(
source = c("a", "a", "b", "c", "d", "c"),
target = c("b", "a1", "c", "d", "e", "e"),
value = ceiling(rnorm(6, 10, 1)),
stringsAsFactors = FALSE
)
# googleVis solution
plot(gvisSankey(sankey, from = 'source', to = 'target', weight = 'value'))
# echarts4r solution
sankey %>%
e_charts() %>%
e_sankey(source, target, value, focusNodeAdjacency = 'allEdges')
# networkD3 solution
nodes <- data.frame(name = c("a", "a1", "b", "c", "d", "e"))
links <- data.frame(
source = c(0, 0, 2, 3, 4, 3),
target = c(2, 1, 3, 4, 5, 5),
value = ceiling(rnorm(6, 10, 1))
)
sankeyNetwork(Links = links,
Nodes = nodes,
Source = "source",
Target = "target", Value = "value", NodeID = "name",
fontSize = 12, nodeWidth = 30, sinksRight = TRUE)
使用 networkd3,将 sinksRight = TRUE
更改为 sinksRight = FALSE
library('networkD3')
sankey <- data.frame(
source = c("a", "a", "b", "c", "d", "c"),
target = c("b", "a1", "c", "d", "e", "e"),
value = ceiling(rnorm(6, 10, 1)),
stringsAsFactors = FALSE
)
sankeyNetwork(Links = links,
Nodes = nodes,
Source = "source",
Target = "target", Value = "value", NodeID = "name",
fontSize = 12, nodeWidth = 30, sinksRight = FALSE)