[R] Highlight overlapping area between two curves

Bojanowski, M.J. (Michal) M.J.Bojanowski at uu.nl
Tue Mar 13 11:49:46 CET 2007


If PDF is OK, you can use the 'alpha' argument in colors, i.e.:

pdf( "file.pdf")
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")
polygon(p, x1, col = rgb(1,0,0, .5),lwd=4, lty=2)
polygon(p, x2, col = rgb(0,0,1, .5),lwd=4)
dev.off()
 

hth,
Michal

*** Note that my e-mail address has changed to m.j.bojanowski at uu.nl
*** Please update your address books accordingly. Thank you!

_________________________________________
Michal Bojanowski
ICS / Sociology
Utrecht University
Heidelberglaan 2; 3584 CS Utrecht
Room 1428
m.j.bojanowski at uu.nl
http://www.fss.uu.nl/soc/bojanowski
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Nguyen Dinh
Nguyen
Sent: Tuesday, March 13, 2007 5:20 AM
To: r-help at stat.math.ethz.ch
Subject: [R] Highlight overlapping area between two curves

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.
Nguyen

###START
x1 <- rnorm(10000, 0.70,0.12)
x2 <- rnorm(10000, 0.90,0.12)

d1 <- density(x1)
d2 <- density(x2)

plot(range(d1$x,d2$x), range(d1$y, d2$y), type = "n",
     xlab = "X value", ylab = "Probability Density" )

lines(d1, col = "red",lwd=4, lty=2)
lines(d2, col = "blue",lwd=4)

##END CODE

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list