Friday, March 1, 2013

Overlapping Histogram in R

While preparing a class exercise involving the use of overlaying of histogram, I searched Google on possible article or discussion on the said topic. Luckily, I found a blog where the author demonstrated an R function to create an overlapping histogram. However, a comment from a guy also showed the same output using transparency. Below were the sample codes that can be used to generate overlapping histogram in R as based on the blog and the viewers comment.


Here are the codes:


  1. Of course, for the transparency to have any effect, you would have to use an image file format that actually supports it, e.g. PNG or PDF. In R, you can do this easily using the png() or pdf() functions.

  2. Nice post! Love this, a very useful tool to have.


    1. Thanks Doug! I am happy that others like my post and found it useful.

  3. How about that we don't know the ylim for the two distributions? If they are different (the first one is less than the second)? Can we look the maximum ylim beforehand. Thanks.