如何在R中的SankeyNetwork Flow中为链接着色

时间:2019-04-20 16:05:29

标签: r sankey-diagram

我无法为链接添加颜色,尽管通过fl幸,我已经能够为节点着色。

my_color <- 'd3.scaleOrdinal()
   .domain(["2010", "2011", "2012", "2013", "2014"])
   .range(["blue", "pink", "green", "purple", "orange"])'

sankeyNetwork(Links = l3, Nodes = n3,
          Source = 'source',
          Target = 'target',
          Value = 'value',
          NodeID = 'name',
          units = 'ValueUSD',
          fontSize = 12,
          colourScale = my_color)

出现节点颜色,但不知道如何使链接着色。我希望链接的颜色基于年份,而不是基于国家/地区。

the output

2 个答案:

答案 0 :(得分:1)

取自“设置连接颜色”here

https://www.noon.com/uae-en/galaxy-m31-dual-sim-blue-6gb-ram-128gb-4g-lte/N35521717A/p?o=f885efe0b6534e9f
https://www.noon.com/uae-en/iphone-12-pro-max-with-facetime-128gb-pacific-blue-5g-international-specs/N41247213A/p?o=ca38c8921770ea2a
https://www.noon.com/uae-en/iphone-12-pro-with-facetime-256gb-pacific-blue-5g-international-specs/N41247235A/p?o=cfab59c09cab747b
...

答案 1 :(得分:0)

SankeyNetwork中来自NetworkD3软件包的选项受到限制。我建议调查“ plotly”包。在这里您可以找到一些示例:https://plot.ly/~alishobeiri/1591/plotly-sankey-diagrams/#/