我无法让polygon()
将分布在下方分布一直到x轴。它似乎高于指数分布到y=-x
线。这是我到目前为止所处的位置:
x <- seq(0,50,0.01)
y <- dexp(seq(0,50,0.01),rate=0.11)
plot(x, y, type="l", col=col2rgb("yellow",0.5), xaxs="i", yaxs="i", ylim=c(0,0.15))
polygon(x, y ,border=NA,col=col2rgb("yellow",0.5))
非常感谢!
答案 0 :(得分:8)
解决方案很简单,只需将x <- seq(0,50,0.01)
y <- dexp(seq(0,50,0.01),rate=0.11)
plot(x, y, type="l", col=col2rgb("yellow",0.5), xaxs="i", yaxs="i", ylim=c(0,0.15))
polygon(c(0, x), c(0, y), border=NA, col=col2rgb("yellow",0.5))
添加到多边形的顶点即可。见下文:
polygon()
polygon()
如何运作
(0, 0)
将按顺序排列所有顶点。原始代码的问题是原点x0 <- c(0, 0.5, 1.5)
y0 <- c(1.5, 0.5, 0)
## triangle, with three vertices
plot(x0, y0, pch = ".")
polygon(x0, y0, col = "red", border = NA)
## area under triangle, four vertices
polygon(c(0, x0), c(0, y0), col = "yellow", border = NA)
不是顶点之一,因此它不是多边形的一部分。您还可以考虑以下玩具示例:
git update-index --asume-unchanged <filenameHere>