4

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")
.
.
.
2
  • We see some code in the link for drawing one plot, but you do not show the code you used to plot the 8 plots. Try to boil this down to a small piece of R code which reproduces your problem. That would make it much easier to help us. Commented Jan 3, 2012 at 22:09
  • @PaulHiemstra: I am using the same code as in the link. I have updated the question. Please have a look. Commented Jan 4, 2012 at 15:01

1 Answer 1

2

You'll need to tell the R instance about your initialized JRI using .jengine(), otherwise it can't issue callbacks , e.g. to resize the window. As for blanked windows you'll need to provide the code that you use.

(You may want to use stats-rosuda-devel to discuss rJava/JRI/JavaGD-related issues there.)

Sign up to request clarification or add additional context in comments.

6 Comments

can you give some more details about .jengine()? any example or link?
It's a command in rJava - see ?.jengine. Suggested use would be something like re.eval("{library(rJava); .jengine()}"). Can you post your sampleScript.R code so we can look at the blanking issue?
.. that's incomplete - what is win.graph()??
You can ignore the ... and consider that as complete. The same set of 4 lines (from par( to hist() repeats after each win.graph();, total 8 number of times, hence I removed the repetitions. As I mentioned before, it plots 8 graphs. The win.graph() is an R function which is used to open another graphics window. It is not written by me, hence I am not sure if I can share the entire script or not. Please let me know if you need any more clarification.
Well, then ask the author (why it doesn't work). It's not part of R - why don't you just use dev.new()??
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.