Reputation: 85
Hi I've constructed a Sankey Diagram using R's sankeyNetwork function.
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)
The spreadsheet entries are here.
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) By default the color of the nodes should all be different, but they're all blue. How can I make the color of the nodes all different?
2) Also ABW is too small to see anything. Is there anyway to make it bigger and the whole diagram less cramp?
Upvotes: 0
Views: 101
Reputation: 85
Found the answer. It's cause the node values weren't detected as unique.
Upvotes: 0