如何使用R,Java和JRI绘制图形?

时间:2021-08-29 20:15:03

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

我是R的新手,所以请原谅我这是一个非常基本的问题。

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.

我写了一个R脚本,它做了一些计算,最后绘制了Box Plot。如果我从R控制台运行此脚本,它运行正常并绘制图形。

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.

如果我从Java程序(JRI站点上给出的示例rtest.java程序)运行脚本,则计算结果很好。但绘制图表存在一些问题。框架窗口打开并保持忙碌并挂起。 (如果我尝试单击窗口,则会显示“无响应”。)我正在使用JRI。

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

这就是我在脚本中绘制图形的方式:

boxplot(mat);

Above command works fine on the R-console.

以上命令在R控制台上正常工作。

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:

编辑1:我的盒子绘图命令的输出:

如何使用R,Java和JRI绘制图形?

Output of this code on the link provided by John:

在John提供的链接上输出此代码:

如何使用R,Java和JRI绘制图形?

1 个解决方案

#1


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.

我是这样做的:粘贴链接。基本上你需要告诉R包JavaGD你有一个可以显示R图的JFrame。

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.

@John Colby的答案中的示例只是将绘图存储为文件,然后将其显示在Java中 - 也是一个选项,但这是一种有点间接的方式。

(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.)

(不幸的是,我的代码在Scala中,但由于它与Java非常相似(我用Java翻译它),我希望你能够将它翻译回来。我使用了一些JRI示例作为它的基础,它使用只有java类。)

#1


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.

我是这样做的:粘贴链接。基本上你需要告诉R包JavaGD你有一个可以显示R图的JFrame。

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.

@John Colby的答案中的示例只是将绘图存储为文件,然后将其显示在Java中 - 也是一个选项,但这是一种有点间接的方式。

(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.)

(不幸的是,我的代码在Scala中,但由于它与Java非常相似(我用Java翻译它),我希望你能够将它翻译回来。我使用了一些JRI示例作为它的基础,它使用只有java类。)