When it is within a few degrees of the horizon, the sun passes through 12 times the thickness of the atmosphere than when it is directly overhead. This leaves mostly longer wavelengths, which our eyes translate into beautiful yellow, orange and red sunrises and sunsets. Other natural events such as fires and volcanic eruptions add further particles to scatter the light and only the longest red light waves reach your eye. The rainbow, is the confluence of light and water, though unfortunately there is no pot of gold. The magic that makes rainbows involves the optical effects of the refraction and reflection of light as it enters and then leaves water droplets.
Rainbows occur when rain is falling in one part of the sky and the sun is shining in another.
The geometry necessary for this process to be seen has sunlight coming from behind the observer. As it enters a raindrop the light is refracted, then it is reflected off the inside of the drop, which bends it back toward the observer. Finally, it is refracted again as it leaves the drop. This process separates light into its component colors, which we see with red at the top and violet at the bottom. Rainbows also appear in the spray from a waterfall or sprinkler.