[R] zoom graphics

Barry Rowlingson B.Rowlingson at lancaster.ac.uk
Wed Mar 3 11:32:36 CET 2004


solares at unsl.edu.ar wrote:
> Hi, i don't understand how i cant zoom in and zoom out a graphics (plots)
> exist a package for that? Thanks Ruben
> 

  I dont think you can do it quite like you can zoom in and out in a 
program like 'photoshop'. All you can really do is redraw the plot with 
a different set of X and Y limits.

Example:

# some data
  xy=list(x=rnorm(100),y=rnorm(100))

# default plot shows all the data:
  plot(xy)

# define an interactive 'zoom' function:
zoom=function(){reg=locator(2);plot(reg,type='n')}

# click two points at the corners of the zoom region:
zoom()

# add the points - dont use 'plot' since this resets the axes:
points(xy)

  If you've got a complex plot with lots of things on it, then yes, you 
have to redraw it all again, but then you probably should have put that 
complex plot into a single function!

Barry




More information about the R-help mailing list