title: How to sort source and/or target nodes in a sankey diagram within a shiny app?
body: <p>I have a simple sankey diagram, generated using <code>networkD3</code> package inside a shiny app. How can <code>source</code> and/or <code>target</code> nodes be sorted?</p>
  
  <p>As you can see in the MWE, by default, neither source nodes (A, B, C, D, E) nor target nodes (V, W, X, Y, Z) are sorted. At least, sorting is not comprehensible to me.</p>
  
  <p><a href="https://i.stack.imgur.com/jHAlI.png" rel="noreferrer"><img src="https://i.stack.imgur.com/jHAlI.png" alt="sankeyDiagram"></a></p>
  
  <p>Code:</p>
  
  <pre><code>library("shiny")
  library("networkD3")
  
  ui &lt;- fluidPage(
    column(3),
    column(6, sankeyNetworkOutput("mySankeyD")),
    column(3)
  )
  
  server &lt;- function(input, output) {
    output$mySankeyD &lt;- renderSankeyNetwork({
      myDf &lt;- list(
        nodes=data.frame(name=c( "A", "B", "C", "D", "E",
                                 "V", "W", "X", "Y", "Z")),
        links=data.frame(source=as.integer(c(0, 1, 2, 3, 3, 4, 4)),
                         target=as.integer(c(7, 6, 7, 8, 7, 5, 9)),
                         value =           c(1, 4, 1, 5, 1, 5, 3)
        )
      )
  
      sankeyNetwork(Links = myDf$links, Nodes = myDf$nodes, Source = "source",
                    Target = "target", Value = "value", NodeID = "name",
                    units = "TWh", fontSize = 25, nodeWidth = 30, fontFamily = "sans-serif", iterations = 30)
    })
  }
  
  shinyApp(ui, server)
  </code></pre>
  
  <p>How does <code>sankeyNetwork()</code> determine the order of nodes? Is it possible to sort them alphabetically?</p>
  
  <p>I'd like to have sorted source nodes, if possible also sorted target nodes.</p>
  
  <p><strong>EDIT</strong>
  As @emilliman5 pointed out in the comment, it is no possible to sort the nodes manually. </p>
  
  <p>Thus, are there other R packages out there to generate sankey diagrams that allow sorting of nodes? If yes, how to do so?</p>