【问题标题】:calling plots from R into Java application从 R 调用绘图到 Java 应用程序
【发布时间】:2011-04-23 07:06:53
【问题描述】:

是否有人成功地使用了 JRI 和 rJava?我想在我的 Java 应用程序中放入一些用 R 制作的图表,但没有成功。任何人都可以提供工作示例。这是我找到的,但它不起作用。

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)");
    }
    
}

【问题讨论】:

    标签: java r plot rjava jri


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-29
      • 2017-09-07
      • 1970-01-01
      • 2018-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多