1

Possible Duplicate:
Shading a kernel density plot between two points.

How to draw this graph in R, assuming normal pdf?

enter image description here

Community
  • 1
  • 1
Qiang Li
  • 10,593
  • 21
  • 77
  • 148

2 Answers2

6

I answered that a while back on StackOverflow for something closely related. The question really is a duplicate and should be closed. All these how do I shade below a curve questions are answered by a close read of help(polygon) and a study of the existing examples.

Community
  • 1
  • 1
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
5

The code for getting shaded area below:

plot(dnorm,-4,4,xlab="x",ylab="pdf")
xvals <- seq(-2,1,length=50)
dvals <- dnorm(xvals)
polygon(c(xvals,rev(xvals)),c(rep(0,50),rev(dvals)),col="gray")

Result:

enter image description here

m0nhawk
  • 22,980
  • 9
  • 45
  • 73