# Plot kernel density estimates of variable with normal curve: plot.kdnc = function(v,...,xlab=deparse(substitute(v)),title="",rug=T) { xlab=xlab v = na.omit(v) x = v dens=density(v,...) ylim=range(0,dnorm(x,mean=mean(v),sd=sd(v)),dens$y) if (title=="") title=paste("Kernel density estimates of",xlab,"\nwith normal curve") plot(dens,col='red',ylim=ylim,xlab=xlab,main=title) if (rug==T) rug(jitter(v),col="red") curve(dnorm(x,mean=mean(v),sd=sd(v)),col='blue',add=T) }