【发布时间】:2014-12-25 22:54:13
【问题描述】:
我对 Rstudio 有一个奇怪的问题:如果脚本调用 ggplot2 函数来显示绘图,那么使用 Source 运行脚本不会生成绘图。如果我用Ctrl+A 选择整个脚本,然后运行当前行或选择 (Ctrl+Enter),那么图会显示。同样,在控制台中输入绘图命令会产生正确的输出。
例如:
library(ggplot2)
p = ggplot(mtcars, aes(wt, mpg))
p + geom_point()
只有粘贴到控制台时才会产生输出,而不是来源。
对此还有其他问题,但都没有帮助:
- ggplot2 ggsave function causes graphics device to not display plots 谎称该问题已在较新版本中得到修复,但事实并非如此。
-
RStudio - ggplot not saving first plot when printing and saving multiple plots in a script 已作为重复项关闭,但它不仅不是重复项,而且
dev.off()解决方法也不起作用(“Error in dev.off() : cannot shut down device 1 (the null device)”)
如何在获取脚本时让 Rstudio 显示绘图?我正在使用 Rstudio 0.98.1062 和 R 3.1.1。
【问题讨论】: