Because the incoming light is composed of all those different colours! The water in the air spreads them out. If the sun only gave off red and orange light (instead of all colours like it does now), we wouldn’t see any blue in the rainbow.
There’s a cool thing I like about the colours in the rainbow. We are always taught there are 7 colours in a rainbow: Red, Orange, Yellow, Green, Blue, Indigo, Violet. However, if we think about art there are three primary colours, Red, Yellow and Blue which can be combined to produce Green, Orange and Purple. So there are really only 6 basic colours. So why 7 in a rainbow? It turns out that Newton decided to split purple into two different colours because 7 was a lucky number according to the Ancient Greeks and in particular, Pythagoras who believed there was a connection between colour and music. So 7 natural notes in music = 7 colours in the rainbow!
Comments