R语言中使用locator(1)函数获取图形的位置坐标

1、

> plot(1:10)
> locator(1)  ## 此时鼠标点击图形中位置,将返回位置坐标
$x
[1] 2.202362

$y
[1] 7.89666

> text(locator(1),"xxx",cex = 2,col="red")   ## 结合text函数,可以图形中添加文本
> text(locator(1),"yyy",cex = 2,col="red")

 

原文地址:https://www.cnblogs.com/liujiaxin2018/p/14667735.html