如何使用 networkD3 库设置桑基图中节点的颜色
How to set the color of nodes in the sankey plot using the networkD3 library
我用了下面的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")
您需要在 colourScale
定义
中向节点组 1
添加黑色 #000000
分配
colourScale = JS('d3.scaleOrdinal().domain(["1", "a", "b", "c", "d", "e"]).
range(["#000000","#B3E2CD","#FDCDAC","#CBD5E8","#F4CAE4","#E6F5C9"])')
我用了下面的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")
您需要在 colourScale
定义
1
添加黑色 #000000
分配
colourScale = JS('d3.scaleOrdinal().domain(["1", "a", "b", "c", "d", "e"]).
range(["#000000","#B3E2CD","#FDCDAC","#CBD5E8","#F4CAE4","#E6F5C9"])')