Skip to content

Instantly share code, notes, and snippets.

@infotroph
Created April 25, 2016 20:36
Show Gist options
  • Save infotroph/c68fc7a3f8594473361f87e2a348ddf9 to your computer and use it in GitHub Desktop.
Save infotroph/c68fc7a3f8594473361f87e2a348ddf9 to your computer and use it in GitHub Desktop.
# Demo of intermittent plotting failures.
# Apparent requirements:
# * Interactive session (I'm in R.app using Quartz graphics)
# * Arranging multiple figures using gridExtra::arrangeGrob
# * Very different figure complexities
# (i.e one plot big enough to have a rendering lag, one that renders much faster.)
# * No graphics device open at beginning of arrangeGrob call
# Gentle reader, can you reproduce this on your machine?
# Can you help me identify where the problem is?
set.seed(34565)
library(ggplot2)
library(gridExtra)
library(grid)
p1 = ggplot(diamonds, aes(x, price))+geom_point()
p2 = ggplot(mtcars, aes(wt, mpg))+geom_point()
# Examples that usually fail:
# grid.draw exits with no error, but p1 is only partially drawn
graphics.off()
pp=arrangeGrob(p1, p2)
grid.draw(pp)
graphics.off()
pp=arrangeGrob(p1, p2)
Sys.sleep(1e-3)
grid.draw(pp)
# Usually succeeds
graphics.off()
pp=arrangeGrob(p1, p2)
Sys.sleep(1)
grid.draw(pp)
# Always succeeds
dev.new()
pp=arrangeGrob(p1, p2)
grid.draw(pp)
# "Always" succeeds (thought I saw it fail a few times early in debugging, but now can't reproduce)
graphics.off()
grid.arrange(p1, p2)
sessionInfo()
# R version 3.2.4 (2016-03-10)
# Platform: x86_64-apple-darwin13.4.0 (64-bit)
# Running under: OS X 10.11.3 (El Capitan)
#
# locale:
# [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#
# attached base packages:
# [1] grid stats graphics grDevices utils datasets methods
# [8] base
#
# other attached packages:
# [1] gridExtra_2.2.1 ggplot2_2.1.0
#
# loaded via a namespace (and not attached):
# [1] labeling_0.3 colorspace_1.2-6 scales_0.4.0 plyr_1.8.3
# [5] tools_3.2.4 gtable_0.2.0 Rcpp_0.12.4 munsell_0.4.3
@karawoo
Copy link

karawoo commented Apr 29, 2016

My results from trying to reproduce:

@infotroph Weeird. In the order of your examples I got: fail, succeed, fail, succeed, succeed. Tried #2 two more times: fail, then succeed.

— Kara Woo (@kara_woo) April 29, 2016
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
sessionInfo()
R version 3.2.4 (2016-03-10)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.4 (El Capitan)

locale:
[1] C

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

other attached packages:
[1] gridExtra_2.2.1 ggplot2_2.1.0  

loaded via a namespace (and not attached):
[1] labeling_0.3     colorspace_1.2-6 scales_0.4.0     plyr_1.8.3      
[5] gtable_0.2.0     Rcpp_0.12.4      munsell_0.4.3   

@bhive01
Copy link

bhive01 commented Apr 29, 2016

I get:
Fail, Fail, Succeed, Succeed, Succeed.

Tried each one 3x.

devtools::session_info()
Session info -------------------------------------------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.2.4 (2016-03-10)
 system   x86_64, darwin13.4.0        
 ui       AQUA                        
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       America/Los_Angeles         
 date     2016-04-29                  

