简体   繁体   English

如何将散点图中的点的标签输出到bash控制台

[英]How to output the label of points in scatterplot to bash console

I have a simple R-Script: 我有一个简单的R脚本:

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. 我从bash脚本运行它来生成基本图。

Now I want to use X11() to plot directly into a window and not into a PDF. 现在,我想使用X11()直接绘制到窗口中而不是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. 我现在想要的是将inp$V1悬停在某个点上或在其上滑动时,在控制台上显示每个点的标签(在inp$V1 )。

How to do? 怎么做?

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. identify功能使您可以单击点,并返回单击点的索引值,该索引值可用于子集标签向量。

For identification when hovering (instead of clicking) you can look at the HTKidentify function in the TeachingDemos package. 为了在悬停时标识(而不是单击),可以查看TeachingDemos包中的HTKidentify函数。

Edit 编辑

Here is an example using identify that may be more what you want (I tested it on windows, not unix/X11): 这是一个使用identify的示例,它可能更多地是您想要的(我在Windows而不是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). plot=FALSE告诉查明没有把标签上的情节和n=1告诉它你点击1分后返回(在while追溯到识别更多的点,而是立即打印出标签)。

Obviously you would create other labels to use than just the letters. 显然,您会创建除字母以外的其他标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM