簡體   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