如何使用R,Java和JRI绘制图形? [英] How to plot a graph using R, Java and JRI?

查看:229
本文介绍了如何使用R,Java和JRI绘制图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



如果我从Java程序运行脚本(JRI站点上给出的示例rtest.java程序),计算就可以了。但绘制图表存在一些问题。框架窗口打开并保持忙碌并挂起。 (如果我试图点击窗口,它会显示'Not Responding'。)我正在使用JRI。



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

  boxplot(mat); 

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



我很确定这是关于某些导入/包或类似的设置。但是无法确切地知道它到底是什么。



任何人都可以帮我这个吗?



谢谢。



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





。基本上你需要告诉R包 JavaGD 你有一个可以显示R图的JFrame。



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



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


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:

Output of this code on the link provided by John:

解决方案

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

这篇关于如何使用R,Java和JRI绘制图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