【问题标题】:Area under curve曲线下面积
【发布时间】:2014-10-11 23:19:22
【问题描述】:
curve(-12 * log(x) - (415 / x), 25, 50)
abline(h = -55, lty = 2)

我想绘制曲线和实线之间的区域并对其进行着色,但无法做到。我尝试使用 pracma 包中的 trapz 函数。有什么建议将不胜感激?

【问题讨论】:

    标签: r auc


    【解决方案1】:

    然后您可以使用polygon() 来定义足够多的点的 x 和 y 坐标以使其看起来平滑。我会选择 120:

    ff <- function(x) -12 * log(x) - (415 / x)  ## define curve
    
    # get a vector or potential x values for the polygon
    x1 <- seq(from=25, to=50, length.out=120)
    x1 <- x1[ff(x1) >= -55]  ## filter only relevant section
    
    x2 <- rev(x1)    ## reverse the vector for the return trip
    xx <- c(x1, x2)  ## concatenate to get all x coordinates
    yy <- c(rep(-55, length(x1)), ff(x2))
    
    curve(ff, 25, 50)
    abline(h = -55, lty = 2)
    # join the dots and fill the space orange
    polygon(xx, yy, col='orange')
    

    编辑:向整个过程添加代码以反映来自@epsilone 的评论

    【讨论】:

    • 不错的答案@ilir,作为建议,我会在调用polygon 之前添加问题的一段代码,以便您可以在单个代码块中获得所需的最终输出;)跨度>
    猜你喜欢
    • 1970-01-01
    • 2011-06-24
    • 2020-03-30
    • 1970-01-01
    • 2018-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多