Blogger

Delete comment from: One R Tip A Day

rtwillia said...

Hey Paolo,
Thanks for getting back to me. Close. I basically used brute force to get to the image I needed although in, I'm sure, a most inefficient manner. I wanted shading on curve x1 from -1.13 to the remainder of the negative tail of the distribution. Maybe you can take a look at at it ans see if you can tell me how one would get this result without using "white" polygon fill to achieve the graphic. You'll see what I'm talking about.
Thanks for all of your advice,
Ryan

p<-seq(-8.5,4.9,.001)
x1<-dnorm(p,-1.5,1.5)
x2<-dnorm(p,0,1.5)
plot(range(p),range(x1,x2),type="n")
lines(p,x1,col="red",lwd=4)
lines(p,x2,col="blue",lwd=4,lty=2)
line<--1.13
#abline(v=line)

x<-p
y<-x1
scale<-.001
shade<- (max(y)) / scale
xt <- c(x[(shade):length(x)],-1)
yt <- c(y[(shade):length(y)],0)
polygon(xt, yt, col="gray")
lines(p,x1,col="red",lwd=4)
lines(p,x2,col="blue",lwd=4,lty=2)

x<-p
y<-x1
scale<-.001
cutpoint <- (max(x)-line) / scale
xt <- c(x[(length(x)-cutpoint):length(x)],line)
yt <- c(y[(length(y)-cutpoint):length(y)],0)
polygon(xt, yt, col='white')
lines(p,x1,col="red",lwd=4)
lines(p,x2,col="blue",lwd=4,lty=2)
lines(p,x1,col="red",lwd=4)
floor<-0
abline(h=floor)

Sep 10, 2008, 10:39:00 AM


Posted to Highlight overlapping area between two curves

Google apps
Main menu