[R] Shading the area between lines

Jim Lemon jim at bitwrit.com.au
Sat Jul 4 10:03:56 CEST 2009


Hannu Kahra wrote:
> Hi,
>
> I have a graph with seven parallel horizontal lines. Is it possible to
> shade the area between two adjacent lines?
>
>   
Hi Hannu,
Easy if you know the endpoints of the lines.

plot(rep(1,2),type="l",ylim=c(0,8))
for(i in 1:6) {
 lines(rep(i+1,2))
 polygon(c(1,1,2,2),c(i,i+1,i+1,i),col=i)
}

Jim




More information about the R-help mailing list