Packages -----------------------------------------------------------------------------------------------------------------------------------------------------
 package    * version     date       source                          
 colorspace   1.2-6       2015-03-11 CRAN (R 3.2.0)                  
 devtools     1.11.1.9000 2016-04-29 Github (hadley/devtools@fe27701)
 digest       0.6.9       2016-01-08 CRAN (R 3.2.3)                  
 ggplot2    * 2.1.0       2016-03-01 CRAN (R 3.2.4)                  
 gridExtra  * 2.2.1       2016-02-29 CRAN (R 3.2.4)                  
 gtable       0.2.0.9000  2016-02-26 Github (hadley/gtable@0ed36a4)  
 labeling     0.3         2014-08-23 CRAN (R 3.2.0)                  
 memoise      1.0.0       2016-01-29 CRAN (R 3.2.3)                  
 munsell      0.4.3       2016-02-13 CRAN (R 3.2.3)                  
 plyr         1.8.3.9000  2015-10-16 Github (hadley/plyr@9d8294e)    
 Rcpp         0.12.4      2016-03-26 CRAN (R 3.2.4)                  
 scales       0.4.0.9000  2016-02-26 Github (hadley/scales@646b6a4)  
 withr        1.0.1       2016-02-04 CRAN (R 3.2.3)                  

@dschwilk
Copy link

I cannot reproduce. All succeed.

> sessionInfo()
R version 3.2.5 (2016-04-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 15.10

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] gridExtra_2.2.1 ggplot2_2.1.0  

loaded via a namespace (and not attached):
[1] labeling_0.3     colorspace_1.2-6 scales_0.4.0     plyr_1.8.3      
[5] gtable_0.2.0     Rcpp_0.12.3      munsell_0.4.3   

@bhive01
Copy link

bhive01 commented Apr 29, 2016

I updated to 3.2.5 and updated packages and it's the same for me. FFSSS.

If it's ok on Linux, I postulate that the other thing @karawoo, @infotroph and myself have in common is OS X. Could be a quartz issue of some sort. I have no idea who could help us figure this out though. Perhaps R-SIG-Mac?

The good news is that your example is at least mostly reproducible on OS X.

devtools::session_info()
Session info -------------------------------------------------------------------------------------------------------------------------------------------------
 setting  value                                      
 version  R version 3.2.5 Patched (2016-04-18 r70561)
 system   x86_64, darwin13.4.0                       
 ui       AQUA                                       
 language (EN)                                       
 collate  en_US.UTF-8                                
 tz       America/Los_Angeles                        
 date     2016-04-29                                 

Packages -----------------------------------------------------------------------------------------------------------------------------------------------------
 package    * version     date       source                          
 colorspace   1.2-6       2015-03-11 CRAN (R 3.2.0)                  
 devtools     1.11.1.9000 2016-04-29 Github (hadley/devtools@fe27701)
 digest       0.6.9       2016-01-08 CRAN (R 3.2.3)                  
 ggplot2    * 2.1.0       2016-03-01 CRAN (R 3.2.4)                  
 gridExtra  * 2.2.1       2016-02-29 CRAN (R 3.2.4)                  
 gtable       0.2.0.9000  2016-02-26 Github (hadley/gtable@0ed36a4)  
 labeling     0.3         2014-08-23 CRAN (R 3.2.0)                  
 memoise      1.0.0       2016-01-29 CRAN (R 3.2.3)                  
 munsell      0.4.3       2016-02-13 CRAN (R 3.2.3)                  
 plyr         1.8.3.9000  2015-10-16 Github (hadley/plyr@9d8294e)    
 Rcpp         0.12.4      2016-03-26 CRAN (R 3.2.4)                  
 scales       0.4.0.9000  2016-02-26 Github (hadley/scales@646b6a4)  
 withr        1.0.1       2016-02-04 CRAN (R 3.2.3)    

@tdsmith
Copy link

tdsmith commented Apr 29, 2016

In R.app, I see 1 and 2 fail; the rest succeed.

In RStudio with the RStudio graphics device, all plots succeed, but if I call options("device"="quartz") I can reproduce; 1 and 2 sometimes succeed, 3 and 4 usually succeed, 5 succeeds.

Session info --------------------------------------------------------------------------------------------------------------
 setting  value                                      
 version  R version 3.2.4 Revised (2016-03-16 r70336)
 system   x86_64, darwin15.3.0                       
 ui       RStudio (0.99.878)                         
 language (EN)                                       
 collate  en_US.UTF-8                                
 tz       America/Los_Angeles                        
 date     2016-04-29                                 

