r - 单击 Rstudio 后,我可以直接绘制每个 locator() 点吗?
问题描述
plot(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
推荐阅读
- cypress - 赛普拉斯在提交表单时取消 api 请求
- fortran - BBedit 选项“运行”或“在终端中运行”
- git - 从 master 获取当前差异并将其转换为单个提交,而无需将每个提交应用在彼此之上
- html - 当浏览器最小化时,如何在一个部分堆栈中创建 2 列?
- regex - 具有未知子文件夹深度的 nginx 位置
- javascript - 在数组中查找元素并返回父元素
- angular - 我们如何定位以错误 *ngIf 条件开头的元素?
- sql - 在 SQL 中选择最大计数
- android - 为什么颤振中的建造者在这里打破
- google-apps-script - 迁移到 V8 运行时后触发的电子邮件无法正常工作