The ggplot2 ggsave function causes the graphics device to not display graphics

I updated my ggplot2 library and now I have a problem when after the ggsave call the graphics device no longer displays the graph. I cannot solve the problem because I cannot export the graphs as needed. Please, help.

A search on the Internet revealed some problems with dpi mismatch, but setting or changing dpi does not have any effect. This problem seems to have started after updating the ggplot2 library.

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 starting, the output is empty and the graphics device no longer displays a graph. Any subsequent graphics are not displayed on the graphics device.

After running dev.off (), the new graphs are displayed in order until ggsave is called again.

sessionInfo () reports versions of R and the library as:

 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 also occurs in 2.15.0 and 2.15.3 of R.

EDIT: code changed, so data will be loaded using sep = ',' and not as spaces

ADDITIONAL: further testing shows that it may actually be an error with RStudio and how it displays the graphics device after ggsave, and not R. Running the above script in RGui does not reproduce the problem only in RStudio V0.97.336 + V0.97.449 .

+6
r ggplot2
May 9 '13 at 23:39
source share
1 answer

There seems to be a problem with RStudio. This question is described here and here .

The workaround is to install RStudio V0.97.311 or make sure that you run ggplot and ggsave separately (i.e., you do not select and run together in the + enter control block).

+5
May 10 '13 at 18:17
source share



All Articles