title: In R, how do I save a data.tree plot to a file?
body: <p>I'm unable to save a plot generated by the <code>plot.Node</code> function in <code>data.tree</code>. I've tried the following:</p>
  
  <pre><code>### Create tree object and plot it
  data(acme);
  plot(acme);
  </code></pre>
  
  <p>This works fine, showing the plot, as one would expect.</p>
  
  <pre><code>### Try saving it as png
  png(filename='file.png', type='cairo-png');
  plot(acme);
  dev.off();
  </code></pre>
  
  <p>This creates an empty file. <code>ggsave</code> does the same. Apparantly, <code>plot.Node</code> uses <code>DiagrammeR</code> under the hood, so I looked into that package. It has a function to export graphs:</p>
  
  <pre><code>export_graph(acme, file_name="file.png");
  </code></pre>
  
  <p>This gives the error:</p>
  
  <pre><code>Error in file.exists(diagram) : invalid 'file' argument
  </code></pre>
  
  <p>When I transform to GraphViz first, I get a different error:</p>
  
  <pre><code>export_graph(ToGraphViz(acme), file_name="file.png");
  
  Error in graph$dot_code : $ operator is invalid for atomic vectors
  </code></pre>
  
  <p>Clearly, exporting to GraphViz doesn't quite export to what DiagrammeR expects.</p>
  
  <p>I'm in RStudio and so could in theory just save the plot using the GUI, but I need this for in a script.</p>
  
  <p>Apparently, <code>plot.Node</code> doesn't actually <em>plot</em> anything - instead it seems to generate html/js. Does this mean that that result cannot be stored as a graphic? Or is there some export/conversion function somewhere that I'm completely missing? it certainly feels like I'm missing something obvious - I assume the need to store plotted <code>data.tree</code>s as images is quite common. But I have no idea which potential solutions I can still explore.</p>
  
  <p>I'd be very grateful for any pointers anybody has!</p>