ggplot2 没有绘图,因为 ggsave 没有保存
我有一个使用 pyper 库的 python 脚本(通过管道连接到 R),并且我试图从 ggplot2 中获取一些输出。我尝试过“ggsave”方法和“device(...);” dev.off()' 方法,没有任何输出。
我必须使用 pyper,因为每个地方都使用 64 位(python 和 R),所以 rpy[2] 对我来说不是一个选择。
代码如下所示:
r("png(filename='test.png',width=720,height=540)") #comment if ggsave
r("p<-ggplot(DB,aes(X,Y,group=cfg))")
r("""p <- p + geom_path(aes(colour=factor(f1))) + scale_x_log10('X label') +
scale_y_continuous('Y label',breaks=myb,labels=myl) +
geom_point(data=subset(DB,pts==dot),aes(colour=factor(f1),size=factor(f2),
shape=factor(f3))) + labs(colour='l1',size='l2',shape='l3')""")
r("print(p)")
# r("ggsave(filename='test.png',width=10,height=7.5) #comment out if using png
r("dev.off()") # comment if using ggsave
在这两种情况下都不会创建文件。我已检查并确保数据库数据表有条目(1000s)。我可以尝试什么?
I have a python script using the pyper library (pipes to R), and I am trying to get some output out of ggplot2. I have tried both the 'ggsave' method and the 'device(...); dev.off()' methods and nothing is output.
I have to use pyper because of using 64 bits everywere (python and R), so rpy[2] isn't an option for me.
The code looks like the following:
r("png(filename='test.png',width=720,height=540)") #comment if ggsave
r("p<-ggplot(DB,aes(X,Y,group=cfg))")
r("""p <- p + geom_path(aes(colour=factor(f1))) + scale_x_log10('X label') +
scale_y_continuous('Y label',breaks=myb,labels=myl) +
geom_point(data=subset(DB,pts==dot),aes(colour=factor(f1),size=factor(f2),
shape=factor(f3))) + labs(colour='l1',size='l2',shape='l3')""")
r("print(p)")
# r("ggsave(filename='test.png',width=10,height=7.5) #comment out if using png
r("dev.off()") # comment if using ggsave
No file is created in either case. I have checked to make certain that the DB data table has entries (1000s). What could I try?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以这一切都证明是库和环境变量的问题。某些加载的库(例如 ggplot2)不会加载所有依赖项(例如摘要库)。此错误仅发生在代码的“print(p)”部分。
此外,x64 库位置也存在差异,需要正确设置。确保 R_HOME 和 R_LIBS 变量与您的配置匹配。
Pyper 似乎没有告诉我库没有加载,它只是继续运行,所以 qplot 最初没有在 R 中加载。将其加载到正确的位置后,您需要确保始终使用您的用户帐户或始终使用管理员帐户(或者您在 R_LIBS 中有多个路径,但我没有尝试这样做)。
只要加载了库,qplot 和 ggsave 就可以正常工作。
感谢所有热心人士和调试指导!
So this all turns out to be an issue with libraries and environment variables. Some of the loaded libraries, like ggplot2, don't load all dependencies, like the digest library. This error only occurs on the "print(p)" portion of the code.
In addition, there are differences in the x64 library locations that need to be set correctly. Make certain that the R_HOME and R_LIBS variables match your configuration.
Pyper didn't appear to tell me that libraries didn't load, it just kept going, so qplot wasn't loading in R initially. After getting that loaded in the right place, you need to make certain you are using either your user account always or the administrator account always (or you have have multiple paths in R_LIBS, but I didn't try that).
qplot and ggsave worked fine, so long as the libraries were loaded.
Thanks for all the dedicated folks and the directions for debug!