Reputation: 766
I have a simple R-Script:
args <- commandArgs(TRUE)
inp <- read.csv(args[1],sep="\t",header=FALSE,stringsAsFactors=FALSE)
firstCol <- inp$V2
secondCol <- inp$V3
pdf(args[2])
plot(firstCol,secondCol,xlab="#",ylab="maxLength")
dev.off()
I run it from a bash script to generate a basic plot.
Now I want to use X11()
to plot directly into a window and not into a PDF.
What I want now is to appear the label (in inp$V1
) of every dot on the console when hovering over a point or klicking onto it.
How to do?
Upvotes: 2
Views: 128
Reputation: 49640
The identify
function lets you click on points and it returns the index value for the points clicked on that could be used to subset a vector of labels.
For identification when hovering (instead of clicking) you can look at the HTKidentify
function in the TeachingDemos package.
Edit
Here is an example using identify
that may be more what you want (I tested it on windows, not unix/X11):
x <- runif(26)
y <- rnorm(26)
plot(x,y)
while(length(tmp <- identify(x,y, plot=FALSE, n=1))) {
cat(letters[tmp],'\n')
}
The plot=FALSE
tells identify to not put the label on the plot and the n=1
tells it to return after you click on 1 point (the while
goes back to identifying more points, but prints out the label immediately).
Obviously you would create other labels to use than just the letters.
Upvotes: 3