-1
我想在java中使用從language.csv導入數據的r語言繪製圖形。我有問題,我的輸出是空白的。在NetBeans中,程序運行成功沒有錯誤,但是程序無法顯示,而在R studio中,圖形可以正常顯示。如何使用R語言在Java中繪製圖形(read.csv(file))
這是我的代碼中的R演播室:
//import file.csv
RealDataErq <- read.csv("C:.../erq_csv_comma.csv",header = TRUE)
//create garph by Request.By
RealDataErq_RequesterBy <- aggregate(RealDataErq$NUMBER, by=list(Status=RealDataErq$Request.By), FUN=sum)
//plot garph
plot(RealDataErq_RequesterBy)
這是我的代碼在NetBeans:
package rserveproject;
import java.io.File;
import java.io.IOException;
import javax.swing.ImageIcon;
import org.rosuda.REngine.REXP;
import org.rosuda.REngine.Rserve.RConnection;
import org.rosuda.REngine.Rserve.RserveException;
import rcaller.RCaller;
/**
*
*/
public class Graph2Erp {
public static void main(String a[]) throws IOException {
RConnection connection = null;
try {
RCaller caller = new RCaller();
caller.setRscriptExecutable("C:\\\\Program Files\\\\R\\\\R-3.3.1\\\\bin\\\\i386\\\\Rscript");
caller.cleanRCode();
connection = new RConnection();
REXP x;
// connection.eval("RealDataErq <- read.csv(file='C:\\\\Users\\\\.....\\\\Desktop\\\\erq_csv_comma.csv', sep=' ', colClasses=c(NA, NA, NA))");
connection.eval("RealDataErq <- read.csv('C:\\\\Users\\\\.....\\\\Desktop\\\\erq_csv_comma.csv',header = TRUE)");
connection.eval("RealDataErq_RequesterBy <- aggregate(RealDataErq$NUMBER, by=list(Status=RealDataErq$Request.By), FUN=sum)");
File file = caller.startPlot();
connection.eval("plot(RealDataErq_RequesterBy)");
caller.endPlot();
caller.runOnly();
ImageIcon ii = caller.getPlot(file);
caller.showPlot(file);
} catch (RserveException e) {
e.printStackTrace();
}
finally{
connection.close();
}
}
}
在NetBeans這是我的輸出:
這是我的文件。 csv: https://drive.google.com/drive/folders/0B3ynuWBsKXoHY2tSQVdQZU4tVlE?usp=sharing
我不會使用JavaGD。你有另一種解決方案嗎?
此我中的R工作室輸出:https://i.stack.imgur.com/PjSzu.png –