【问题标题】:How to make the size of fixed `text()` to mach the size of a moving `text()` in R如何使固定`text()`的大小与R中移动`text()`的大小相匹配
【发布时间】: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()

【问题讨论】:

    标签: r function plot


    【解决方案1】:

    这样的东西有用吗?

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

    【讨论】:

      猜你喜欢
      • 2014-08-11
      • 1970-01-01
      • 1970-01-01
      • 2021-12-21
      • 2016-07-22
      • 2018-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多