3

I have created a Sankey diagram using the riverplot package, with the help of the website from google (https://developers.google.com/chart/interactive/docs/gallery/sankey) and the community here. I am very happy with the graph now and would like to save it as a .svg, however I can not find the code in R to save it. Does anyone know how to do this?

Thank you very much for your help.

Here is my code:

df <- my data
colors_node <-    c('green','blue','red','yellow','brown','orange','darkviolet',
'grey','navy','aquamarine','darkgreen','firebrick')
colors_node_array <- paste0("[", paste0("'", colors_node,"'", collapse = ','), "]")
opts <- paste0("{
    iterations: 0,
    link: { color: { stroke: 'black', strokeWidth: 1 } },
    node: { colors: ", colors_node_array ,",
           label: { fontName: 'Arial',
                     fontSize: 8,
           color: '#871b47',
           bold: true,
           italic: true }} 
    }" )

plot(
   gvisSankey(df, from="origin", 
         to="visit", weight="weight",
         options=list(
           height=400, width = 300,
           sankey=opts
         ))
 )

I have also tried to use online software to convert the html file created (like here: Can I export part of an HTML page to an SVG image?), but I think due to the interactivity this is not possible

www
  • 38,575
  • 12
  • 48
  • 84
Paperwing
  • 65
  • 4

1 Answers1

0

I was looking for saving Google Sankey Diagram created by directly the JavaScript embedded HTML code from https://developers.google.com/chart/interactive/docs/gallery/sankey

Then, http://www.hiqpdf.com/demo/ConvertHtmlToSvg.aspx has managed it for me just by copying the html code to the site, I was able to download svg version of the visualisation

user2386488
  • 85
  • 10