Question

I want to generate a R boxplot by using rcaller with java. My code is :

try {
        RCaller caller = new RCaller();
        caller.setRExecutable("/usr/bin/R");
        caller.setGraphicsTheme(new DefaultTheme());

        RCode code = new RCode();
        code.clear();

        File file = code.startPlot();

        code.addRCode("boxplot((1:10),main=\"1-10\")");

        System.out.println(code.toString());
        code.endPlot();

        caller.setRCode(code);
        caller.runAndReturnResultOnline("boxplot(1:10),main=\"1-10\"");
        code.showPlot(file);

But it does not keep run on codecaller.runAndReturnResultOnline("boxplot(1:10),main=\"1-10\"");

i try to use code below ,that can plot a R plot.what differences between them ?

try {
        RCaller caller = new RCaller();
        caller.setRExecutable("/usr/bin/R");
        caller.setGraphicsTheme(new DefaultTheme());

        RCode code = new RCode();
        code.clear();

        double[] numbers = new double[] { 1, 4, 4, 5, 6, 10 };
        code.addDoubleArray("x", numbers);

        File file = code.startPlot();
        System.out.println(file.toString());

        code.addRCode("plot.ts(x)");
        System.out.println(code.toString());
        code.endPlot();

        caller.setRCode(code);
        caller.runAndReturnResultOnline("plot.ts(x)");
        code.showPlot(file);
Was it helpful?

Solution

Replace your line :

code.addRCode("boxplot((1:10),main=\"1-10\")");

By this :

code.addRCode("boxplot(c(1:10),main='1-10')");

Or as in the second example (the working one), you can give your x vector from java and replace this line:

caller.runAndReturnResultOnline("plot.ts(x)");

by

caller.runAndReturnResultOnline("boxplot(x)");

PS: I dont' have java to test.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top