Search code examples
rlinesareacurve

How to fill an area using narrow parallel lines


I would like to exploit something like the "polygon" function to fill the area under a curve but I don't want to use colors but narrow parallel lines (better if oblique).

Is that possible?


Solution

  • Using the density and angle arguments this can be achieved in polygon() (i.e. read the manual)

     x=seq(-7,10,length=200)
     y1=dnorm(x,mean=0,sd=1)
     plot(x,y1,type="l",lwd=2,col="red")
     y2=dnorm(x,mean=3,sd=2)
     lines(x,y2,type="l",lwd=2,col="blue")
    
    
     polygon(x,pmin(y1,y2), density = 10, angle = -45)
    

    with MINOR tweaking from (Shaded area under two curves using R)

    enter image description here