As the intermolecular forces get weaker, the amount dissolved decreases. Ammonia can form hydrogen bonds with water thus allowing it to be more soluble. CO2 and O2 can only react through London forces, but since CO2 has a higher molecular mass, more electrons, it will have a larger in magnitude temporary dipole moment. This results in the CO2 being more soluble in water than O2.
The overall trend in solubility is NH3>CO2>O2