1

I used following code to calculating prediction in R using Java that code work fine it shows me output but, I want draw plot using same code on my predicted output code was given below

import org.rosuda.REngine.Rserve.RConnection;
public class demo{
public static void main(String args[]){
    try{
         System.out.println("INFO: Trying to connect to R ");
         RConnection c = new RConnection();
         c.eval("library('RMongo')");
         c.eval(" db <- mongoDbConnect('dbname', '127.0.0.1', '27017')");
         c.eval("query <- dbGetQuery(db,'collection_name','{\"hostId\" : \"300.3.3.3\"}')");
         c.eval("date <- query$Date");
         c.eval("cpu <- query$cpuUtilization");
         c.eval("memory <- query$memory");
         c.eval("df <- data.frame(date=1377843220)");
         c.eval("res <- lm(cbind(memory,cpu)~ date -1 )");
         int[] d= c.eval("predict(res,df)").asIntegers();
         for (Integer td : d) {
             System.out.println(td);
            }
         c.close();
        }
    catch(Exception e){
     System.out.println("ERROR: In Connection to R ");
     System.out.println("The Exception is "+ e.getMessage());
     e.printStackTrace();
     }
}
}

So any one knows how to draw plot using R in java code ?

1 Answer 1

2

Use a JFrame with a JGDPanel from JavaGD and plot something via JRI. Look into JGD: http://cran.r-project.org/web/packages/JavaGD/JavaGD.pdf Look into JRI: http://rosuda.org/JRI/

Another alternative is using R to generate the data you want and using native Java graphics libraries.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.