9.10 Sankey Diagrams (cont.)

  • We’ll build the diagram using the sankeyNetwork function in the networkD3 package.

  • Sankey diagrams created with the networkD3 package are not ggplot2 graphs, so they can not be modified with ggplot2 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.