将绘图从 R 调用到 Java 应用程序中
有人成功使用 JRI 和 rJava 吗?我想将一些用 R 制作的图表放入我的 Java 应用程序中,但没有成功。任何人都可以提供工作示例。这是我发现的,但它不起作用。
import org.rosuda.JRI.REXP;
import org.rosuda.JRI.Rengine;
/**
* @author Nero
*In this file, I will try to plot a simple example, only to test how it?s possible to plot through java
*Attention: Nothing will work if you have not included the JRI.jar as library ( through properties)*/
public class TryPlot {
public static void main(String[] args) {
// TODO Auto-generated method stub
//start the Rengine (JRI)
Rengine re = new Rengine(null, false, null);
//in R: >a<- c(1.2,2.3,4.5) :
double da[] = {1.2, 2.3, 4.5};
long xp3 = re.rniPutDoubleArray(da);
re.rniAssign("a", xp3, 0);
//look up for a:
REXP x;
x = re.eval("a");
System.out.println(x);
//THE PROBLEM: The window opens, but nothing happens???
re.eval(" plot(a)");
}
}
Is there anybody who is succesfully working with JRI and rJava? I want to put some graphs, plots made in R into my Java application, but without success. Can anybody provide working example. Here is what I found, but its not working.
import org.rosuda.JRI.REXP;
import org.rosuda.JRI.Rengine;
/**
* @author Nero
*In this file, I will try to plot a simple example, only to test how it?s possible to plot through java
*Attention: Nothing will work if you have not included the JRI.jar as library ( through properties)*/
public class TryPlot {
public static void main(String[] args) {
// TODO Auto-generated method stub
//start the Rengine (JRI)
Rengine re = new Rengine(null, false, null);
//in R: >a<- c(1.2,2.3,4.5) :
double da[] = {1.2, 2.3, 4.5};
long xp3 = re.rniPutDoubleArray(da);
re.rniAssign("a", xp3, 0);
//look up for a:
REXP x;
x = re.eval("a");
System.out.println(x);
//THE PROBLEM: The window opens, but nothing happens???
re.eval(" plot(a)");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为普通的 R 图形设备只有在 R GUI 中使用时才起作用,而不是从 java 或命令行启动。
所以我使用“JavaGD”包作为图形设备,效果很好。
Plot 在普通的 JFrame 中打印,甚至可以通过子类化它来扩展。
I think the normal R graphics device works only if you use it in the R GUI, not if started from java or the commandline.
So I used the package "JavaGD" as a graphics device and this works fine.
the Plot is printed in a normal JFrame which can even be extended by subclassing it.