6

I am very new to R, so please pardon me if this is a very very basic question.

I have written an R script, which does some calculations and at the end plots Box Plot. If I run this script from the R console, it runs fine and graph is plotted.

If I run the script from the Java program (the sample rtest.java program which is given on the JRI site), the calculations are done fine. But there is some problem with plotting the graph. The frame window opens and remains busy and hangs. (If I try to click on the window, it shows 'Not Responding'.) I am using JRI.

This is how I am plotting the graph in the script:

boxplot(mat);

Above command works fine on the R-console.

I am pretty sure that this is about some import/package or some similar setting. But not able to find out what exactly it is.

Can anyone help me with this?

Thanks.

EDIT 1: Output of my box-plotting command:

enter image description here

Output of this code on the link provided by John:

enter image description here

John Colby
  • 22,169
  • 4
  • 57
  • 69
Bhushan
  • 18,329
  • 31
  • 104
  • 137

1 Answers1

4

Here is how I did it: Pastebin link. Basically you need to tell the R package JavaGD that you have a JFrame available where the R plots can be displayed.

The example in the answer of @John Colby just stores the plot as a file and then displays it in Java - also an option, but a somewhat indirect way to do it.

(Unfortunately for you my code is in Scala, but as that's quite similar to Java (I translated it from Java), I hope you will be able to translate it back. I used some JRI example as a base for it, and it uses only java classes.)

ROLO
  • 4,183
  • 25
  • 41
  • Thanks for the reply ROLO. By any chance do you have the original Java code? or know where can I find it? – Bhushan Oct 21 '11 at 18:10
  • [This](http://www.wojtek.njh6.de/Ddocs/Djri/jri.html) should get you started. If I understand correctly from very quickly scanning through it the only thing you have to execute are these R command `library(JavaGD); JavaGD()` before you start plotting (i.e. no further java programming needed). – ROLO Oct 21 '11 at 18:22
  • If the question is about Java, the answer should also be on that language. With R 3 and Java 8 the code you link does not work. And I have no idea if it is a problem with the code itself or something else. – Luís de Sousa Feb 19 '17 at 09:03