例如,如果我需要在阴谋中遮蔽两个区域
x<-rep(1:10)
plot(x,type="h")
Run Code Online (Sandbox Code Playgroud)
我需要以1到3和7到10之间的区域为例,
我使用这个命令,但它省略了绘图线.
usr <- par('usr')
rect(1, usr[3], 3, usr[4], col='green')
Run Code Online (Sandbox Code Playgroud)
Jos*_*ien 13
如果我理解正确,你可以通过使用鲜为人知的panel.first=参数得到你想要的东西plot.default():
plot(x,type="h",
panel.first = {
usr <- par('usr')
rect(c(1,7), usr[3], c(3,10), usr[4], col='green', border=NA)
})
Run Code Online (Sandbox Code Playgroud)
或者,为了避免任何par('usr')数值,只需:
plot(x, type="h",
panel.first = rect(c(1,7), -1e6, c(3,10), 1e6, col='green', border=NA))
Run Code Online (Sandbox Code Playgroud)

看?多边形:
polygon( x = c(1,1,3,3,1), y=c( usr[1], x[1], x[3], usr[1], usr[1]) ,col="red")
> polygon( x = c(1,1,3,3,1), y=c( usr[1], x[1], x[3], usr[1], usr[1]) ,col="red")
> polygon( x = c(7,7,10,10,7), y=c( usr[2], x[7], x[10], usr[1], usr[1]) ,col="red")
Run Code Online (Sandbox Code Playgroud)
我选择关闭多边形,但似乎我记得你可以让它自我关闭.
