0

Two methods of storing plot objects in list or a name string are mentioned on this page Generating names iteratively in R for storing plots . But both do not seem to work on my system.

> plist = list()
> plist[[1]] = plot(1:30)
> 
> plist
list()
> 
> plist[[1]]
Error in plist[[1]] : subscript out of bounds

Second method:

> assign('pp', plot(1:25))
> 
> pp
NULL

I am using:

> R.version
               _                           
platform       i486-pc-linux-gnu           
arch           i486                        
os             linux-gnu                   
system         i486, linux-gnu             
status                                     
major          3                           
minor          2.0                         
year           2015                        
month          04                          
day            16                          
svn rev        68180                       
language       R                           
version.string R version 3.2.0 (2015-04-16)
nickname       Full of Ingredients         

Where is the problem?

Community
  • 1
  • 1
rnso
  • 23,686
  • 25
  • 112
  • 234
  • 2
    The base graphics plotting functions (ie `plot()`) do not return objects. That would only work for lattice (eg `xyplot()`) or ggplot objects (er `qplot()`). The accepted answer to that question is misleading. – MrFlick May 10 '15 at 03:34

1 Answers1

3

Use recordPlot and replayPlot:

plot(BOD)
plt <- recordPlot()
plot(0)
replayPlot(plt)
G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341