Overlay Density Curve Over Histogram Using R Base Graphics

It is useful to overlay the expected density function over a histogram. This can give you a visual cue to if the data actually fits the expected distribution, however this should not be a substitute for a goodness-of-fit test.

In R base graphics there are two ways to do this.

Find the min and max of the data and create a sequence to feed into the density function.

There is a quicker way by using the curve function. It requires that a variable x be in the function call and will evaluate the function along the same length as the original plot.

Use a built in function that generates x sequence value based on the plot.