# overlay.R # written by Bret Larget # January 23, 2008 # This function is meant to be used as the panel argument # with histogram from the lattice package. # # For example, if you have a variable y and you want to overlay a normal curve # over the histogram of y, you would use this call. # # > plot( histogram(~ y,type="density",panel=overlayNormal ) ) overlayNormal = function(x,ncol="black",nlwd=2,...) { panel.histogram(x,...) panel.mathdensity(dmath = dnorm, col=ncol, args = list(mean=mean(x),sd=sd(x)),lwd=nlwd) }