# Plot histogram of variable with kernel density estimates and normal curve: hist.kdnc = function(v,breaks=0,include.lowest=T,right=T,xlab=deparse(substitute(v))) { xlab = xlab v = na.omit(v) x = v h = hist(v,plot=F) if (length(breaks)==1) breaks=h$breaks dens=density(v) ylim=range(0,h$density,dnorm(x=v,mean=mean(v),sd=sd(v)),dens$y) xlim=range(v,dens$x) hist(v,freq=F,breaks=breaks,include.lowest=include.lowest,right=right, xlim=xlim,ylim=ylim,col=grey(0.95),xlab=xlab, main=paste('Histogram of',xlab,'\nwith kernel density and normal curve ')) lines(density(v),col='red') curve(dnorm(x,mean=mean(v),sd=sd(v)),col='blue',add=T) }