使用r中的定位器删除插入到绘图中的文本框

Eli*_*eth 2 plot r

如何删除使用定位器插入的最后一项(如文本框)?即

plot(1:3)
text(locator(1),labels="oops wrong spot...remove me",cex=1,font=1)
Run Code Online (Sandbox Code Playgroud)

Mat*_*rde 8

您可以非常轻松地实现可以执行此操作的内容:

locator <- function(...) {
    assign('.last.plot', recordPlot(), envir=.GlobalEnv)
    graphics::locator(...)
}

undo <- function()
   if (exists('.last.plot')) replayPlot(.last.plot)

plot(1:3)
text(locator(1),labels="oops wrong spot...remove me",cex=1,font=1)
undo()
Run Code Online (Sandbox Code Playgroud)