简体   繁体   English

如何使固定的`text()`的大小与R中移动的`text()`的大小相匹配

[英]How to make the size of fixed `text()` to mach the size of a moving `text()` in R

If you run my small function below, you'll see something like the below picture. 如果您在下面运行我的小功能,则会看到类似下图的内容。 The Smaller-sized " Here " are fixed all around the curve. 较小的此处 ”在整个曲线上固定 But the Larger-sized "Here" is moving if you run my function multiple times ( see my R code further below ). 但是,如果您多次运行我的函数,则较大的“ Here”正在移动请参阅下面的R代码 )。

My question is how I can have the size of the fixed "HERE" text() to become equal to the size of the Moving text() ONLY WHEN THE TWO PIECES of TEXT FALL on TOP of EACH OTHER? 我的问题是, 只有当两枚TEXT FALL落在其他TOP上时,如何才能使固定的“ HERE” text()的大小等于Moving text()的大小?

Please see my annotated R code below. 请在下面查看我带注释的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()

Would something like this work? 这样的事情行吗?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM