calling ggplot2 through rJava on Ubuntu20

18 Views Asked by At

We are facing a problem while running ggplot through rJava.

The problem occurs only if the geom_line() parameter is used with ggplot2.

The code runs properly and produces the graph for the first iteration, but it fails in the second iteration and the java application is terminated.

This problem is faced while using R version 4.3.1 on Ubuntu 20 and java version 17.

This problem does not occur and the code runs fine on Ubuntu 18

import org.rosuda.JRI.REXP;
import org.rosuda.JRI.Rengine;
public class Sample {
public static void main(String[] args) throws InterruptedException {
    Rengine engine=new Rengine (new String [] {"--vanilla"}, false, null);
    for (int i = 0; i < 1; i ++) {
        System.gc();
        engine.eval("x<-c(1:10)");
        engine.eval("y<-c(1:10)");
        engine.eval("xy<-data.frame(x,y)");
        engine.eval("library(ggplot2)");
        engine.eval("z<-ggplot(xy, aes(x, y))+geom_line()");
        engine.eval("print(z)");
        System.gc();
        System.out.println("Done");
      }
   }
}
0

There are 0 best solutions below