[R] Highlight overlapping area between two curves

Charilaos Skiadas skiadas at hanover.edu
Tue Mar 13 06:53:01 CET 2007


On Mar 13, 2007, at 12:19 AM, Nguyen Dinh Nguyen wrote:

> Dear R helpers,
> I have a graph as following; I would like to highlight the  
> overlapping area
> between the two curves. Do you know how to do this?
> Thank you in advance for your help.

Perhaps not exactly what you wanted, but it might give you some ideas:

p <- seq(0.2,1.4,0.01)
x1 <- dnorm(p, 0.70, 0.12)
x2 <- dnorm(p, 0.90, 0.12)
plot(range(p), range(x1,x2), type="n")
lines(p, x1, col = "red",lwd=4, lty=2)
lines(p, x2, col = "blue",lwd=4)
polygon(c(p,p[1]),c(pmin(x1,x2),0), col="grey")


> Nguyen

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College



More information about the R-help mailing list