curve(-12 * log(x) - (415 / x), 25, 50)
abline(h = -55, lty = 2)
我想绘制曲线和实线之间的区域并对其进行着色,但无法做到。我尝试使用 pracma 包中的 trapz 函数。任何建议,将不胜感激?
然后,您可以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 的评论