For example if i need to shade two area in plot
x<-rep(1:10)
plot(x,type=\"h\")
I need as an example shade the area from 1 to 3 and from
If I understand you correctly, you can get what you want by using the little-known panel.first=
argument to 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)
})
Or, to avoid any mucking around with par('usr')
values, just do:
plot(x, type="h",
panel.first = rect(c(1,7), -1e6, c(3,10), 1e6, col='green', border=NA))
See ?polygon:
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")
I chose to close the polygon but seem I remember you can get it to self-close.