运行代码后,图表中存在细微差距.
x = seq(0, 1, by=0.01)
y1=x
y2=x^2
plot(x, y1,type="l")
lines(x,y2,type="l",col="red")
xx1<-c(0,x[x<1 & x>0 ],1,x[x<1 & x>0 ],0)
yy1<-c(0,x[x<1 & x>0 ],1,(x[x<1 & x>0 ])^2,0)
polygon(xx1,yy1,col="yellow")
Run Code Online (Sandbox Code Playgroud)
请看附件,为什么有一个细微的差距?我怎么能删除它,让它被黄色填充?

如果减少点数,则更容易看出问题的原因:
x <- seq(0, 1, by=0.2)
plot( x, x, type="l" )
lines( x, x^2, col="red" )
xx1 <- c(0,x[x<1 & x>0 ],1,x[x<1 & x>0 ],0)
yy1 <- c(0,x[x<1 & x>0 ],1,x[x<1 & x>0 ]^2,0)
polygon(xx1, yy1, lwd=3, col="wheat")
points(xx1, yy1)
Run Code Online (Sandbox Code Playgroud)

这些点是正确的,但顺序不是.对于凸多边形,xx1应首先增加,然后减少.
plot( x, x, type="l" )
lines( x, x^2, col="red" )
xx1 <- c(x, rev(x))
yy1 <- c(x, rev(x)^2)
polygon(xx1, yy1, lwd=3, col="wheat")
Run Code Online (Sandbox Code Playgroud)