Save graph from R as editable graphic in Excel
I am writing a GUI in R, and one of the functions I must implement is a button to save graphical output to an Excel sheet, ideally the graphic should be editable in Excel. I am trying to do this the following way:
- Save data used for graph to an .xlsx file
- Call a VBA scrip from R to recreate the graph in the .xlsx file.
I am stuck with step two, as I dont know how to execute a vba scrip from R. Any help is greatly appreciated.
I'd suggest setting up the sheet as a template and then create the graph and linking it to a specific area on the sheet or another sheet. Then when you need to create a new file, copy the template and add the data from R to Excel and then the graph will update with the new data.
If you want to use VBA then the method I generally use is StatconnDCOM + RCOM and just address Excel as a COM object.