title: networkD3 forceNetwork: how to change legend text colour, text label colour, and bring text label to the front?
body: <p>I am trying to make some adjustments to a network graph plotted using <a href="/questions/tagged/networkd3" class="post-tag" title="show questions tagged &#39;networkd3&#39;" rel="tag">networkd3</a> <code>forcenetwork</code> in R. </p>
  
  <p>In particular, I would like to change the text label colour to black (or white, for black background) and bring the text labels to the front of the nodes. The standard option makes it really difficult to read the text labels as some labels are too light in colour, while others are obstructed by dense clusters of nodes. </p>
  
  <p>It would be nice if I can change the legend text colour too, so that I can have the flexibility to change the background colour. </p>
  
  <p>One possible solution as pointed out in this post <a href="https://stackoverflow.com/questions/36133746/change-background-color-of-networkd3-plot">here</a>, is to hijack some unused parameters. </p>
  
  <pre><code>forceNetwork(Links = MisLinks, Nodes = MisNodes,
     Source = "source", Target = "target",
     Value = "value", NodeID = "name",
     Group = "group", opacity = 0.8,
     linkDistance = 
       JS('function(){d3.select("body").style("background-color", "#DAE3F9");return 50;}'))
  </code></pre>
  
  <p>However, with no knowledge in JS, I have no idea how to write it or whether it is even possible. </p>