我对Rstudio有一个奇怪的问题:如果一个脚本调用ggplot2函数来显示一个绘图,那么使用Source来运行脚本不会生成绘图.如果我用Ctrl+A
Select 整个脚本,然后是Run the current line or selection(Ctrl+Enter
),那么将显示does图.同样,在控制台中键入绘图命令会生成正确的输出.
例如:
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和R3.1.1.