I've found many examples on the Internet of how to add normal curves to histograms in R, but none of those examples seem reliable when tested. Can anyone here please give correct R code for this? Thank you.

Code:

```
# Draw a histogram with a normal curve.
histnorm=function(x, ...)
{
if (length(x)>0)
{
hist(x,freq=FALSE, ...)
rug(x)
curve(dnorm(x, mean=mean(x), sd=sd(x)), add=TRUE, col="red", lty="dotted", xaxt="n")
abline(v=mean(x),col="blue")
mtext(paste("mean ", round(mean(x),1), "; sd ", round(sd(x),1), "; N ", length(x),sep=""), side=1, cex=.75)
} # fi
} # histnorm
```