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")

 

 

posted @ 2021-04-16 16:49  小鲨鱼2018  阅读(2849)  评论(0编辑  收藏  举报