[R-SIG-Mac] Intermittent plotting failures on new Quartz window

Chris Black chris at ckblack.org
Wed Jun 1 19:17:06 CEST 2016


Thank you for looking into this. I think you did read it before — apparently I double-posted and one copy stayed in the moderation queue for a month! Sorry ‘bout that.

In any case, plot.new() seems like a reasonable way forward. If it helps anyone else I’m happy to investigate more off-list, but for my purposes I’ll call this fixed.

Thanks,
Chris

> On May 30, 2016, at 3:59 PM, Simon Urbanek <simon.urbanek at r-project.org> wrote:
> 
> I though I read this before - yes, it looks like a timing issue that has to do with OS X providing windows asynchronously, so the drawing space is not ready yet while R is already plotting so the plot is incomplete. R doesn't know that so it doesn't redraw unless you resize the plot or play the history (cmd-left/right) -- the fact that the history shows the full plot proves that this is not something on the R side (since the display list is complete), but rather the initial rendering doesn't have a window to draw into. I didn't find any API for Quartz to know when the window is actually ready. This only affects creating a new window and plotting into it before it's ready. Once the window is shown, everything works as expected - so you're probably better of using plot.new() first before you start creating the grobs.
> 
> Cheers,
> Simon
> 
> 
> On Apr 30, 2016, at 5:21 PM, Chris Black <black11 at igb.illinois.edu> wrote:
> 
>> Hi, all. I’m getting some puzzling, intermittent plot failures that seem to occur only when I’m in an interactive session, arranging plots with very different drawing speeds, and only when Quartz needs to open a new window before plotting. 
>> 
>> I posted a longer version of this at https://gist.github.com/infotroph/c68fc7a3f8594473361f87e2a348ddf9, but here’s a minimal example:
>> 
>> 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()
>> 
>> graphics.off()
>> pp=arrangeGrob(p1, p2)
>> grid.draw(pp)
>> 
>> Expected result: New graphics window containing a two-panel plot with diamonds on the top and cars on the bottom.
>> Observed result: Usually (~80% of the time?), a new graphics window with the top panel incompletely drawn (usually just axes with no points or panel grid), and the bottom panel as expected. Rarely (~20%?), the complete plot as expected. 
>> 
>> I can modulate the success rate somewhat by putting different lengths of Sys.sleep() in between the arrangeGrob and grid.draw calls, and I can guarantee success by calling dev.new() before arrangeGrob. See the above-linked Gist for details and for session info from a few other folks — thus far only the Quartz users can reproduce it, hence my starting with this list. 
>> 
>> Session info:
>> 
>> R for 3.2.4 GUI 1.67 Mavericks build (7152)
>> 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   
>> _______________________________________________
>> R-SIG-Mac mailing list
>> R-SIG-Mac at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
> 
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac



More information about the R-SIG-Mac mailing list