This video explains how to overlay histogram plots in R for 3 common cases: overlaying a histogram with a normal curve, overlaying a histogram with a density curve, and overlaying a histogram with a second data series plotted on a secondary axis.

Note: Towards the end of the video (maybe minute 14 or so), I make a language error when talking about the “padj” parameter in the mtext function…the setting doesn’t “left truncated” the label, I meant “right align”, “left align”, etc.

Download:

Histogram overlay in R code and sample data file

Nice. Since I see from previous blog posts that you also use SAS, I wanted to point out a few ways to do similar operations in SAS:

1) Most people are familiar with using PROC UNIVARIATE to plot the histogram and fit and overlay one or more parametric curves or KDES. For example: http://blogs.sas.com/content/iml/2011/06/24/the-area-under-a-density-estimate-curve/

2) If you want to compare the densities for different variables, you can use PROC KDE: http://blogs.sas.com/content/iml/2012/01/13/overlay-density-estimates-on-a-plot/

@RickWicklin Thanks for stopping by Rick. This is great information for the next time I use SAS.