我使用了以下R代码,并获得了以下图表。但我想将节点的颜色从绿色更改为黑色。我尽力找到相关的方法或参数,但没有找到。
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")
答案 0 :(得分:4)
您需要在#000000
定义中的节点组1
中添加黑色colourScale
分配
colourScale = JS('d3.scaleOrdinal().domain(["1", "a", "b", "c", "d", "e"]).
range(["#000000","#B3E2CD","#FDCDAC","#CBD5E8","#F4CAE4","#E6F5C9"])')