R:从用户绘制的点生成坐标数据?

Mik*_*der 5 plot r vector-graphics draw

我想手动将点添加到绘图中(通过鼠标点击),然后从这些点生成坐标数据.

是否有一个包或一组函数可以让我在R中执行此操作?

Jos*_*ien 6

您可以使用基本功能locator()执行此操作.请尝试以下操作,例如:

plot(1:4)
df <- data.frame(locator())
## Now, on the plotting device:
## 
##     (1) "Left-click" on each of the four points
##     (2) "Right-click --> Stop" to return to the command-line

## The object that is returned, and assigned to df will look
## something like the following
df
         x        y
1 1.008072 1.032795
2 2.011049 2.002365
3 3.004381 2.995299
4 3.997714 4.011595
Run Code Online (Sandbox Code Playgroud)

locator()当您需要精确地将某些内容(例如文本或图例)放置到绘图的坐标系不容易从轴上读取的绘图上时,通常很有用.例如,尝试此操作,在返回命令行之前单击一次:

barplot(VADeaths)
text(locator(1), "I clicked here", col="red")
Run Code Online (Sandbox Code Playgroud)