1

I'm trying to reproduce some grid package examples, specifically those which involve the grid.cap function, to "capture" the current plot raster matrix. Examples here (Paul Murrell's article, Spanish flag example) and here.

But grid.cap will simply not work for me as is, unless I open a new window with dev.new()/dev.off():

# not working
plot(1:10)
cap <- grid::grid.cap()
is.null(cap)
[1] TRUE

# working
dev.new()
plot(1:10)
cap <- grid::grid.cap()
dev.off()
is.null(cap)
[1] FALSE
dim(cap)
[1] 672 672

I'm using a standard R 3.4.1 on Windows 7 (see sessionInfo()).

  • Why is this happening?
  • What can I do to fix this?
  • If I can't fix this are there alternative ways to "capture" a plot's raster matrix without actually popping it up in a window or better yet without actually plotting it, e.g. capturing a ggplot object?
> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

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

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

loaded via a namespace (and not attached):
[1] directlabels_2017.03.31 compiler_3.4.1          tools_3.4.1             yaml_2.1.14            
[5] grid_3.4.1              quadprog_1.5-5
Giora Simchoni
  • 3,487
  • 3
  • 34
  • 72

0 Answers0