R plot undo line segment?

孤者浪人 提交于 2019-12-02 02:38:24

You can do it with Grid graphics,

library(grid)
ll = replicate(2, grid.locator())
g = grid.segments(ll[,1]$x, ll[,1]$y, ll[,2]$x, ll[,2]$y, 
      name="mysegment", gp=gpar(col="pink", lwd=5))
grid.remove("mysegment")

No. About the best you can do unless you use grid graphics is to write over the offending segment in the background color (i.e. segments(p1$x, p1$y, p2$x, p2$y, col = 'white') if the background is white -- a hack that sometimes fails).

To address your updated question above about somehow storing the written pixels to remove them later; in R's base graphics system (as distinguished from Paul Murrell's grid graphics system, as discussed by @baptiste, or graphics using the rgl package for dynamic 3D graphics) the metaphor is of a canvas you're painting. R doesn't "remember" what it has drawn; those pixels or segments are added to the output device and forgotten.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!