If the cylinders have no spark, rich. If they have no fuel, lean. Little air, will cause it to go rich. Vacuum leaks, it goes lean.

Compression will cause similar results, not enough compression causes poor fuel burning, shows up rich.

The O2 sensor is detecting the oxygen levels in the exhaust stream, more oxygen leans out the exhaust, less oxygen the exhaust is richer with fuel molecules.