Could anyone please tell me a way to get mouse movement events? I am trying to make a zoomable time series plot
-
`locator()` collects mouse click information – Andrie Aug 22 '12 at 20:29
-
Study the code of `quantmod::zooom` – GSee Aug 22 '12 at 20:31
-
2Also, see http://stackoverflow.com/questions/12078575/unix-getting-mouse-coordinates-over-x-like-the-mathematica – GSee Aug 22 '12 at 20:32
2 Answers
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("")

- 48,880
- 13
- 125
- 145
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.

- 48,497
- 6
- 83
- 110