簡體   English   中英

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

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM