[英]How to make the size of fixed `text()` to mach the size of a moving `text()` in R
如果您在下面运行我的小功能,则会看到类似下图的内容。 较小的 “ 此处 ”在整个曲线上固定 。 但是,如果您多次运行我的函数,则较大的“ Here”正在移动 ( 请参阅下面的R代码 )。
我的问题是, 只有当两枚TEXT FALL落在其他TOP上时,如何才能使固定的“ HERE” text()
的大小等于Moving text()
的大小?
请在下面查看我带注释的R代码。
Here = function(){
curve(dnorm(x), -4, 4)
x.on.curve = seq(-4, 4, len = 21) # x.values for fixed text
y.on.curve = dnorm(x.on.curve) # y.values for fixed text
xx <- sample(x = seq(-4, 4, len = 21), size = 1) # x.values for moving text
yy <- dnorm(xx) # y.values for moving text
text(x.on.curve, y.on.curve, 'Here') ## whenever the x.values of a fixed 'HERE'
# matches the x.value of the moving 'HERE'
# in below "text()", change cex = 2, ELSE cex = 1
text(xx, yy, 'Here', cex = 2)
}
## Please run multiple times here:
Here()
这样的事情行吗?
Here = function(){
curve(dnorm(x), -4, 4)
x.on.curve = seq(-4, 4, len = 21) # x.values for fixed text
y.on.curve = dnorm(x.on.curve) # y.values for fixed text
ind <- sample(1:21,1) # index of the x and y values for moving text
text(x.on.curve[-ind], y.on.curve[-ind], 'Here')
text(x.on.curve[ind], y.on.curve[ind], 'Here', cex = 2)
}
## Please run multiple times here:
Here()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.