# 
# A function that ADDS a pdf onto a histogram that has been drawn with
# a density scale (i.e., probability=T option on the hist function.
# x is the data vector that the histogram is constructed from.
#
# To use this function, you should first create a histogram of x, using the
# prob=T option.  That is
# hist(x, prob=T)
# Then use overlay(x,dens=)
#
#  Tom Moore
#  Nov. 11, 2004
#
#

overlay <- function(x,dens=dnorm, ...){
         xd <- seq(min(x), max(x), length=101)
         yd <- dens(xd, ...)
         lines(xd, yd,lty=1)
         }