2017-04-14 40 views
0

如果你在下面运行我的小函数,你会看到类似下面的图片。 的更小尺寸的这里”的固定各地的曲线。但较大尺寸的“这里”移动如果你运行我的功能多次(见下文进一步我的R代码里面)。如何让固定的`text()`的大小加大移动的`text()`的大小R

我的问题是我怎么能有大小固定的“这里” text()成为等于移动text()大小只有当在彼此的顶部两块TEXT坠落?

请参阅下面我注释的R代码。

enter image description 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 

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() 

回答

3

会是这样的工作?

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()