2

I used the following R code, and got the following graph. But I want to change the color of the nodes from green to black. I tried my best to find a relevant method or parameter, but did not find one.

library(networkD3)

source <- c(0,1,3,4,4)
target <- c(2,2,1,1,0)
value <- c(33,44,66,77,88)
link_group <- as.character(c('a', 'b', 'c', 'd', 'e'))


sankeydata <- data.frame(source,target, value, link_group)
sankeydata
names <- c('a', 'b', 'c', 'd', 'e')
id <- c(0,1,2,3,4)
group <- as.character(c(1,1,1,1,1))

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

sankeyNetwork(Links = sankeydata, Nodes = sankeyNodes, Source = "source", colourScale = JS(
  'd3.scaleOrdinal()  
  .domain(["a","b","c","d","e"])
  .range(["#B3E2CD","#FDCDAC","#CBD5E8","#F4CAE4","#E6F5C9"])'), 
  Target = "target", Value = "value", NodeID = "names", LinkGroup = "link_group", units = "Quads",
  NodeGroup = "group", fontSize = 15, nodeWidth = 20,fontFamily = "Arial")

the output plot

roadfar
  • 51
  • 8

1 Answers1

5

You need to add black color #000000 assignment to the node group 1 in your colourScale definition

colourScale = JS('d3.scaleOrdinal().domain(["1", "a", "b", "c", "d", "e"]).
                 range(["#000000","#B3E2CD","#FDCDAC","#CBD5E8","#F4CAE4","#E6F5C9"])')
Prem
  • 11,775
  • 1
  • 19
  • 33