36

I would like to know if R allows to pan and zoom images produced with the "plot" function. I would like to obtain the plot transformation using the mouse and not through the command line, is it possible?

Thanks in advance.

rlar
  • 856
  • 1
  • 10
  • 15

7 Answers7

30

It's a bit old question but for future references, I've wrote a package doing precisely that (based on zoomplot {in pkg:TeachingDemos}). It's called zoom:

The CRAN page on zoom

And you are welcome to check the latest and greatest and expand the package on Github

Usage -

library(zoom) # Invoke the Library
# Call plot
zm()

The instructions for Usage in a normal plot is

Mouse:

  • Scroll to zoom in and out
  • Hold left mouse button to move

Keyboard:

  • Left/Right (h/l): move left/right
  • Up/Down (k/j) : move up/down
  • + or i / - or o : zoom in/out
  • L/H : zoom in/out (x-axis only)
  • K/J : zoom in/out (y-axis only)
  • p : print to file
  • r : reset limits
  • s : show limits

q on the graphic window to quit

MichaelChirico
  • 33,841
  • 14
  • 113
  • 198
cmbarbu
  • 4,354
  • 25
  • 45
  • With hundreds (or perhaps thousands) of data points, the refresh felt slow in this library, and then R crashed. This is based on VERY limited experience. – Josiah Yoder Aug 06 '19 at 19:43
15

Not with the default plotting device as its internal model is 'static'.

There are workarounds, tough: look for example at package playwith, or at a Java-based device such as the iplots package on Simon's rforge. There are also extensions like ggobi and other on-going work (such as the Qt-based device which will in time replace ggobi) which try to make R-based graphing more dynamic.

But the main takeaway is: not, not really -- due to the way R graphics devices are designed.

chl
  • 27,771
  • 5
  • 51
  • 71
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
5

To add to Dirk's answer: see also the iWebPlots and RnavGraph packages.

Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
2

You should look at Greg Snows zoomplot {in pkg:TeachingDemos}. You may be able to call that function with cursor interface using the tk toolkit. I think Greg's package also has examples of such an interface.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
1

You can also add R graphs to plot.ly . This should be enough for the most common stuff.

Stefan

Buggy
  • 2,050
  • 21
  • 27
1

Now there are also http://www.htmlwidgets.org/ that add a great set of interactive visualizations capabilities to R. Most of them can easily be zoomed and panned.

Aurèle
  • 12,545
  • 1
  • 31
  • 49
1

To add to existing answers: I like to use the identify() function to manually add labels just to particular points I want.

Tomas
  • 57,621
  • 49
  • 238
  • 373