0

I have an R script named plot.R which reads data from a .txt file then creates a matrix which is then plotted using matplot. My matplotfunction is like that :

matplot(mymatrix,col=rainbow(3),lty=1,xaxt='n',yaxy='n',main='title')
axis(1,at=seq(1,dim(mymatrix)[1],by=1),labels=as.character(mylist))
axis(2,at=seq(floor(min(mymatrix)),ceiling(max(mymatrix)),by=0.05))
legend("topright",legend=c('name1','name2','name3'),col=rainbow(3))
some abline functions and some points displayed

My goal is too create a macro in VBA which launches the script via a Shell command (I'm using Windows, so a cmd) :

Dim wsh as Object
Set wsh = VBA.CreateObject("WScript.Shell")
wsh.Run "Pathname\myscript.cmd"

and the batch file is like this:

R CMD BATCH -slave mypath\plot.R

and I would like to display the plot created in my R script, if possible I would like to paste it (as a picture) in an Excel Worksheet.

How should I do this, keeping in mind that I would like my plot to look like it looks in R when I display it in fullscreen, so if possible without a reformatting ?

etienne
  • 3,648
  • 4
  • 23
  • 37
  • creating a R plot from Excel and paste it in a worksheet ... the way to operate seems completely crazy. Operate full R. – Colonel Beauvel Sep 15 '15 at 13:35
  • I understand it seems strange to use excel for that but I work from Excel where I got data which updates every second and for which I would like to have plots I can only have in R (Excel cannot do what I want in R or not good enough) and it is easier to have all the info in a worksheet rather than switching between R and Excel if I want to look at the plots. – etienne Sep 15 '15 at 13:38
  • Is this a duplicate of http://stackoverflow.com/q/3730350/946850? (Not voting to close yet.) – krlmlr Sep 15 '15 at 13:46
  • I knew about RExcel but do not have admin rights on my computer to install it, so this post can not answer my question (I guess) – etienne Sep 15 '15 at 13:48
  • check out http://www.math.ucla.edu/~anderson/rw1001/library/base/html/windows.html (random URL for the r man page for the Windows graphics device). note the _"If the filename is omitted for a win.metafile device, the output is copied to the clipboard when the device is closed."_ – hrbrmstr Sep 15 '15 at 16:22
  • @etienne did you find any answer... i also have same problem.. dont have admin rights on my computer – aman Aug 02 '17 at 17:21

0 Answers0