[R] Equivalent of Hold On MatLab Command

Richard.Cotton at hsl.gov.uk Richard.Cotton at hsl.gov.uk
Fri Jan 30 15:05:26 CET 2009


> Does R have a graphic command equivalent of MatLab Hold On ?
> I am trying to sabve on a pdf file a composite drawing. I first 
> declare the canvas size, then I define the layout, finally I 
> generate the 4 plots according to layout order. Eventually I close 
> the pdf file (dev.off()).
> The resulting PDF file contains 2 pages. The first one shows only 
> the layout. The second one shows the whole
> composite drawing.
> MatLab has the command Hold On to work around similar 
> synchronization problems.
> Does R have have an equivalent command ?

If you are using base graphics (i.e. not lattice/ grid graphics), then you 
can mimic MATLAB's hold on feature by using the points/lines/polygons 
functions to add additional details to your plots without starting a new 
plot.  In the case of a multiplot layout, you can use par(mfg=...) to pick 
which plot you add things to.

#open the pdf device
pdf("test.pdf")

#setup the layout
par(mfrow=c(2,2))

#plot at each location
for(i in 1:4) plot(runif(1:10))

#return to the first plot
par(mfg=c(1,1))

#add a line to this plot (without replacing anything)
lines(seq(0.1,1,0.1))

#close the device to complete the plot
dev.off()

If you have an extra page in you PDF file, it's probably because you've 
called plot.new() somewhere where you didn't mean to (either explicitly or 
implicitly).  Without a reproducible example, it's hard to help further.

Regards,
Richie.

Mathematical Sciences Unit
HSL



------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}




More information about the R-help mailing list