繁体   English   中英

Rscript ggplot-ggsave问题

[英]Rscript ggplot - ggsave problem

我正在使用以下代码绘制图形并将其打印为PDF:

ggplot(agg_data_cl, aes( as.Date(date), avg_entries, color = classification ) ) +
  geom_point()

ggsave(file = "output.pdf")

当我在TextMate中执行脚本时,这可以正常工作。

但是,当我通过RScript从命令行调用它时,出现以下错误:

Error in all.vars(as.formula(.$facets)) : 
  could not find function "as.formula"
Calls: print ... <Anonymous> -> <Anonymous> -> <Anonymous> -> all.vars
Execution halted

我在RScrpipt文件中使用以下标头:

#! /usr/local/bin/Rscript --vanilla --default-packages=utils

任何想法可能是什么问题?

这是我的命令行会话信息:

R version 2.13.1 (2011-07-08)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] C/UTF-8/C/C/C/C

attached base packages:
[1] grid  utils base 

other attached packages:
[1] ggplot2_0.8.9 proto_0.3-9.2 reshape_0.8.4 plyr_1.5.2   

loaded via a namespace (and not attached):
[1] grDevices_2.13.1 graphics_2.13.1  stats_2.13.1

在textmate中,sessionInfo()给了我更多附加的基本包:

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods  
[8] base

我不知道为什么会这样。

问题是调用Rscript时的--vanilla选项。

这是Rscript --help关于其选项的说明

--save              Do save workspace at the end of the session
--no-environ        Don't read the site and user environment files
--no-site-file      Don't read the site-wide Rprofile
--no-init-file      Don't read the user R profile
--restore           Do restore previously saved objects at startup
--vanilla           Combine --no-save, --no-restore, --no-site-file
                    --no-init-file and --no-environ

..和--vanilla基本上意味着Rscript应该在开始执行R命令之前忘记所有内容,包括一些已安装的软件包。

两件事情:

1)确保您具有库(ggplot2)_in_your_script_

2)确保对ggplot对象进行print()或plot()。 (请参阅FAQ 7.22)在这种情况下,这可能不是问题,因为您可以节省gg,但这是Rscript会话中的点阵或ggplot图形的常见问题。

as.formula在stats软件包中。 不知道为什么不加载它,但是看看在脚本开始处手动包括library(stats)是否可以解决此问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM