title: Why does forceNetwork in networkd3 R display all nodes not in edgelist?
body: <p>Thanks for any help you can provide.</p>
  
  <p>I am using the <code>networkd3</code> package in <code>R</code> to plot a <code>forceNetwork</code> plot of a nodelist and links (edgelist).</p>
  
  <p>I have an edgelist / link list:</p>
  
  <pre><code>&gt; edgelist
  
        round_prob NODEAid NODEBid
  33979     0.6245    6990    6588
  4899      0.9797    1042    1041
  37109     0.6046    7498    7531
  27771     0.7144    5906   16029
  3603      0.6452     783     804
  28491     0.6078    6034    5862
  4518      0.6245     962    9874
  19613     0.6745    4121   10285
  19916     0.8721    4179    4180
  8249      0.6821    1737    1733
  35389     0.7150    7145   16992
  32010     0.6495    6728   16921
  22553     0.6959    4722    4549
  14996     0.6031    3273   12929
  35927     0.6245    7221    9814
  15349     0.6245    3337    3233
  34833     0.6109    7085    6852
  39044     0.6117    7936    7977
  39075     0.6844    7944   10978
  11691     0.6821    2572    2587
  </code></pre>
  
  <p>This is a sample of a much larger edgelist, where I have selected only those links with link probability >0.6 and &lt;1. The full edgelist <em>was</em> zero-indexed before the sample was taken.</p>
  
  <p>I also have a nodelist, that is 18000 rows long. A sample of it is this:</p>
  
  <pre><code>&gt; head(nodes)
  
    node id gr
  0 1097  0  1
  1 1149  1  1
  2 1150  2  1
  3 3395  3  1
  4 3396  4  1
  5 3523  5  1
  </code></pre>
  
  <p>I try to plot using <code>forceNetwork</code>:</p>
  
  <pre><code>forceNetwork(Links = edgelist, Nodes = nodes, Source = "NODEAid",
               Target = "NODEBid", Value = "round_prob", NodeID = "node",
               Group = "gr", opacity = 0.9)
  </code></pre>
  
  <p>This gives this plot, before zooming in:</p>
  
  <p><a href="https://i.stack.imgur.com/qLqMa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qLqMa.png" alt="enter image description here"></a></p>
  
  <p>Problem: I only have 20 pairs of nodes, yet my plot has thousands more (I cannot return the number). </p>
  
  <p>By hovering over the unconnected points, I have been able to identify that they are made up of all possible nodes that feature in the nodelist.</p>
  
  <p>Basically I think that <code>forceNetwork</code> is plotting every possible node, even those not in the edgelist.</p>
  
  <p>Why is this happening and how can I stop it from doing so?</p>
  
  <hr>
  
  <p>As per this question <a href="https://stackoverflow.com/questions/31194888/going-crazy-with-forcenetwork-in-r-no-edges-displayed">Going crazy with forceNetwork in R: no edges displayed</a> I made sure that all my data was in numeric format and zero indexed. I still get this error.</p>
  
  <p>Note: If I run the forceNetwork example in this question <a href="https://stackoverflow.com/questions/42051274/how-to-plot-a-directed-graph-in-r-with-networkd3">How to plot a directed Graph in R with networkD3?</a> and from this tutorial <a href="https://christophergandrud.github.io/networkD3/" rel="nofollow noreferrer">https://christophergandrud.github.io/networkD3/</a> the output is as expected. </p>