Packages ------------------------------------------------------------------------------------------------------------------
 package    * version  date       source                            
 colorspace   1.2-6    2015-03-11 CRAN (R 3.2.0)                    
 devtools     1.10.0   2016-01-23 CRAN (R 3.2.3)                    
 digest       0.6.9    2016-01-08 CRAN (R 3.2.3)                    
 ggplot2    * 2.1.0    2016-03-01 CRAN (R 3.2.3)                    
 gridExtra  * 2.2.1    2016-02-29 CRAN (R 3.2.4)                    
 gtable       0.2.0    2016-02-26 CRAN (R 3.2.3)                    
 labeling     0.3      2014-08-23 CRAN (R 3.2.0)                    
 memoise      1.0.0    2016-01-29 CRAN (R 3.2.3)                    
 munsell      0.4.3    2016-02-13 CRAN (R 3.2.3)                    
 plyr         1.8.3    2015-06-12 CRAN (R 3.2.1)                    
 Rcpp         0.12.4   2016-03-26 CRAN (R 3.2.4)                    
 rsconnect    0.4.1.11 2016-02-19 Github (rstudio/rsconnect@2419667)
 scales       0.4.0    2016-02-26 CRAN (R 3.2.3)

@infotroph
Copy link
Author

Happy to hear more reports, but I'm leaning towards calling this a Quartz issue and will take it to R-SIG-Mac shortly. Thanks, all!

@bhive01
Copy link

bhive01 commented May 5, 2016

Saw email on R-Sig-Mac.
Updated to R 3.3.0 this morning and it still happening. So AFAIK whatever is causing it hasn't been fixed.

devtools::session_info()
Session info ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.3.0 (2016-05-03)
 system   x86_64, darwin13.4.0        
 ui       AQUA                        
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       America/Los_Angeles         
 date     2016-05-05                  

Packages --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 package    * version     date       source                          
 assertthat   0.1         2013-12-06 CRAN (R 3.3.0)                  
 colorspace   1.2-6       2015-03-11 CRAN (R 3.3.0)                  
 curl         0.9.7       2016-04-10 CRAN (R 3.3.0)                  
 DBI          0.4         2016-05-02 CRAN (R 3.3.0)                  
 devtools     1.11.1.9000 2016-05-05 Github (hadley/devtools@c19c6f6)
 digest       0.6.9       2016-01-08 CRAN (R 3.3.0)                  
 dplyr      * 0.4.3.9001  2016-05-05 Github (hadley/dplyr@3074cf7)   
 ggplot2    * 2.1.0       2016-05-05 Github (hadley/ggplot2@59c503b) 
 git2r        0.14.0      2016-03-13 CRAN (R 3.3.0)                  
 gridExtra  * 2.2.1       2016-02-29 cran (@2.2.1)                   
 gtable       0.2.0       2016-02-26 CRAN (R 3.3.0)                  
 httr         1.1.0       2016-01-28 CRAN (R 3.3.0)                  
 knitr        1.12.3      2016-01-22 CRAN (R 3.3.0)                  
 labeling     0.3         2014-08-23 CRAN (R 3.3.0)                  
 magrittr     1.5         2014-11-22 CRAN (R 3.3.0)                  
 memoise      1.0.0       2016-01-29 CRAN (R 3.3.0)                  
 munsell      0.4.3       2016-02-13 CRAN (R 3.3.0)                  
 plyr         1.8.3       2015-06-12 CRAN (R 3.3.0)                  
 purrr      * 0.2.1       2016-02-13 CRAN (R 3.3.0)                  
 R6           2.1.2       2016-01-26 CRAN (R 3.3.0)                  
 Rcpp         0.12.4      2016-03-26 CRAN (R 3.3.0)                  
 rstudioapi   0.5         2016-01-24 CRAN (R 3.3.0)                  
 scales       0.4.0       2016-02-26 CRAN (R 3.3.0)                  
 tibble       1.0-1       2016-05-05 Github (hadley/tibble@cb38672)  
 withr        1.0.1       2016-02-04 CRAN (R 3.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment