【发布时间】:2014-10-11 23:19:22
【问题描述】:
curve(-12 * log(x) - (415 / x), 25, 50)
abline(h = -55, lty = 2)
我想绘制曲线和实线之间的区域并对其进行着色,但无法做到。我尝试使用 pracma 包中的 trapz 函数。有什么建议将不胜感激?
【问题讨论】:
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 的评论
【讨论】:
polygon 之前添加问题的一段代码,以便您可以在单个代码块中获得所需的最终输出;)跨度>