【发布时间】:2017-04-14 17:26:02
【问题描述】:
如果你在下面运行我的小函数,你会看到类似下图的内容。 较小的“此处”在曲线周围固定。但是,如果您多次运行我的函数,较大的“这里”会移动(请进一步查看我的 R 代码下面)。
我的问题是如何让固定的“HERE”text() 的大小与移动的text() 的大小相同仅当 THE两段文字相互重叠?
请看下面我带注释的 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()
【问题讨论】: