I have implemented the code below to create an rCharts Sankey diagram, sourced from https://github.com/timelyportfolio/rCharts_d3_sankey:
if(!require(rCharts)){
library(devtools)
install_github('ramnathv/rCharts')
}
library(rCharts)
sankeyPlot <- rCharts$new()
sankeyPlot$setLib('http://timelyportfolio.github.io/rCharts_d3_sankey')
sankeyPlot$set(
data = data.frame(source=c('Cold','Warm','Total'),target=c('Total','Total','End'),value=c(20,80,100)),
nodeWidth = 15,
nodePadding = 10,
layout = 32,
width = 500,
height = 300,
units = "TWh",
labelFormat = ".1%"
)
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;
})
</script>
")
sankeyPlot
In my implementation of Sankeyplot$set
, I specified a value for units. However, I am unable to see either the units or the values on the chart produced. The example with units is taken from the official github documentation (example_hirst_f1.R). How can I display both the values and the units in my chart?