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

发布于 2024-09-26 22:53:44 字数 993 浏览 4 评论 0原文

有人成功使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我乃一代侩神 2024-10-03 22:53:44

我认为普通的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文