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
@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