我想更改Sankey中节点和链接的颜色。不幸的是d3.scale.Ordinal((函数对我不起作用。你知道吗?理想情况下,左侧的节点应该与离开这些节点的链接具有相同的颜色。
如果你有任何想法,我会很高兴。桑基在没有着色的情况下工作。塞西
这是代码:
links2 <- data.frame(source=c(0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5),target=c(6,7,8,9,6,7,8,9,6,7,8,9,6,7,8,9,6,7,8,9,6,7,8,9),value=c(3,6,8,8,2,7,5,1,5,5,13,12,43,5,2,7,8,6,5,7,3,5,4,19))
nodes2 <-data.frame(name=c("Cow","Ice","Emu","Coala","Uhu","Panda","Pink","Cyan","Grey","Green"))
links2$group <- as.factor(c("type_a","type_b","type_c","type_d","type_e","type_f"))
nodes2$group <- as.factor(c("a","b","c","d","e","f","g","h","i","j"))
my_colour <- 'd3.scale.Ordinal().domain(["type_a","type_b","type_c","type_d","type_e","type_f","a","b","c","d","e","f","g","h","i","j"]), .range(["darkblue", "gray45" , "khaki4", "skyblue1", "darkgoldenrod4", "gray27", "darkblue", "gray45" , "khaki4", "skyblue1", "darkgoldenrod4", "gray27","darkgreen", "forestgreen","yellowgreen","peru"])'
Network2 <- sankeyNetwork(Links=links2, Nodes=nodes2, Source = "source", Target = "target", Value = "value", NodeID = "name", sinksRight=FALSE,fontSize= 20,iterations=0, colourScale = my_colour, LinkGroup="group", NodeGroup="group")
```
您在传递给sankeyNetwork
的JavaScript字符串中有三个错误。
-
networkD3
使用D3v4,而不是D3v3…名称d3.scale.Ordinal
来自D3v3,而D3v4等效名称是d3.scaleOrdinal
-
该比特
]), .range([
应该是]).range([
-
您需要使用HTML颜色名称,而不是CSS3名称