How to color groups in dank sankeyNetwork?

My nodes are made up of names and groups, but I cannot imagine the different colors for the groups in my sankey diagram. The colors are either blue, or the default, or all black using the code below.

Here is the code I'm using:

sankeyNetwork(        
Links = data$links,
Nodes = data$nodes,
Source= "source",
Target = "target",
Value = "weight",
NodeID = "names",
fontSize = 15,
NodeGroup = "group" 
))

Here's the output I get: enter image description here

+4
source share
2 answers
library(networkD3)
source <- c(0,1,2,3,4,5)
target <- c(2,2,2,3,1,0)
value <- c(33,44,55,66,77,88)

sankeydata <- data.frame(source,target, value)

names <- c('a', 'b', 'c', 'd', 'e', 'f')
id <- c(0,1,2,3,4,5)
group <- c(1,1,1,2,2,2)

sankeyNodes <- data.frame(names,id, group)


sankeyNetwork(Links = sankeydata, Nodes = sankeyNodes, Source = "source",
         Target = "target", Value = "value", NodeID = "names", NodeGroup = "group", fontSize = 12, nodeWidth = 30)

I would expect two colors (since there are two groups), but the colors do not return. I have the same problem as the OP.

Help text tells you that NodeGroup is responsible for color.

If you run the same code for another graph in the library (networkD3):

#same data
forceNetwork(Links = sankeydata, Nodes = sankeyNodes , Source = "source",
         Target = "target", Value = "value", NodeID = "names",
         Group = "group", opacity = 0.8, zoom = TRUE)

The network graph displays two different colors.

0
source

NodeGroup Nodes . . , , , , , , @john-friel, . , group ...

library(networkD3)
source <- c(0,1,2,3,4,5)
target <- c(2,2,2,3,1,0)
value <- c(33,44,55,66,77,88)

sankeydata <- data.frame(source,target, value)

names <- c('a', 'b', 'c', 'd', 'e', 'f')
id <- c(0,1,2,3,4,5)
group <- as.character(c(1,1,1,2,2,2))

sankeyNodes <- data.frame(names,id, group)


sankeyNetwork(Links = sankeydata, Nodes = sankeyNodes, Source = "source",
         Target = "target", Value = "value", NodeID = "names", 
         NodeGroup = "group", fontSize = 12, nodeWidth = 30)
0

All Articles