[R] saving contour() plot info

Duncan Murdoch murdoch.duncan at gmail.com
Tue Jul 3 16:53:54 CEST 2012

On 03/07/2012 10:36 AM, Robert Douglas Kinley wrote:
> { I think this message got rejected at the 1st attempt - trying again}
> R 2.15.1 , windows XP
> I have a  very non-stationary  bivariate  time-series - say  {xt,yt}  t=1 ... lots.
> I want to do a bivariate density contour-plot of the whole series and then  step
> through the series 1 second at a time plotting that second's  {x,y} subset on top of the contour
> plot and losing the previous second's subset so that the effect enables you to see
> an 'animation' of how the series 'travels' through  different parts of the joint density  as time passes.
> The only way I've found to do this is to repeatedly call contour() before plotting  each
> seconds-worth of data ... this works, but because of the time taken to do the  contour()
> calculations in each step of the loop , it has an unpleasant flashing appearance.

Generally the way to get rid of the flashing is to use dev.hold() while 
plotting, then dev.flush() when done.  This isn't supported on all 
graphics devices.
> Is it possible to run contour() just once and save the contour- plotting info, so that in each
> step of the loop I only have do the actual plotting of the contours?

It is possible to save the contour information.  See ?contourLines. This 
doesn't save everything (e.g. the labelling), but it might be enough for 

You could also try using recordPlot() after plotting the contours, then 
replayPlot() when you want to reproduce them.

Duncan Murdoch

> Or any other way of achieving the desired outcome.
> Grateful for any guidance      ...     Bob Kinley
> 	[[alternative HTML version deleted]]
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list