0

I am new to Rstudio and have just plotted a network diagram using simpleNetwork in the networkD3 package. I am looking to save the output in PDF/JPEG/TIFF format for my PhD thesis, however, most suggestions are with respect to saving it on a website (.html).

My code is as follows:

simpleNetwork(data, Source = 1, Target = 2, height = NULL, width = NULL,
          linkDistance = 120, charge = -40, fontSize = 12, fontFamily = "serif",
          linkColour = "grey", nodeColour = "black", opacity = 1.0, zoom = F)

Everything runs successfully, however I am not able to save the output as a PDF/JPEG/TIFF.

Is there any way I could save it in a picture or pdf format?

CJ Yetman
  • 8,373
  • 2
  • 24
  • 56

2 Answers2

3

Here is what I have done in the past using the 'htmlwidgets' and 'webshot' packages:

g <- simpleNetwork(data, Source = 1, Target = 2, height = NULL, width = NULL,
          linkDistance = 120, charge = -40, fontSize = 12, fontFamily = "serif",
          linkColour = "grey", nodeColour = "black", opacity = 1.0, zoom = F)
    
require(htmlwidgets)
saveWidget(g, file="name_of_your_file.html")

require(webshot)
webshot("file:///C:/Users/.../name_of_your_file.html", "name_of_your_pdf.pdf")
TWest
  • 765
  • 2
  • 6
  • 27
0

sometimes, a picture is worth a thousand words...

enter image description here

CJ Yetman
  • 8,373
  • 2
  • 24
  • 56
  • Thank you very much, CJ Yetman! I have already tried doing that, however, the resolution was terrible (both as jpeg & tiff). Is there another way the output could be saved via some sort of code/package? – mg19922611 May 12 '19 at 09:07
  • When you use the “Save as Image” feature, you can choose the resolution it exports to. Maybe you could use the webshot package to capture a screen capture of the viewer. Or use your operating system’s built-in screen capture ability. – CJ Yetman May 12 '19 at 11:30