  Solid oxygen is a unique molecular crystal whose phase diagram is mostly
imposed by magnetic ordering, i.e., each crystal phase has a specific magnetic
structure. However, recent experiments showed that high-pressure $\delta$-phase
is implemented in different magnetic structures. In the present paper we study
the role of interplane exchange interactions in formation of the magnetic
structures with different stacking sequences of the close-packed planes. We
show that temperature-induced variation of intermolecular distances can give
rise to compensation of the exchange coupling between the nearest close-packed
planes and result in the phase transition between different magnetic structures
within $\delta$-O$_2$. Variation of the magnetic ordering is, in turn,
accompanied by the step-wise variation of interplane distance governed by space
and angular dependence of interplane exchange constants.
