>我有一个简单的for()
循环,可以生成某些points()
出现在曲线上所需的x
和y
值。
我的问题是我怎样才能使每个新points()
,删除以前的points()
给人一种points()
在曲线上移动的感觉?
注意:我可以将curve()
插入循环以实现我的目标,但出于我的目的,我需要避免重复curve()
。因此,需要将curve()
排除在for()
循环之外。
下面是一个小的 R 代码:
curve(dnorm(x), -4, 4)
for(i in 1:7) {
xx <- sample(x = seq(-4, 4, len = 21), size = 1) # gives one x value for point()
yy <- dnorm(xx) # gives one y value for point()
points(xx, yy, pch = 19, cex = 1.1) ## I need after each new point is generated
## the previous point be gone!
Sys.sleep(1/2)
}
睡眠期后重绘曲线:
curve(dnorm(x), -4, 4)
for(i in 1:7) {
xx <- sample(x = seq(-4, 4, len = 21), size = 1)
yy <- dnorm(xx) ; points(xx, yy, pch = 19, cex = 1.1)
Sys.sleep(1/2) ;curve(dnorm(x), -4, 4) ;
}