R 为什么多边形函数中有一个很小的间隙?

R 为什么多边形函数中有一个很小的间隙?,r,polygon,R,Polygon,运行代码后,图形中有一个很小的间隙 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

运行代码后,图形中有一个很小的间隙

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")
x=seq(0,1,by=0.01)
y1=x
y2=x^2
绘图(x,y1,type=“l”)
行(x,y2,type=“l”,col=“red”)

xx1如果减少分数,问题的原因更容易看出:

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)
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")