I den folgenden Code bin mit einem rCharts Sankey-Diagramm (https://github.com/timelyportfolio/rCharts_d3_sankey) zu erzeugen:Einheiten in rCharts Sankey-Diagramm
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;
})
//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
In Sankeyplot$set
, habe ich einen Wert für die Einheiten. Allerdings sehe ich weder die Einheiten, noch sehe ich die Werte. Das Beispiel der Einheiten stammt aus der offiziellen github-Dokumentation (example_hirst_f1.R). Wie kann ich die Werte und die Einheiten in meinem Diagramm anzeigen?