简体   繁体   English

ggplot2 ggsave函数导致图形设备不显示绘图

[英]ggplot2 ggsave function causes graphics device to not display plots

I've updated my ggplot2 library and I am now having a problem where after calling ggsave, the graphics device no longer displays the plot. 我已经更新了ggplot2库,现在遇到了一个问题,在调用ggsave之后,图形设备不再显示绘图。 I'm unable to resolve the issue meaning I cannot export the plots as needed. 我无法解决该问题,这意味着我无法根据需要导出地块。 Please help. 请帮忙。

Searching the web has revealed some mention of problems with dpi mismatches, but setting or changing the dpi appears to have no effect. 在网络上搜索时发现了一些有关dpi不匹配的问题,但是设置或更改dpi似乎没有效果。 This problem appears to have begun after doing an update of the ggplot2 library. 更新ggplot2库后,似乎已经开始出现此问题。

The following code reproduces the problem: 下面的代码重现该问题:

library(ggplot2);
df <- read.table(textConnection('value,value1 
 1,1 
 2,2
 3,3 '),header=TRUE,sep=',');

ggplot(df,aes(x=value,y=value1)) +   geom_point();

setwd('c:/temp'); 
ggsave('test.png');

After running, the output is blank, and the graphics device no longer displays the plot. 运行后,输出为空白,并且图形设备不再显示绘图。 Any subsequent plots are not displayed on the graphics device. 任何后续绘图都不会显示在图形设备上。

After running dev.off(), new plots are displayed okay, until ggsave is called again. 运行dev.off()后,新图将显示正常,直到再次调用ggsave。

sessionInfo() reports the versions of R and libraries as: sessionInfo()将R和库的版本报告为:

R version 3.0.0 (2013-04-03)
Platform: i386-w64-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_New Zealand.1252  LC_CTYPE=English_New Zealand.1252   
[3] LC_MONETARY=English_New Zealand.1252 LC_NUMERIC=C                        
[5] LC_TIME=English_New Zealand.1252    

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

other attached packages:
[1] plyr_1.8        ggplot2_0.9.3.1 RODBC_1.3-6    

loaded via a namespace (and not attached):
 [1] colorspace_1.2-2   dichromat_2.0-0    digest_0.6.3       grid_3.0.0         gtable_0.1.2      
 [6] labeling_0.1       MASS_7.3-26        munsell_0.4        proto_0.3-10       RColorBrewer_1.0-5
[11] reshape2_1.2.2     scales_0.2.3       stringr_0.6.2      tools_3.0.0   

The problem occurs in 2.15.0 and 2.15.3 of R also. R的2.15.0和2.15.3中也会出现此问题。

EDIT: changed code so data would load using sep=',' rather than whitespace 编辑:更改代码,以便数据将使用sep =','而不是空格加载

ADDITION: further testing reveals that this may in fact be a bug with RStudio and how it is displaying the graphics device after ggsave, rather than R itself. 另外:进一步的测试表明,这实际上可能是RStudio的错误以及ggsave之后显示图形设备的方式,而不是R本身。 Running the above script in RGui does not reproduce the problem, only in RStudio V0.97.336 + V0.97.449. 仅在RStudio V0.97.336 + V0.97.449中,在RGui中运行上述脚本不会重现该问题。

Seems to be an issue with RStudio. 似乎与RStudio有关。 The issue is described here and here . 问题在这里这里描述。

The workaround is to install RStudio V0.97.311, or ensure that you execute the ggplot and ggsave lines separately (ie don't select and run together in a block with control+enter). 解决方法是安装RStudio V0.97.311,或确保分别执行ggplot和ggsave行(即,不要在使用control + enter的块中选择并一起运行)。

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

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