autstat Support

icon
Avatar
aschmutz
Posts: 1
Hi,
I want to do a barchart with ggplot2 and print it in an Excel sheet.
I do my plot in a RInterface.RRun "" command, and to print it I use the command RInterface.InsertCurrentRPlot Range("'Sheet1'!$F$14'"). So I tried RInterface.RRun "print(name_plot)" but it isn't working.
But nothing happen, there isn't an error message in Rlog, and there isn't a graph printed in Excel neither.
Whereas, if I copy/paste the R code in excel and I execute it with a right click then "Run code", the graph is printed.
How can we use ggplot2 using VBA and Rexcel?

Thanks.

A.
[Last edited by aschmutz@lim-group.com, 2016-10-03 14:18]
2016-10-03 08:08
Avatar
Thomas Baier
Moderator
Posts: 217
Hi,

could you please post a complete example so we can reproduce the problem.

Thomas
2016-10-07 13:59
Avatar
erich
Posts: 2
This is an example of a VBA macro creating a ggplot2 chart and transferring it to an Excel sheet:


Sub gtest()
RInterface.StartRServer
RInterface.RRun "library(ggplot2) "
RInterface.PutDataframe "mydf", Range("A1:B12")
RInterface.RRun "gg <- ggplot(mydf,aes(x=x,y=y))+geom_line()"
RInterface.RRun "print(gg)"
RInterface.InsertCurrentRPlot Range("E8")
End Sub
2016-10-07 15:58
icon