not sure which colors you want, but if you installed a new rCharts with devtools::install_github("ramnathv/rCharts") , here is how you can color based on the original value with a demo here .
require(rCharts) require(rjson) x = read.csv('/Users/<username>/sankey.csv', header=FALSE) colnames(x) <- c("source", "target", "value") sankeyPlot <- rCharts$new() sankeyPlot$set( data = x, nodeWidth = 15, nodePadding = 10, layout = 32, width = 500, height = 300, units = "TWh", title = "Sankey Diagram" ) sankeyPlot$setLib('http://timelyportfolio.imtqy.com/rCharts_d3_sankey') sankeyPlot$setTemplate( afterScript = " <script> // to be specific in case you have more than one chart d3.selectAll('#{{ chartId }} svg path.link') .style('stroke', function(d){ //here we will use the source color //if you want target then sub target for source //or if you want something other than gray //supply a constant //or use a categorical scale or gradient return d.source.color; }) //note no changes were made to opacity //to do uncomment below but will affect mouseover //so will need to define mouseover and mouseout //happy to show how to do this also // .style('stroke-opacity', .7) </script> ") sankeyPlot
If you want to use d3.scale.category??() to provide your color, I assume that you will want to color the node rectangle as well. Here is one example of a color change for both node and link.
sankeyPlot$setTemplate( afterScript = " <script> var cscale = d3.scale.category20b(); </script> ") sankeyPlot
timelyportfolio
source share