[R] a question about identify and locator

John Fox jfox at mcmaster.ca
Fri Jul 30 16:41:50 CEST 2004


Dear Uwe and Jordi,

It is possible to get close to what Jordi wants using the tcltk package:

IDPoints <- function(x, y, labels){
    top <- tktoplevel()
    tkwm.title(top, "Coordinates")
    coords <- tclVar("")
    coordsEntry <- tkentry(top, width="25", textvariable=coords)
    Stop <- tclVar("No")
    onStop <- function() {
        tclvalue(Stop) <- "Yes"
        tkdestroy(top)
        }
    stopButton <- tkbutton(top, text="Stop", fg="red", width="12",
command=onStop)
    tkgrid(coordsEntry)
    tkgrid(stopButton)
    repeat {
        if (tclvalue(Stop) == "Yes") break
        if (missing(x)){
            xy <- format(locator(1), digits=10)
            tclvalue(coords) <- paste(xy, collapse=", ")
            }
        else{
            point <- identify(x, y, rep("", length(labels)), n=1)
            tclvalue(coords) <- labels[point]
            }
        }
    }

Try, e.g.,

plot(1:10)
IDPoints()
IDPoints(1:10, 1:10, letters[1:10])

There is a minor irritation that I haven't been able to remove, however: You
have to identify one more point after pressing the "Stop" button.

Regards,
 John 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Uwe Ligges
> Sent: Friday, July 30, 2004 9:27 AM
> To: Molins, Jordi
> Cc: 'r-help at stat.math.ethz.ch'
> Subject: Re: [R] a question about identify and locator
> 
> Molins, Jordi wrote:
> 
> > Hello,
> > 
> > I use R 1.9.1 on Windows 2000. I have a chart that I am 
> looking. I use
> > identify() and locator() to find out the (x,y) values of 
> interesting 
> > points in the chart, but these functions are not always 
> helpful (e.g., 
> > sometimes
> > identify() prints on top of the chart, making the number 
> illegible). 
> 
> par(xpd = NA) just before using identify() should help here. 
> See ?par for details.
> 
> 
>  > What I
> > would be interested in is in a functionality that 
> identifies the (x,y) point
> > using something like a text box superimposed on the chart 
> that disappears
> > when the cursor is away from the chart (for example, 
> similar to Excel) or
> > even better, small text boxes located both in the x and y 
> axis near to the
> > points (0,y) and (x,0), resp., that are constantly updated 
> (like charts in
> > Bloomberg) .
> > 
> > Is there something like this in R? 
> 
> Not within R itself.
> 
> Uwe Ligges
> 
> 
> > Thank you
> > 
> > Jordi




More information about the R-help mailing list