I have successfully drawn a single graph using Java, JavaGD and R. I followed this tutorial .
Now, I have an R-script, which reads a CSV file, does some calculations. At the end, it plots 8 different graphs. When I run this script using Java/JavaGD, only 1st and 8th plot are visible. 2nd through 7th are on "inactive" windows, which are blank. I am using the exact same code as in the above mentioned link/tutorial. So I guess something is getting overwritten.
How can I draw them on proper windows? Also, the first window, if re-sized, becomes blank. How to solve this issue?
Please don't hesitate to ask for clarification, if needed. I am not sure how well I have explained the problem.
Any help/reading material is greatly appreciated.
Update 1:
Currently, I am using this code:
public static void main(String[] args) {
// TODO Auto-generated method stub
Rengine re;
String[] dummyArgs = new String[1];
dummyArgs[0] = "--vanilla";
re = new Rengine(dummyArgs, false, null);
re.eval("library(JavaGD)");
// This is the critical line: Here, we tell R that the JavaGD() device that
// it is supposed to draw to is implemented in the class MyJavaGD. If it were
// in a package (say, my.package), this should be set to
// my/package/MyJavaGD1.
re.eval("Sys.putenv('JAVAGD_CLASS_NAME'='test/MyJavaGD1')");
re.eval("JavaGD()");
// re.eval("plot(c(1,5,3,8,5), type='l', col=2)");
// re.eval("source(\"C:\\Documents and Settings\\username\\My Documents\\Test Data\\BoxPlot.r\");");
re.eval("source(\"C:\\\\Documents and Settings\\\\username\\\\My Documents\\\\sampleRScript.R\")");
re.end();
System.out.println("Done!");
}
Part of the script:
par(las=2,mfrow=c(2,1))
PlotData <- subset (m4, select=c(LotNo,def,cavity,Lift), subset=(cavity=="1"))
boxplot(Lift ~ def, data=PlotData, main="Number 1")
hist(PlotData$Lift,50, main="", xlab="Lift", ylab="Frequency")
win.graph()
par(las=2,mfrow=c(2,1))
PlotData <- subset (m4, select=c(LotNo,def,cavity,Lift), subset=(cavity=="2"))
boxplot(Lift ~ def, data=PlotData, main="Number 2")
hist(PlotData$Lift,50, main="", xlab="Lift", ylab="Frequency")
win.graph()
par(las=2,mfrow=c(2,1))
PlotData <- subset (m4, select=c(LotNo,def,cavity,Lift), subset=(cavity=="3"))
boxplot(Lift ~ def, data=PlotData, main="Number 3")
hist(PlotData$Lift,50, main="", xlab="Lift", ylab="Frequency")
.
.
.