[R] using R interactively

Terry J. Westley twestley at buffalo.veridian.com
Mon Jun 28 20:18:41 CEST 1999


1) Is it possible to erase data points, legends, and/or text
   from an R plot?

2) What's the best way to find the closest data point to
   what locator() returns?

For more background and some context on these questions, read on...

In using R interactively, I am displaying further details
about a specific data point when the user clicks on the
plot point.

Here's a simple example:

# begin example
n <- runif(10)
plot(n)

while (1) {
   # get index of data point user clicks on
   l <- locator(1)
   index <- order(abs(n-l$y))[1]

   # show which one user clicked on
   points (x=index, y=n[index], pch="X")

   # show details about that data point
   legend (x=1, y=max(n),
      legend=paste("n(", index, ") = ", n[index], sep=""))
}
# end example

1) Is there a way to remove or erase the data point used
   to identify which data point was selected and the legend
   when the user clicks on the next data point?

2) Is there a better way to find the closest data point
   than what I used: order(abs(n-l$y))[1]?  I'm pretty new
   to R so I'm sure there are better ways than this.

   In my actual code, the X axis is time so I searched in
   the time vector rather than in y as in the example above.
   I'm sure there must be an easy way to find the closest point
   in both X and Y space.

3) Also, has anyone implemented anything like buttons or pull-down
   menus so that I could implement other functions?  I'm using
   Tcl/Tk to control this application but I would prefer that, once
   the plot is displayed, the user doesn't have to go back to another
   window to invoke other functions (such as Quit).

I'm using R version 0.64.0 on sparc-sun-solaris2.5.1.  The
sample code above also works as expected on Windows 95 with
R version 0.63.3.

Thanks.

--
Terry J. Westley, Principal Engineer
Veridian Engineering, Calspan Operations
P.O. Box 400, Buffalo, NY 14225
twestley at buffalo.veridian.com    http://www.veridian.com

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list