1

Could anyone please tell me a way to get mouse movement events? I am trying to make a zoomable time series plot

2 Answers2

2

Here's a "zoomable time series plot" that's already written

library(quantmod)
getSymbols("SPY", src='yahoo')
chartSeries(SPY)

Now, you can zoom by either using zoomChart

zoomChart("last 6 months")

or, you can use the zooom function

zooom()

Now click somewhere on the chart, then click somewhere else on the chart to the right of where you clicked the first time, and it will zoom in using the places you clicked as the new start and end.

You can use zoomChart with an empty string to "unzoom" like this

zoomChart("")
GSee
  • 48,880
  • 13
  • 125
  • 145
0

If you are using windows then you can use getGraphicsEvent get mouse movements otherwise (or even with windows) you need to use something like the tcltk package. If you only care about the mouse clicks then you can use locator.

What might be preferable is to use the tkexamp function from the TeachingDemos package to set up a plot that can be scrolled/zoomed using slider bars. There are other packages that provide similar functionality, but I am less familiar with them.

Greg Snow
  • 48,497
  • 6
  • 83
  • 110