问题
I have written an R function, that connect to database, fetch some records, obtain association rule of the object via arules
library and plot the rules using arulesViz
. I save the R function in an script file, named associationRule.R.
plotAssociationRule = function(){
library(arules)
library(RJDBC)
jdbcDriver <- JDBC(driverClass="oracle.jdbc.OracleDriver", classPath="lib/ojdbc6-11.2.0.2.0.jar")
jdbcConnection <- dbConnect(jdbcDriver, "jdbc:oracle:thin:@//172.16.1.133:1521/oradb", "hr_midhco", "HrMidhco1394")
KARKONAN_BASKET <- dbGetQuery(jdbcConnection, "SELECT * FROM BASKET_HR_NON_HOLDING_KARKONAN")
KARKONAN_BASKET_SUB <- subset(KARKONAN_BASKET, select= c ("ITEM_ERTEBAT","ITEM_ROSHD","ITEM_HOGHOGH","ITEM_MM","ITEM_MK","ITEM_TM","ITEM_VEJHE","ITEM_ANGIZEH","ITEM_TAHOD","ITEM_SOALAT"))
KARKONAN_BASKET_SUB$ITEM_ERTEBAT <- factor(KARKONAN_BASKET_SUB$ITEM_ERTEBAT)
KARKONAN_BASKET_SUB$ITEM_ROSHD <- factor(KARKONAN_BASKET_SUB$ITEM_ROSHD)
KARKONAN_BASKET_SUB$ITEM_HOGHOGH <- factor(KARKONAN_BASKET_SUB$ITEM_HOGHOGH)
KARKONAN_BASKET_SUB$ITEM_MM <- factor(KARKONAN_BASKET_SUB$ITEM_MM)
KARKONAN_BASKET_SUB$ITEM_TM <- factor(KARKONAN_BASKET_SUB$ITEM_TM)
KARKONAN_BASKET_SUB$ITEM_MK <- factor(KARKONAN_BASKET_SUB$ITEM_MK)
KARKONAN_BASKET_SUB$ITEM_VEJHE <- factor(KARKONAN_BASKET_SUB$ITEM_VEJHE)
KARKONAN_BASKET_SUB$ITEM_ANGIZEH <- factor(KARKONAN_BASKET_SUB$ITEM_ANGIZEH)
KARKONAN_BASKET_SUB$ITEM_TAHOD <- factor(KARKONAN_BASKET_SUB$ITEM_TAHOD)
KARKONAN_BASKET_SUB$ITEM_SOALAT <- factor(KARKONAN_BASKET_SUB$ITEM_SOALAT)
rules <- apriori(KARKONAN_BASKET_SUB,parameter=list(support=0.6, confidence=0.5))
inspect(rules)
library(arulesViz)
plot(rules, method="graph", control=list(type="items"))
return (rules)
}
I use Rserve() to call the function from java. the java code is simple
import java.io.IOException;
import org.rosuda.REngine.REXP;
import org.rosuda.REngine.REXPMismatchException;
import org.rosuda.REngine.Rserve.RConnection;
import org.rosuda.REngine.Rserve.RserveException;
/**
* Created by f.aliakbarian on 6/12/2016.
*/
public class test {
public static void main(String[] args) throws IOException, RserveException, REXPMismatchException {
System.out.println("executing R command!!!");
RConnection c = new RConnection();
System.out.println("Reading script...");
REXP eval = c.eval("source('C:/scripts/associationRule.R')");
REXP valueReturned = c.eval("plotAssociationRule()");
System.out.println(valueReturned);
}
}
when I run the program, the plot is shown with the title "graph for 10 rules", that means the code is executed correctly but the the window not responding. the message above the window is R graphics: Device 2 (active) not responding
I increased the memory of idea but nothing changes.
来源:https://stackoverflow.com/questions/37788072/plot-graphics-result-for-example-association-rules-via-aruleviz-from-java-code