Sankey Diagram for energy consumption

A great Sankey Diagram built with R and the networkD3 package. Shows the flow of energy. Chart is interactive: move nodes if necessary, hover links for more information.

Sankey section About Sankey

Here is an example of Sankey diagram applied to a real data set. Original dataset is available here.

This chart is made using the networkD3 library, and comes from its documentation.

# Load package
# Load energy projection data
URL <- ""
Energy <- jsonlite::fromJSON(URL)

# Now we have 2 data frames: a 'links' data frame with 3 columns (from, to, value), and a 'nodes' data frame that gives the name of each node.
head( Energy$links )
head( Energy$nodes )
# Thus we can plot it
p <- sankeyNetwork(Links = Energy$links, Nodes = Energy$nodes, Source = "source",
              Target = "target", Value = "value", NodeID = "name",
              units = "TWh", fontSize = 12, nodeWidth = 30)

# save the widget
# library(htmlwidgets)
# saveWidget(p, file=paste0( getwd(), "/HtmlWidget/sankeyEnergy.html"))

Related chart types

Chord diagram
Arc diagram
Edge bundling


This document is a work by Yan Holtz. Any feedback is highly encouraged. You can fill an issue on Github, drop me a message on Twitter, or send an email pasting with

Github Twitter