Product: TIBCO Spotfire®
How can I overlay a density plot (normal curve) over a histogram?
User looking for S+ code to overlay a density plot (normal curve) over a histogram.
Here is one approach to combining the density (normal curve) and the histogram. The key here is the probability=TRUE argument to hist(), which puts it on a 0-1 vertical scale rather than a scale of bin counts. Then, computing the interquartile range is a fairly reasonable way to set the horizontal scale of the density function.
x <- rnorm(500)
iqd <- summary(x) - summary(x)
You can view the help files on any of the functions used in the code above by typing a question mark followed by the function name at your S+ command prompt. For example: