#---------------------------------------------------------------------- # Draw normal distribution with filled polygon filled.normal <- function(from=-5,to=5, mean, sd_gor, hatch.from=-5, hatch.to=1.5, col='red', angle=45, density=NULL) { # history, density plot x = c(seq(from, to, length=50)) #, c(hatch.to, hatch.from)) y = dnorm(x, mean=mean, sd=sd_gor) plot(x, y, from=from, to=to, type='l') # colored polygon xp = seq(hatch.from, hatch.to, length=50) yp = dnorm(xp, mean=mean, sd=sd_gor) # close the polygon xp = c(xp, hatch.to, hatch.from) yp = c(yp, 0., 0.) polygon(xp,yp, col='red', border="blue") #, density=density) # black horizontal line on x-axis xl = c(from, to) yl = c(0, 0) lines(xl,yl) } filled.normal(mean=3, sd_gor=1, from=-5, to=10) #---------------------------------------------------------------------- filled.rejection.normal <- function(from=-5,to=5, mean, sd, confidence=.95, col='red', angle=45, density=5) { plot(dnorm, from=from, to=to) polygon(c(from,to),c(0,0)) rej = 0.5*(1-confidence) xleft = qnorm(rej) hatch.from = from hatch.to = xleft xp = c(seq(hatch.from,hatch.to,(hatch.to-hatch.from)/50), c(hatch.to, hatch.from)) yp = c(dnorm(xp)[1:(length(xp)-2)], c(0., 0.)) # without density argument, I get filled polygon polygon(xp,yp, col='red', border="black") xright = qnorm(1-rej) hatch.from = xright hatch.to = to xp = c(seq(hatch.from,hatch.to,(hatch.to-hatch.from)/50), c(hatch.to, hatch.from)) yp = c(dnorm(xp)[1:(length(xp)-2)], c(0., 0.)) polygon(xp,yp, col='red', border="black") } #----------------------------------------------------------------------