导出绘制的变量显示空白图像 [英] exporting plotted variable shows blank image

查看:57
本文介绍了导出绘制的变量显示空白图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 JRI 进行 Java 和 R 集成.请找到下面的脚本

I am doing java and R integration using JRI. Please find below script

            String path = "C:\\Users\\hrpatel\\Desktop\\CSVs\\DataNVOCT.csv";
            rengine.eval("library(tseries)");
            rengine.eval(String.format("mydata <- read.csv('%s')",path.replace('\\', '/')));
            String exportFilePath= "C:\\Users\\hrpatel\\Desktop\\CSVs\\arima3.jpg";
            rengine.eval("Y <- NewVisits");
            rengine.eval("t <- Day.Index");
            rengine.eval("summary(Y)");
            rengine.eval("adf.test(Y, alternative='stationary')");
            rengine.eval("adf.test(Y, alternative='stationary', k=0)");
            rengine.eval("acf(Y)");
            rengine.eval("pacf(Y)");
            rengine.eval("mydata.arima101 <- arima(Y,order=c(1,0,1))");
            rengine.eval("mydata.pred1 <- predict(mydata.arima101, n.ahead=1000)");
            rengine.eval(String.format("jpeg('%s')",exportFilePath.replace('\\', '/')));
            rengine.eval("plot(t,Y)");
            rengine.eval("lines(mydata.pred1$pred, col='blue',size=10)");
            rengine.eval("lines(mydata.pred1$pred+1*mydata.pred1$se, col='red')");
            rengine.eval("lines(mydata.pred1$pred-1*mydata.pred1$se, col='red')");
            rengine.eval("dev.off()");

在上面的代码库中,当我尝试 plot(t,Y) 或 plot(Y) 时.它导出一个空白图像,而在 plot(mydata) 的情况下它是工作文件.

In above codebase when i tried plot(t,Y) or plot(Y). it export a blank image, while in case of plot(mydata) it is working file.

当我在 R 中运行上面的代码时,还有一件事会创建图像(使用 JRI 会显示空白图像).

One more thing when i run above code in R it creates the image(using JRI it shows blank image).

我花了 1 天时间来解决这个问题,但我没有找到任何解决方案.

I have spend 1 day to solve this but i dont found any solution.

如果您有其他选择,请提出建议.

Please suggest if you have any alternatives.

需要你的帮助.

提前致谢

推荐答案

如果我理解正确,你有一个名为 mydata 的数据集,它有两列,NewVisits, 和 Day.Index,在这种情况下你需要改变:

if i understand correctly, you have a data set named mydata, that has two columns, NewVisits, and Day.Index, in that case you need to change:

rengine.eval("Y <- NewVisits");

rengine.eval("Y <- mydata$NewVisits");

rengine.eval("t <- Day.Index");

rengine.eval("t <- mydata$Day.Index");

这也解释了为什么 plot(mydata) 对您有用 - 因为 R 可以识别它.

This also explains why plot(mydata) works for you - because R recognizes it.

如果这不是解决方案,那么我看不到您在何处阅读 NewVisitsDay.Index 来自

if this isn't the solution, then i cant see where you are reading NewVisits and Day.Index from

顺便说一句,我强烈建议使用 ggplot

BTW i stongly recommend to plot using the ggplot package

这篇关于导出绘制的变量显示空白图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