嗨,我使用R的sankeyNetwork函数构建了一个Sankey Diagram。
library(networkD3)
library(readxl)
links2 <- read_excel("/Users/desmondho/Documents/sankey2.xlsx", sheet = "links")
nodes2 <- read_excel("/Users/desmondho/Documents/sankey2.xlsx", sheet = "nodes")
sankeyNetwork(Links = links2, Nodes = nodes2, Source = "source",
Target = "target", Value = "value", NodeID = "name",
fontSize = 11, nodeWidth = 15,
fontFamily = "sans-serif", iterations = 0)
电子表格条目在这里。
sheet =“links”:
structure(list(source = c(0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5,
5, 5, 5), target = c(6, 7, 8, 9, 10, 11, 6, 7, 8, 9, 10, 11,
6, 7, 8, 9, 10, 11, 6, 7, 8, 9, 10, 11, 6, 7, 8, 9, 10, 11, 6,
7, 8, 9, 10, 11), value = c(1, 0, 0, 0, 0, 0, 1, 55908, 374,
2, 159, 93, 0, 672, 30879, 2, 203, 124, 0, 0, 0, 9341, 21, 169,
0, 702, 830, 0, 146554, 5058, 2, 2026, 2732, 0, 13273, 215844
)), row.names = c(NA, -36L), class = c("tbl_df", "tbl", "data.frame"
))
sheet =“nodes”
structure(list(X__1 = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
), name = c("ABW 0", "ABW 1", "ABW 3", "ABW 4", "ABW 5", "ABW 6",
"DBW 0", "DBW 1", "DBW 3", "DBW 4", "DBW 5", "DBW 6")), row.names = c(NA,
-12L), class = c("tbl_df", "tbl", "data.frame"))
1)默认情况下,节点的颜色应该都不同,但它们都是蓝色的。如何使节点的颜色完全不同?
2)ABW太小,看不到任何东西。反正是为了让它更大,整个图表更少抽筋?
找到了答案。这是因为节点值未被检测为唯一。