gpt4 book ai didi

java - 将绘图从 R 调用到 Java 应用程序中

转载 作者:搜寻专家 更新时间:2023-11-01 03:29:41 26 4
gpt4 key购买 nike

有没有成功使用 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)");
}

}

最佳答案

我认为普通的 R 图形设备只有在 R GUI 中使用它时才能工作,如果从 java 或命令行启动则不行。所以我使用包“JavaGD”作为图形设备,效果很好。Plot 打印在一个普通的 JFrame 中,甚至可以通过子类化它来扩展。

关于java - 将绘图从 R 调用到 Java 应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3897648/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com