I discovered a way for exporting from offline R to svg

Hi guys, I have been struggling lately trying to export R plots in to an svg format in offline mode and I found a way to do it. I dont’t know if you guys already know this but it may help someone.

First you need to visualize your plot in Rstudio viewer, then export the plot to web page. Open the web page in the browser and right click and inspect element, search for the svg tag in the html code, copy the inner content of that tag in a new file, name the file with .svg extension and you can now enjoy your plot in svg format.

Hi Lahmer

Thanks for your suggestion. Is it possible to get the content of the svg tag programmatically e.g by the rvest package? Can you help me on the following example, please?:

library(plotly)

df <- data.frame(a = c(1,2),
b = c(3,4))

p <- plot_ly(df,x =~a,y =~b,mode = “scatter”,type = “scatter”)
htmlwidgets::saveWidget(p,“simplePlot.html”)