That's basically the same thing as asking why is a grapefruit not shaped like a lemon? This is certainly due to genetics and probably has little to do with gravity as they grow in similar fashions.
Both pears and apples are cultivated, and thus over time designed by man when selecting particular specimens for breeding. There could thus also be a matter of esthetics involved in fruit shapes.