Here, I will introduce a way to two overlapping histograms with transparent colors, which makes a nice way to compare two distributions.
We start by plotting two histograms, each of 100 numbers with similar distributions but with slightly different means.
Now what we want to do is to put these two histograms together on the same plot, but to make it transparently colored so that we can see both distributions.
The key piece of code here is to assign the color using the rgb() function. The syntax is rgb(red, green, blue, alpha), where alpha<1 makes the color transparent. *Note that col=rbg(1,1,1,1) creates white, and rgb(0,0,0,1) creates black... think 'light' not 'paint'.
Also make sure to assign the same axes for the histograms. I also take out the title and the redundant axis names. par(new=TRUE) is a general way to let you plot one plot over another. I usually keep the axes in the second plot in, so that I'll notice if they happened to be on a different scale than the first, but once you've got it down it might be nice to take out the redundant axis lines by using axes=FALSE.
Play around with the rgb() yourself, but here's a quick set I've tried (opaque colors):
R Resources >