我一直在使用的后期R,rserve和ggplot.
在R控制台中执行此代码时,会直接呈现带有两个条形的图表.png(file ='Yash_GenderVsTotalAccountBalance.png',width = 400,height = 350,res = 72)ggplot(data = YashCustomersAccounts,aes(x = GENDER_DESC,y = ACCOUNT_BALANCE))+ geom_bar(stat ='identity')dev.关闭()
但是当我使用Rserve从JAVA调用相同的代码(涉及ggplot调用)时,它会创建一个空白的png.代码如下.
package RRnD;
import java.awt.*;
import org.rosuda.REngine.*;
import org.rosuda.REngine.Rserve.*;
public class PlottingGenderVsTotalAccountBalance {
public static void main(String[] args) throws RserveException {
try {
RConnection c = new RConnection(); // make a new local connection on default port (6311)
System.out.println("1. Connection created ----------------------------------------------------------------------");
System.out.println("Working directory = "+c.eval("getwd()").asString());
System.out.println("2. Working dir read ----------------------------------------------------------------------");
c.eval("YashCustomers <- read.csv('YashCustomer.csv', header=TRUE)");
c.eval("YashAccounts <- read.csv('YashAccount.csv', header=TRUE)");
c.eval("YashCustomersAccounts <- merge(YashCustomers,YashAccounts, by='CUSTOMER_ID')"); …Run Code Online (Sandbox Code Playgroud)