Coal forms when organic matter, mainly plants get buried to depth on the order of kilometers where the pressure can be calculated from pressure= density of overlying rock x gravity x depth.
So a depth of ten km in Earth is pressure of ~ 0.3 GPa.
At any rate due to pressure and T at depth, the plant material loses a lot of its H and O and because the oxygen pressure is so low, this plant material gets reduced to elemental carbon.
Different types of coal (lignite, bituminous, anthracite) form mainly due to the temp t which they are held.... we are taking about 100's of degrees C , roughly...
Recall that on Earth the temperature increases by about 25 deg C for every kilometer down... so at 10 km typical T is 200-300 deg C.
Without plants there would be no coal.