Native color range for Sankey diagram with networkD3 package in R

I am trying to build Sankey diagrams using sankeyNetwork()networkD3 in the package.

sankeyNetwork(Links = Flow_data, Nodes = Nodes_data,
    Source = "Source_ID", Target = "Target",
    Value = "value", NodeID = "Nodes_name",
    width = 1000, height=600, fontsize = 16, nodeWidth = 50,
    colourScale = "d3.scale.category20c()")

Rendering works fine, but I would like to change the range of colors to a separate range. Is there a chance to change the colors of SankeyNetwork? I only need a range, for example. 3 colors that I can set myself (not predefined colors).

+4
source share
1 answer

You can configure:

sankeyNetwork(Links = Flow_data, Nodes = Nodes_data,
                      Source = "Source_ID", Target = "Target",
                      Value = "value", NodeID = "Nodes_name",
                      width = 1000, height=600, fontsize = 16, nodeWidth = 50,
                      colourScale = "d3.scale.category20c()")  <==== Categorical color

UPDATE

Newer version:

d3.scale.ordinal().range(["#7d3945","#e0677b", "#244457"])
now works if changed to:
d3.scaleOrdinal().range(["#7d3945","#e0677b", "#244457"]) 

Thanks @Peter Ellis

UPDATE

Is there a way to set transparency when using custom colors?

"# AARRGGBB" doesn't seem to work

selectAll ( "_" ). style ( "opacity", 0.5), : fooobar.com/questions/1604425/... . CSS3 : "fill =" rgba (124,240,10,0.5) "

: http://bl.ocks.org/aaizemberg/78bd3dade9593896a59d

: https://github.com/mbostock/d3/wiki/Ordinal-Scales#categorical-colors

+6

All Articles