Search code examples
rplotarea

shaded area under curve R


I am trying to plot a shaded area under a curve but however the shaded area is over the curve. Can anyone tell me what's wrong with my code?

x=seq(0,30)
y1=exp(-0.1*x)
plot(x,y1,type="l",lwd=2,col="chocolate1")
polygon(x,y1, density = 5, angle = 45,col="chocolate1")

Solution

  • you probably want something like this:

    polygon(c(min(x),x),c(min(y1),y1), density = 5, angle = 45,col="chocolate1")