gpt4 book ai didi

r - 如何使用networkD3库设置桑基图中节点的颜色

转载 作者:行者123 更新时间:2023-12-02 03:38:55 58 4
gpt4 key购买 nike

我使用了以下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")

the output plot

最佳答案

您需要将黑色#000000分配添加到colourScale定义中的节点组1

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

关于r - 如何使用networkD3库设置桑基图中节点的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49294056/

58 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com