Hello,
I have create a desktop application in Java using Swing. I would like to generate a heatmap graphic to show it in my app as an image so I installed rJAva and through JRI it connects to R.
I wrote my R script in R for generating and saving to hard disk my ggplot2 heatmap graphic. So far so good, Java connects with R perfectly in the java side. In hte other side, R creates the image perfectly in Rstudio.
The problem exists when I connect from Java (through rJAva/JRI libraries) to R, to generate the ggplot2 graphics. It only generates a blank png. If it were a plot graphic instead of a ggplot2 graphic it wouldn´t have any problem.
My Java code which connects to R:
File mapa = new File("D:\\trading_tools\\javaBBB\\BBBproject\\files\\mapas\\cosa.png");
if(!mapa.exists()){
Rengine re=new Rengine (new String []{"--vanilla"}, false, null);
if (!re.waitForR()) {
System.out.println ("Cannot load R");
return;
}
writeCSV(); //function which wrotes 'test2csv.csv' in hard disk
re.eval("require(ggplot2);require(XML);require(rjson)");
re.eval("csv<-read.csv('D:/trading_tools/javaBBB/BBBproject/files/mapas/test2csv.csv',head=T,sep=';',dec='.',colClasses=rep('numeric', 24))");
re.eval("png(filename='D:/trading_tools/javaBBB/BBBproject/files/mapas/cosa.png', width = 400, height = 400)");
re.eval("g<-ggplot(csv[1:nrow(csv),], aes(x=sl,y=tp)) + geom_tile(aes(fill=CA))");
re.eval("dev.off()");
re.end();
}
I read in some webs that ggplot2 doesn´t generate the graphics out of R.
Can sombebody help me please? Any workaround or different option?
I thought about converting the project in a web application and then use Rserve but I am afraid of doing all the work to finally have the same issue in Rserve.
Does anybody have experience in this issue?
Any suggestion or help will be appreciatted!
Thanks in advance and best regards.