9.10 Sankey Diagrams (cont.)
We’ll build the diagram using the
sankeyNetwork
function in thenetworkD3
package.Sankey diagrams created with the
networkD3
package are notggplot2
graphs, so they can not be modified withggplot2
functions.
p <- sankeyNetwork(Links = Energy$links,
Nodes = Energy$nodes,
Source = "source",
Target = "target",
Value = "value",
NodeID = "name",
units = "TWh", #optional unit names for popups
fontSize = 12,
nodeWidth = 30)
p
Following the flow from left to right, energy supplies are on the left and energy demands are on the right.
The graph is interactive so you are able to highlight nodes and drag them to new positions.