## empty plot with appropriate ranges plot(0,0, type = "n", xlim = c(20,120), ylim = c(0,.05), xlab = "x", ylab = "Density") ## the two normal densities are plotted in intervals of ## plus/minus 3*sigma around mu. mu <- 45 sigma <- 8 ## shaded area xs <- seq(qnorm(0.025, mu, sigma), qnorm(0.975, mu, sigma), length = 50) ds <- dnorm(xs, mu, sigma) polygon(c(xs, rev(xs)), c(rep(0,50), rev(ds)), col = "grey", border = NA) ## the first density (plotted on top of shaded area) curve(dnorm(x,mu,sigma), mu-3*sigma, mu+3*sigma, add = TRUE) mu <- 70 sigma <- 15 ## hatched area xs <- seq(80, 100, length = 50) ds <- dnorm(xs, mu, sigma) polygon(c(xs, rev(xs)), c(rep(0,50), rev(ds)), density = 15, angle = 70, border = TRUE) ## the other density curve(dnorm(x,mu,sigma), mu-3*sigma, mu+3*sigma, add = TRUE)