The way I would do it is with function curve
instead of abline
in order to keep to coordinates of the path of both lines and feed them to `polygon:
c1 <- curve((-b-1)/w[1,2] - x*w[1,1]/w[1,2], from=-10, to=10,
col="orange",add=TRUE,lty=3)
c2 <- curve((-b+1)/w[1,2] - x*w[1,1]/w[1,2], from=-10, to=10,
col="orange",add=TRUE,lty=3)
polygon(c(c1$x,rev(c2$x)), c(c1$y, rev(c2$y)),col="grey80", border=NA)
Edit: As Julian Urbano correctly suggested, you can use par('usr')
to define the values for parameters from
and to
automatically:
u <- par('usr')
c1 <- curve((-b-1)/w[1,2] - x*w[1,1]/w[1,2], from=u[1], to=u[2],
col="orange",add=TRUE,lty=3)
c2 <- curve((-b+1)/w[1,2] - x*w[1,1]/w[1,2], from=u[1], to=u[2],
col="orange",add=TRUE,lty=3)
polygon(c(c1$x,rev(c2$x)), c(c1$y, rev(c2$y)),col="grey80", border=NA)