Hitesh Singla
2009-Aug-12 04:49 UTC
[R] How to label and unlabel points on scatterplot with mouse pointer
Dear all, How can I label/unlabel points on scatterplot with mouse pointer. As the mouse approches near to point, it should label the closest point, then unlabel when it moves away. How can I do in R? I be very thankful. Thanks and Regards, Hitesh Singla -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
milton ruser
2009-Aug-12 06:46 UTC
[R] How to label and unlabel points on scatterplot with mouse pointer
Hi Hitesh, while the rigth response not arrive, you can play with: id<-1:10 x<-runif(10) y<-runif(10) plot(x,y) identify(x, y , labels = id) Try give a look on spatstat help. I am not quite sure, but may be there you can find some solution (sorry if it is not true) cheers milton On Wed, Aug 12, 2009 at 12:49 AM, Hitesh Singla < hitesh_s@students.iiit.ac.in> wrote:> Dear all, > > How can I label/unlabel points on scatterplot with mouse pointer. As the > mouse approches near to point, it should label the closest point, then > unlabel when it moves away. > > How can I do in R? I be very thankful. > > Thanks and Regards, > > Hitesh Singla > > -- > This message has been scanned for viruses and > dangerous content by MailScanner, and is > believed to be clean. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Hitesh Singla
2009-Aug-12 11:12 UTC
[R] How to label and unlabel points on scatterplot with mouse pointer
Thanks milton, But that does not work in my case.. Any other suggestion be appreciated. Thanks and regards, Hitesh Singla> Hi Hitesh, > > while the rigth response not arrive, you can play with: > > id<-1:10 > x<-runif(10) > y<-runif(10) > > plot(x,y) > identify(x, y , labels = id) > Try give a look on spatstat help. I am not quite sure, but may be there > you > can find some solution (sorry if it is not true) > > cheers > > milton > > On Wed, Aug 12, 2009 at 12:49 AM, Hitesh Singla < > hitesh_s at students.iiit.ac.in> wrote: > >> Dear all, >> >> How can I label/unlabel points on scatterplot with mouse pointer. As the >> mouse approches near to point, it should label the closest point, then >> unlabel when it moves away. >> >> How can I do in R? I be very thankful. >> >> Thanks and Regards, >> >> Hitesh Singla >> >> -- >> This message has been scanned for viruses and >> dangerous content by MailScanner, and is >> believed to be clean. >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> >> and provide commented, minimal, self-contained, reproducible code. >> > > -- > This message has been scanned for viruses and > dangerous content by MailScanner, and is > believed to be clean. > >-- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
Greg Snow
2009-Aug-12 19:46 UTC
[R] How to label and unlabel points on scatterplot with mouse pointer
Here is one approach that works on Windows (but not other platforms): HWidentify <- function(x,y,label=seq_along(x), xlab=deparse(substitute(x)), ylab=deparse(substitute(y)), ...) { plot(x,y,xlab=xlab, ylab=ylab,...) dx <- grconvertX(x,to='ndc') dy <- grconvertY(y,to='ndc') mm <- function(buttons, xx, yy) { d <- (xx-dx)^2 + (yy-dy)^2 if ( all( d > .01 ) ){ plot(x,y,xlab=xlab,ylab=ylab,...) return() } w <- which.min(d) plot(x,y,xlab=xlab,ylab=ylab,...) points(x[w],y[w], cex=2, col='red') text(grconvertX(xx,from='ndc'),grconvertY(yy,from='ndc'), label[w], col='green', adj=c(0,0)) return() } md <- function(buttons, xx, yy) { if (any(buttons=='2')) return(1) return() } getGraphicsEvent('Right Click to exit', onMouseMove = mm, onMouseDown=md) invisible() } tmpx <- runif(25) tmpy <- rnorm(25) HWidentify(tmpx,tmpy,LETTERS[1:25], pch=letters) Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Hitesh Singla > Sent: Tuesday, August 11, 2009 10:50 PM > To: r-help at r-project.org > Subject: [R] How to label and unlabel points on scatterplot with mouse > pointer > > Dear all, > > How can I label/unlabel points on scatterplot with mouse pointer. As > the > mouse approches near to point, it should label the closest point, then > unlabel when it moves away. > > How can I do in R? I be very thankful. > > Thanks and Regards, > > Hitesh Singla > > -- > This message has been scanned for viruses and > dangerous content by MailScanner, and is > believed to be clean. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code.