r - 我可以在 Rstudio 中单击后直接绘制每个 locator() 点吗?

标签 r plot rstudio

绘图(1:10); locator(3, type="p") 在外部图形设备中工作正常。
Rstudio 仅在定位完成后绘制点。
如何在每次点击后立即绘图?

最佳答案

# A workaround is the following:
rslocator <- function(n=512, type="p", ...)
 {
 on.exit(return(list(x=x,y=y))) # output even when function is canceled with ESC in console
 x <- y <- NULL
 i <- 1
 while(i<=n)
   {
   d <- locator(1)
   if(is.null(d)) break # If user pressed ESC in Rstudio Graphics window
   x <- c(x, d$x)
   y <- c(y, d$y)
   points(x,y, type=type, ...)
   i <- i+1
   }
 }


plot(1:10, type="n")
rslocator(7, col="blue", type="o")
# plots each point right after clicking and ESC still works fine

关于r - 我可以在 Rstudio 中单击后直接绘制每个 locator() 点吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65147219/

相关文章:

r - trainControl 中的 p 参数

python - Matplotlib 绘图未显示在 Mac OSX 中?

python - 我们如何使用 matplotlib 正确注释同一张图中的多个图?

Git、Dropbox 和 Rstudio

r - 如何在使用存储在变量中的名称创建数据框时命名列?

r - 更改列名 - 替换前缀

r - 在 RStudio 中按新行缩进

r - 将日期转换为R中的天数(星期一= 1,星期二= 2)

r - 如何在 R 中的多面板图中为每个面板指定不同的颜色

r - R散点图中的轴位置